public static Data.Models.Obra Get(int id) { var model = new Data.Models.Obra(); using(var db = new Data.Context.AppContext()) { model = db.Obra.Include("Cliente") .Include("Encarregado") .Include("ObraStatus") .Include("Notificacao").Where(e => e.Id == id).FirstOrDefault(); } return model; }
public ActionResult AddOrUpdate(int id = 0) { var model = new Data.Models.Obra(); if (id > 0) { model = db.Obra .Include(o => o.Cliente) .Include(o => o.Encarregado) .Include(o => o.Notificacao) .Include(o => o.ObraStatus).Where(o => o.Id == id).FirstOrDefault(); } ViewBag.ClienteId = new SelectList(db.Pessoa, "Id", "Nome", model.ClienteId); ViewBag.EncarregadoId = new SelectList(db.Pessoa, "Id", "Nome", model.EncarregadoId); ViewBag.NotificacaoId = new SelectList(db.Notificacao, "Id", "Nome", model.NotificacaoId); ViewBag.ObraStatusId = new SelectList(db.ObraStatus, "Id", "Nome", model.ObraStatusId); return View("Create", model); }