public ActionResult Create([Bind(Include = "RefeicaoID,PratoID,Dose")] RefeicaoPrato refeicaoPrato) { if (ModelState.IsValid) { int counter = 0; var userId = Convert.ToInt32(User.Identity.GetUserId()); var prato = db.RefeicaoPratos.FirstOrDefault(c => c.Refeico.RegistoDiario.Objectivo.UserID == userId); if (prato == null) { counter++; } db.RefeicaoPratos.Add(refeicaoPrato); db.SaveChanges(); counter++; if (counter == 2) { TempData["Userguide2"] = "Final"; } return(RedirectToAction("Index", "Refeicoes")); } ViewBag.PratoID = new SelectList(db.Pratos, "PratosID", "Nome", refeicaoPrato.PratoID); ViewBag.RefeicaoID = new SelectList(db.Refeicoes, "RefeicaoID", "Tipo", refeicaoPrato.RefeicaoID); return(View(refeicaoPrato)); }
public ActionResult DeleteConfirmed(int RefeicaoID, int PratoID) { RefeicaoPrato refeicaoPrato = db.RefeicaoPratos.FirstOrDefault(r => r.RefeicaoID == RefeicaoID && r.PratoID == PratoID); db.RefeicaoPratos.Remove(refeicaoPrato); db.SaveChanges(); return(RedirectToAction("Index", "Refeicoes")); }
public ActionResult Edit([Bind(Include = "RefeicaoID,PratoID,Dose")] RefeicaoPrato refeicaoPrato) { if (ModelState.IsValid) { db.Entry(refeicaoPrato).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Refeicoes")); } ViewBag.PratoID = new SelectList(db.Pratos, "PratosID", "Nome", refeicaoPrato.PratoID); ViewBag.RefeicaoID = new SelectList(db.Refeicoes, "RefeicaoID", "Tipo", refeicaoPrato.RefeicaoID); return(View(refeicaoPrato)); }
// GET: RefeicaoPratoes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RefeicaoPrato refeicaoPrato = db.RefeicaoPratos.Find(id); if (refeicaoPrato == null) { return(HttpNotFound()); } return(View(refeicaoPrato)); }
// GET: RefeicaoPratoes/Delete/5 public ActionResult Delete(int?RefeicaoID, int?PratoID) { if (RefeicaoID == null || PratoID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RefeicaoPrato refeicaoPrato = db.RefeicaoPratos.FirstOrDefault(r => r.RefeicaoID == RefeicaoID && r.PratoID == PratoID); if (refeicaoPrato == null) { return(HttpNotFound()); } return(View(refeicaoPrato)); }
// GET: RefeicaoPratoes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RefeicaoPrato refeicaoPrato = db.RefeicaoPratos.Find(id); if (refeicaoPrato == null) { return(HttpNotFound()); } ViewBag.PratoID = new SelectList(db.Pratos, "PratosID", "Nome", refeicaoPrato.PratoID); ViewBag.RefeicaoID = new SelectList(db.Refeicoes, "RefeicaoID", "Tipo", refeicaoPrato.RefeicaoID); return(View(refeicaoPrato)); }