Пример #1
0
        public ActionResult Create(Ordine ordine)
        {
            if (ModelState.IsValid)
            {
                IEnumerable<Ordine> sameTable = db.Ordines.Where(x => x.TavoloId == ordine.TavoloId).ToList();
                foreach (Ordine item in sameTable)
                {
                    if (ordine.Data.Date == item.Data.Date)
                    {
                        if (Math.Abs(ordine.Data.Hour * 60 + item.Data.Minute - item.Data.Hour * 60 - item.Data.Minute) <= 60)
                        {
                            return View("Error");
                        }
                    }
                }
                db.Ordines.Add(ordine);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.PersonaId = new SelectList(db.Utentes, "Id", "Nome", ordine.PersonaId);
            ViewBag.TavoloId = new SelectList(db.Tavoloes, "Id", "Codice", ordine.TavoloId);
            return View(ordine);
        }
Пример #2
0
 public ActionResult Edit(Ordine ordine)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ordine).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.PersonaId = new SelectList(db.Utentes, "Id", "Nome", ordine.PersonaId);
     ViewBag.TavoloId = new SelectList(db.Tavoloes, "Id", "Codice", ordine.TavoloId);
     return View(ordine);
 }