public async Task <IActionResult> Edit(int id, [Bind("ID,Number,Name,Description,Price,Family")] MenuDish menuDish)
        {
            if (id != menuDish.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(menuDish);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MenuDishExists(menuDish.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(menuDish));
        }
Exemple #2
0
        private static void GetNodes(HtmlNodeCollection nodeArray)
        {
            string DishType = "Mad";

            foreach (var node in nodeArray)
            {
                if (node.OriginalName.Contains("h2") && !node.InnerText.Contains("Drikkevarer") && !node.InnerText.Contains("Ekstra tilbehør"))
                {
                    DishType = node.InnerText;
                }

                MenuDish dish = new MenuDish();
                string   n    = node.InnerText;
                if (node.OriginalName.Contains("h4") && (n != "" && char.IsDigit(n[0])))
                {
                    dish.DishType = DishType;

                    if (n.Contains("."))
                    {
                        dish.Number = n.Substring(0, n.IndexOf("."));
                        dish.Name   = n.Substring(n.IndexOf(".") + 1);
                    }
                    else
                    {
                        dish.Number = n.Substring(0, n.IndexOf(" "));
                        dish.Name   = n.Substring(n.IndexOf(" "));
                    }
                    if (MenuList.Count != 0)
                    {
                        foreach (var item in MenuList)
                        {
                            if (item.Number == dish.Number)
                            {
                                dish.Family = true;
                            }
                        }
                    }
                    MenuList.Add(dish);
                }

                if (MenuList.Count != 0)
                {
                    int currentListNumber = MenuList.Count - 1;
                    if (node.OriginalName.Contains("p") && MenuList[currentListNumber].Number != "" && MenuList[currentListNumber].Description is null)
                    {
                        MenuList[currentListNumber].Description = node.InnerText;
                    }
                    if (double.TryParse(node.InnerText.Substring(4), out double price))
                    {
                        if (node.OriginalName.Contains("span") && MenuList[currentListNumber].Number != "")
                        {
                            MenuList[currentListNumber].Price = price;
                        }
                    }
                }
            }
        }
Exemple #3
0
 public bool CreateMenuDish(MenuDish instance)
 {
     if (instance.MenuDishId == 0)
     {
         Db.MenuDishs.InsertOnSubmit(instance);
         Db.MenuDishs.Context.SubmitChanges();
         return(true);
     }
     return(false);
 }
        public async Task <IActionResult> Create([Bind("ID,Number,Name,Description,Price,Family")] MenuDish menuDish)
        {
            if (ModelState.IsValid)
            {
                _context.Add(menuDish);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(menuDish));
        }
Exemple #5
0
        public static SimpleDishDTO CreateFromMenuDish(MenuDish md)
        {
            if (md == null)
            {
                return(null);
            }

            var dish = CreateFromDomain(md.Dish);

            return(dish);
        }
Exemple #6
0
        public bool RemoveMenuDish(int MenuDishId)
        {
            MenuDish instance = Db.MenuDishs.FirstOrDefault(p => p.MenuDishId == MenuDishId);

            if (instance != null)
            {
                Db.MenuDishs.DeleteOnSubmit(instance);
                Db.MenuDishs.Context.SubmitChanges();
                return(true);
            }

            return(false);
        }
Exemple #7
0
 public void MenuDishAdd(MenuDish item)
 {
     try
     {
         this.MenuDishList.Add(item);
         this.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         MessageBox.Show("Error");
         //throw;
     }
 }
Exemple #8
0
        public bool UpdateMenuDish(MenuDish instance)
        {
            MenuDish cache = Db.MenuDishs.FirstOrDefault(p => p.MenuDishId == instance.MenuDishId);

            if (instance.MenuDishId != 0)
            {
                cache.DishId   = instance.DishId;
                cache.MenuId   = instance.MenuId;
                cache.RepastId = instance.RepastId;
                Db.MenuDishs.Context.SubmitChanges();
                return(true);
            }
            return(false);
        }
Exemple #9
0
 public void MenuDishDelete(MenuDish item)
 {
     try
     {
         MenuDishList.Attach(item);
         MenuDishList.Remove(item);
         this.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         //throw;
         MessageBox.Show("Невозможно удалить элемент!");
     }
 }
Exemple #10
0
        public void MenuDishChange(MenuDish item)
        {
            try
            {
                var ser = MenuDishList.Where(x => x.Id == item.Id).First();

                ser.CategorieId = item.CategorieId;
                ser.MenuId      = item.MenuId;
                ser.DishId      = item.DishId;
                this.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            string url;

            url = "/Page/Adminka/NewMenusPage.aspx?stage=1";
            if (stage == 1)
            {
                MenuDish tempP = new MenuDish();
                tempP.DishId   = Repository.Dishs.Where(p => p.Name == Recept.Text).FirstOrDefault().DishId;
                tempP.RepastId = Repository.Repasts.Where(p => p.Name == Repast.Text).FirstOrDefault().RepastId;
                List <MenuDish> tempLP = new List <MenuDish>();
                if (Session["ListMenuDish"] != null)
                {
                    tempLP = (List <MenuDish>)Session["ListMenuDish"];
                }
                tempLP.Add(tempP);
                Session["ListMenuDish"] = tempLP;
            }

            Response.Redirect(url);
        }
Exemple #12
0
        public async Task <IActionResult> Create(string dishId, List <string> menuIds)
        {
            IEnumerable <MenuDish> menuDishes = _db.MenuDishes.Where(m => m.DishId == dishId);

            if (menuDishes.Count() == 0 && menuIds.Count == 0)
            {
                return(Json(false));
            }
            if (menuIds.Count != 0)
            {
                List <string> menuDishIds = new List <string>();
                foreach (var menuDish in menuDishes)
                {
                    menuDishIds.Add(menuDish.MenuId);
                }
                if (menuDishIds.SequenceEqual(menuIds))
                {
                    return(Json(false));
                }
                if (menuDishes.Count() != 0)
                {
                    _db.MenuDishes.RemoveRange(_db.MenuDishes.Where(m => m.DishId == dishId));
                }
                foreach (var menuId in menuIds)
                {
                    MenuDish menuDish = new MenuDish {
                        MenuId = menuId, DishId = dishId
                    };
                    _db.Entry(menuDish).State = EntityState.Added;
                }
            }
            else
            {
                _db.MenuDishes.RemoveRange(_db.MenuDishes.Where(m => m.DishId == dishId));
            }
            await _db.SaveChangesAsync();

            return(Json(true));
        }
Exemple #13
0
        public DishDTO AddNewDish(PostDishDTO dishDTO, string userId)
        {
            var newDish = _dishFactory.Create(dishDTO);

            newDish.UserId = userId;
            _uow.Dishes.Add(newDish);
            _uow.SaveChanges();

            if (dishDTO.MenuId != null && _uow.Menus.Exists((int)dishDTO.MenuId))
            {
                MenuDish md = new MenuDish
                {
                    DishId = newDish.DishId,
                    MenuId = dishDTO.MenuId.Value
                };

                _uow.MenuDishes.Add(md);
                _uow.SaveChanges();
            }


            return(_dishFactory.CreateComplex(newDish));
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string url;

            url = "/Page/Adminka/NewMenusPage.aspx";
            if (stage == 0)
            {
                url = "/Page/Adminka/NewMenusPage.aspx?stage=1";
                DbClassesBell.Menu tempd = new DbClassesBell.Menu();
                tempd.Name          = Name.Text;
                tempd.Text          = MText.Text;
                Session["MenusAdd"] = tempd;
            }
            if (stage == 1)
            {
                url = "/Page/Adminka/NewMenusPage.aspx?stage=2";
                MenuDish tempP = new MenuDish();
                tempP.DishId   = Repository.Dishs.Where(p => p.Name == Recept.Text).FirstOrDefault().DishId;
                tempP.RepastId = Repository.Repasts.Where(p => p.Name == Repast.Text).FirstOrDefault().RepastId;
                List <MenuDish> tempLP = new List <MenuDish>();
                if (Session["ListMenuDish"] != null)
                {
                    tempLP = (List <MenuDish>)Session["ListMenuDish"];
                }
                tempLP.Add(tempP);
                Session["ListMenuDish"] = tempLP;
            }
            if (stage == 2)
            {
                url = "/Page/Adminka/NewMenusPage.aspx?stage=3";
                if (Session["MenusAdd"] != null)
                {
                    DbClassesBell.Menu temp = (DbClassesBell.Menu)Session["MenusAdd"];
                    temp.Price          = Convert.ToDecimal(price.Text);
                    Session["MenusAdd"] = temp;
                }
            }
            if (stage == 3)
            {
                url = "/Page/Adminka/MenusAd.aspx";
                List <MenuDish> pAdd = (List <MenuDish>)Session["ListMenuDish"];
                if (Session["MenusAdd"] != null && pAdd != null)
                {
                    DbClassesBell.Menu temp = (DbClassesBell.Menu)Session["MenusAdd"];
                    Repository.CreateMenu(temp);
                    int id = Repository.Menus.Where(p => p.Name == temp.Name).FirstOrDefault().MenuId;
                    foreach (MenuDish asd in pAdd)
                    {
                        MenuDish tempp = asd;
                        tempp.MenuId = id;
                        Repository.CreateMenuDish(tempp);
                    }
                }
                Session.Remove("ListMenuDish");
                Session.Remove("MenusAdd");
            }



            Response.Redirect(url);
        }
Exemple #15
0
 private static bool IsEqualMenuDish(MenuDish x, MenuDish y)
 {
     return(x.DishId == y.DishId && x.MenuId == y.MenuId);
 }
Exemple #16
0
        public void MenuDishDelete(MenuDish delMD) //?
        {
            EsaDbContext db = new EsaDbContext();

            db.MenuDishDelete(delMD);
        }