public ActionResult DeletDiaMenu(int Diaid, int Menuid, bool?E) { var diamenu = db.DayMenu.SingleOrDefault(md => md.Cod_Dia == Diaid && md.Cod_Menu == Menuid); db.DayMenu.Remove(diamenu); db.SaveChanges(); var menu = db.Menus.Find(Menuid); var ListDia = db.Dias.ToList(); ListDia.Add(new Dias { Cod_Dia = 0, Nombre_Dia = "Seleccione el Dia" }); ViewBag.DiasId = new SelectList(ListDia.OrderBy(d => d.Cod_Dia).ToList(), "Cod_Dia", "Nombre_Dia"); var dias = new List <Dias>(); var menudia = db.DayMenu.Where(md => md.Cod_Menu == Menuid).ToList(); if (menudia != null) { foreach (var item in menudia) { var dia = new Dias { Cod_Dia = item.Cod_Dia, Nombre_Dia = item.Dias.Nombre_Dia }; dias.Add(dia); } } else { ModelState.AddModelError(string.Empty, "No tiene Dias Asignados"); ViewBag.Error = true; } var diaMenuView = new DiaMenuView(); diaMenuView.Menu = menu; diaMenuView.Dia = new Dias(); diaMenuView.Dias = dias.OrderBy(d => d.Cod_Dia).ToList(); if (E == null) { return(View("AddDiaMenu", diaMenuView)); } else { return(RedirectToAction(string.Format("Edit/{0}", Menuid))); } }
public ActionResult AddDiaMenu(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var menu = db.Menus.Find(id); if (menu == null) { return(HttpNotFound()); } var dias = new List <Dias>(); var menudia = db.DayMenu.Where(md => md.Cod_Menu == id).ToList(); if (menudia != null) { foreach (var item in menudia) { var dia = new Dias { Cod_Dia = item.Cod_Dia, Nombre_Dia = item.Dias.Nombre_Dia }; dias.Add(dia); } } else { ModelState.AddModelError(string.Empty, "No tiene Dias Asignados"); ViewBag.Error = true; } var ListDia = db.Dias.ToList(); ListDia.Add(new Dias { Cod_Dia = 0, Nombre_Dia = "Seleccione el Dia" }); ViewBag.DiasId = new SelectList(ListDia.OrderBy(d => d.Cod_Dia).ToList(), "Cod_Dia", "Nombre_Dia"); var diaMenuView = new DiaMenuView(); diaMenuView.Menu = menu; diaMenuView.Dia = new Dias(); diaMenuView.Dias = dias.OrderBy(d => d.Cod_Dia).ToList(); return(View(diaMenuView)); }
public ActionResult AddDiaMenu(int id) { var dias = new List <Dias>(); var menudia = db.DayMenu.Where(md => md.Cod_Menu == id).ToList(); if (menudia != null) { foreach (var item in menudia) { var dia = new Dias { Cod_Dia = item.Cod_Dia, Nombre_Dia = item.Dias.Nombre_Dia }; dias.Add(dia); } } else { ModelState.AddModelError(string.Empty, "No tiene Dias Asignados"); ViewBag.Error = true; } var ListDia = db.Dias.ToList(); var menu = db.Menus.Find(id); var diaMenuView = new DiaMenuView(); int diaid = Convert.ToInt32(Request["DiasId"]); if (diaid == 0) { ModelState.AddModelError(string.Empty, "Por favor seleccione el dia"); ViewBag.Error = true; } var daymenu = db.DayMenu.Where(dm => dm.Cod_Menu == id && dm.Cod_Dia == diaid).ToList(); if (daymenu.Count() != 0) { diaMenuView.Menu = menu; diaMenuView.Dia = new Dias(); diaMenuView.Dias = dias.OrderBy(d => d.Cod_Dia).ToList(); ModelState.AddModelError(string.Empty, "Ya se añadido ese dia"); ViewBag.Error = true; ListDia.Add(new Dias { Cod_Dia = 0, Nombre_Dia = "{Seleccione el Dia...}" }); ViewBag.DiasId = new SelectList(ListDia.OrderBy(d => d.Cod_Dia).ToList(), "Cod_Dia", "Nombre_Dia"); return(View(diaMenuView)); } var diamenu = new DayMenu { Cod_Dia = Convert.ToInt32(diaid), Cod_Menu = id }; try { db.DayMenu.Add(diamenu); db.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); ViewBag.Error = true; } if (diaid != 0) { var Ndia = db.Dias.Find(Convert.ToInt32(diaid)); var dia1 = new Dias { Cod_Dia = Ndia.Cod_Dia, Nombre_Dia = Ndia.Nombre_Dia }; dias.Add(dia1); } diaMenuView.Menu = menu; diaMenuView.Dia = new Dias(); diaMenuView.Dias = dias.OrderBy(d => d.Cod_Dia).ToList(); ListDia.Add(new Dias { Cod_Dia = 0, Nombre_Dia = "Seleccione el Dia" }); ViewBag.DiasId = new SelectList(ListDia.OrderBy(d => d.Cod_Dia).ToList(), "Cod_Dia", "Nombre_Dia"); return(View(diaMenuView)); }