// GET: Companies/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Company company = db.Companies.Find(id);

            db.Entry(company).Collection(dbCmpany => dbCmpany.Menus).Load();
            if (company == null)
            {
                return(HttpNotFound());
            }
            return(View(company));
        }
        public async Task <IActionResult> PutMenuItem(int id, MenuItem MenuItem)
        {
            if (id != MenuItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(MenuItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MenuItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task SaveAsync(Menu menu)
        {
            var isNew = menu.Id == default(long);

            _context.Entry(menu).State = isNew ? EntityState.Added : EntityState.Modified;

            await _context.SaveChangesAsync();
        }
Example #4
0
 public ActionResult Edit([Bind(Include = "ProductId,ProductName")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
        // GET: Menus/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Menu menu = db.Menus.Find(id);

            if (menu == null)
            {
                return(HttpNotFound());
            }
            menu.Company = db.Companies.Find(menu.CompanyId);
            db.Entry(menu).Collection(dbMenu => dbMenu.MenuProducts).Load();
            foreach (var menuProduct in menu.MenuProducts)
            {
                menuProduct.Menu    = menu;
                menuProduct.Product = db.Products.Find(menuProduct.ProductId);
            }
            return(View(menu));
        }
 public ActionResult Rate(Order order)
 {
     if ((int)order.Stars <= 2 && (order.Comment == null || order.CommentCategory == CommentCategoryEnum.NULL))
     {
         ViewBag.ErrorMessage = "გთხოვთ დაწეროთ კომენტარი";
     }
     else
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", new { id = order.OrderId }));
     }
     return(View());
 }
Example #7
0
 public ActionResult Edit([Bind(Include = "MenuProductId,ProductId,cookingTime,MenuId,ProductPrice")] MenuProduct menuProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(menuProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", "Menus", new { Id = menuProduct.MenuId }));
     }
     menuProduct.Menu         = db.Menus.Find(menuProduct.MenuId);
     menuProduct.Menu.Company = db.Companies.Find(menuProduct.Menu.CompanyId);
     ViewBag.MenuId           = new SelectList(db.Menus, "MenuId", "Name", menuProduct.MenuId);
     ViewBag.ProductId        = new SelectList(db.Products, "ProductId", "ProductName", menuProduct.ProductId);
     return(View(menuProduct));
 }
Example #8
0
        //To co není v array se smaže
        //to co v array je navíc, se přidá

        public void CompareAndSave(Food[] comparator)
        {
            //Kontrola, aby se z DB smazali staré záznamy a aktualizace upravených
            for (int i = 0; i < database.Menu.Count(); ++i)
            {
                //Opravdu zvlášní způsob, jak procházet entity... Seřadí se, a vždy se přeskočí o i entit a vybere jedna.
                var instance = database.Menu.OrderBy(s => s.Id).Skip(i).First();
                int result   = instance.IsIn(comparator);
                if (result != -1)
                {
                    //Změní se stav entity, aby se naznačilo, že se entita upravila
                    database.Entry(instance).State = System.Data.Entity.EntityState.Modified;
                    database.Menu.OrderBy(s => s.Id).Skip(i).First().SetValues(comparator[result]);
                    continue;
                }
                //Smazání entity
                else if (result == -1)
                {
                    database.Menu.Remove(instance);
                    continue;
                }
            }

            //Přidání nových záznamů
            for (int i = 0; i < comparator.Length; ++i)
            {
                //Pokud entita z porovnávacího pole není v již v DB, přidá se
                if (comparator[i].IsIn(database.Menu.ToArray()) == -1)
                {
                    database.Menu.Add(comparator[i]);
                }
            }
            try
            {
                database.SaveChangesAsync();
            }
            catch (Exception ex) { Console.WriteLine(ex.ToString()); }
        }
Example #9
0
 public void Delete(TEntity entity)
 {
     dbContext.Entry(entity).State = EntityState.Deleted;
 }