public ActionResult SolicitacoesList(Boolean json = false) { var solicitacoes = db.Solicitacoes .Include("Avaliacao") .Include("User"); //Inicializar ViewModel a partir dos modelos de dados List<SolicitacaoIndexModel> model = new List<SolicitacaoIndexModel>(); foreach (var s in solicitacoes) { SolicitacaoIndexModel modelItem = new SolicitacaoIndexModel(); modelItem.InjectFrom(s.Avaliacao, s); modelItem.InsertFrom(s); modelItem.Cancelavel = s.IsCancelavel(); model.Add(modelItem); } if (!json) { return View(model); } else { return Json(model, JsonRequestBehavior.AllowGet); } }
public ActionResult Index() { var solicitacoes = from s in db.Solicitacoes join a in db.Avaliacoes on s.Id equals a.Solicitacao.Id where s.User.UserName == User.Identity.Name select new { Solicitacao = s, Avaliacao = a }; //Inicializar ViewModel a partir dos modelos de dados List<SolicitacaoIndexModel> model = new List<SolicitacaoIndexModel>(); foreach (var line in solicitacoes) { SolicitacaoIndexModel modelItem = new SolicitacaoIndexModel(); modelItem.InjectFrom(line.Avaliacao, line.Solicitacao); model.Add(modelItem); } ViewBag.PodeCriarSolicitacao = BusinessLogic.SolicitacaoBL.PodeCriarSolicitacao(User.Identity.Name) == StatusCriacaoSolicitacao.Permitido; return View(model); }