What i have initially on my App is a list of expensives that is created based on the Scarfolding System but that list is the same for each User, and what i want is that each user can create his own list of expensives and see his own data.
So in the expensive class i did this:
public class Despesa
{
public int TipoDespesaId { get; set; }
public int DespesaId { get; set; }
public string UserId { get; set; }
[Display(Name = "Descrição da Despesa")]
[Required]
public string DespesaDescricao { get; set; }
[Display(Name = "Valor")]
[Required]
public decimal DespesaValor { get; set; }
public int TipoPagamentoId { get; set; }
[Display(Name = "Data")]
[DataType(DataType.Date)]
[CustomValidation(typeof(Validator), "ValidateEndTimeRange")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",ApplyFormatInEditMode = true)]
[Required]
public DateTime Data { get; set; }
public TipoDespesa TipoDespesa { get; set; }
public TipoPagamento TipoPagamento { get; set; }
[Display(Name = "Comentário")]
public string Comentario { get; set; }
}
i just passed the UserId to the model and then in the Index controller of my Expensive View i did a linq query to compare the currentUserID to the Id of the expensive User here is my code:
public ActionResult Index()
{
String userId = User.Identity.GetUserId();
var despesas = from r in db.Despesas.Include(d => d.TipoDespesa).Include(d => d.TipoPagamento).Include(d => d.UserId)
where r.UserId.Equals(userId)
select r;
return View(despesas.ToList());
}
what i need to know is what i am doing wrong cause i get a invalidOperationException