Example #1
0
        public void UpdateMenuPart(MenuPartModel MenuPart)
        {
            //
            log.InfoFormat("[UpdateMenuPartModel] MenuPart={0} ", MenuPart.ToString());
            //RestaurantModel tempRest = GetRestaurantById(MenuPart.RestaurantId);
            //MenuPart.Dishes = tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == MenuPart.Id).Dishes;  //save existed dishes
            //tempRest.Menu.MenuParts.RemoveAll(mp => mp.Id == MenuPart.Id);  //remove old MenuPart from MenuPartsModel List
            //tempRest.Menu.MenuParts.Add(MenuPart);                          //add new MenuPart to MenuPartsModel List
            //UpdateRestaurant(tempRest);                                       //save changes in DB
            RestaurantBasicData restaurant = GetRestaurantBasicById(MenuPart.RestaurantId);

            var dbMenuPart = restaurant.Menu.MenuParts.FirstOrDefault(mp => mp.Id == MenuPart.Id);
            MenuPart temp = MenuPart.ToMenuPartBasic();
            if (temp != null && dbMenuPart != null)
            {
                temp.Dishes = dbMenuPart.Dishes;
                restaurant.Menu.MenuParts.RemoveAll(mp => mp.Id == MenuPart.Id);  //remove old MenuPart from MenuPartsModel List
                restaurant.Menu.MenuParts.Add(temp);
                UpdateRestaurant(restaurant);
            }
        }
Example #2
0
 public int AddNewMenuPartModel(MenuPartModel MenuPart)
 {
     log.InfoFormat("[AddMenuPartToRestaurant] MenuPart={0}", MenuPart.ToString());
     RestaurantBasicData tempRest = GetRestaurantBasicById(MenuPart.RestaurantId);
     if (tempRest.Menu.MenuParts.Count > 0)
         MenuPart.Id = tempRest.Menu.MenuParts.Max(c => c.Id) + 1;
     tempRest.Menu.MenuParts.Add(MenuPart.ToMenuPartBasic());
     UpdateRestaurant(tempRest);
     return MenuPart.Id;
 }