示例#1
0
        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));
        }
示例#2
0
        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"));
        }
示例#3
0
 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));
 }
示例#4
0
        // 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));
        }
示例#5
0
        // 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));
        }
示例#6
0
        // 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));
        }