Beispiel #1
0
 public ActionResult DishDeleteConfirmed(DishModel Dish)
 {
     try
     {
         log.InfoFormat("[DishDeleteConfirmed] Dish={0} ", Dish.ToString());
         m_serviceLayer.DeleteDish(Dish);
         return RedirectToAction("DishesIndex", new { MenuPartId = Dish.MenuPartId, RestaurantId = Dish.RestaurantId });
     }
     catch(Exception ex)
     {
         log.InfoFormat("[DishDeleteConfirmed] Exception={0} ", ex.ToString());
         return View(Dish);
     }
 }
 public ActionResult AddDish(DishModel dish)
 {
     log.InfoFormat("[AddDish] dish={0}", dish.ToString());
     int menuPartId = m_serviceLayer.GetIdByMenuPartName(dish.RestaurantId, "כל המנות");
     if (menuPartId < 0)
     {
         MenuPartModel mp = new MenuPartModel() { RestaurantId = dish.RestaurantId, Name = "כל המנות" };
         dish.MenuPartId = m_serviceLayer.AddNewMenuPartModel(mp);
     }
     else {
         dish.MenuPartId = menuPartId;
     }
     dish.Id = m_serviceLayer.AddNewDish(dish);
     return Content(dish.Id.ToString(), "text/plain");
 }
 public DishModelBackOffice(DishModel dish)
 {
     Name = dish.Name;
     Description = dish.Description;
     RestaurantId = dish.RestaurantId;
     MenuPartId = dish.MenuPartId;
     ImageUrl = dish.ImageUrl;
     LocalUrl = dish.LocalUrl;
     Language = dish.Language;
     NutritionFacts = dish.NutritionFacts;
     BaseLineNutritionFacts = new NutritionFactsViewModel();
     State = dish.State;
     DefaultWeight = dish.DefaultWeight;
     dishId = dish.dishId;
     ItemLocation = dish.ItemLocation;
     IsItPublic = dish.IsItPublic;
     OrderBy = dish.OrderBy;
 }
Beispiel #4
0
 public ActionResult DishCreate(DishModel Dish)
 {
     try
     {
         if (ModelState.IsValid)
         {
             log.InfoFormat("[DishCreate].");
             m_serviceLayer.AddNewDish(Dish);
             return RedirectToAction("DishesIndex", new { MenuPartId = Dish.MenuPartId, RestaurantId = Dish.RestaurantId });
         }
         return View(Dish);
     }
     catch(Exception ex)
     {
         log.InfoFormat("[DishCreate] Exception={0} ", ex.ToString());
         return View(Dish);
     }
 }
 public ActionResult DishEdit(DishModel dish)
 {
     log.InfoFormat("[UpdateDish] dish={0}", dish.ToString());
     m_serviceLayer.UpdateDishAndCarbs(dish);
     return Content("success", "text/plain");
 }
        //"en-US"
        public static DishModel ToDishModel(this Dish dishData, string restId, bool baseLine, string lang = DefaultLang, RestaurantModel restModel = null)
        {
            if (restModel == null) restModel = new RestaurantModel();
            DishModel dishModel = restModel.GetDishModel(dishData, restId, baseLine, lang);
            var tempDish = dishModel;

            DishModel returnValue = new DishModel()
            {
                Id = dishData.Id,
                OrderBy = dishData.OrderBy,
                Name = dishData.Name,
                Language = lang,
                Description = dishData.Description,
                ItemLocation = new LocationModel(dishData.ItemLocation),
                RestaurantId = restId,
                //MenuPartId = MenuPId,
                RecipeId = dishData.RecipeId,
                //Images = item.Images,
                //OverrideIngredients = item.OverrideIngredients,
                CreatedAt = dishData.CreatedAt.ToLocalTime(),
                UpdatedAt = dishData.UpdatedAt.ToLocalTime(),
                State = baseLine ? new SuspiciousState() : dishData.State,
                IsItPublic = dishData.IsItPublic,
                DishState = dishData.DishState,
                NutritionFacts = baseLine && dishData.BaseLineNutritionFacts != null ? new NutritionFactsViewModel(dishData.BaseLineNutritionFacts) : new NutritionFactsViewModel(dishData.NutritionFacts),
                ImageUrl = dishData.ImageUrl
            };
            if (dishData.Image != null)
            {
                returnValue.LocalUrl = "/Restaurant/GetImage/" + dishData.Image.Id.ToString();
            }
            if (dishData.DefaultWeight != null) returnValue.DefaultWeight = dishData.DefaultWeight.ToWeightTypeModel(lang);

            if (dishData.LocalizedName != null)
            {
                string locName = dishData.LocalizedName.GetDescription(lang);
                if (locName != null) returnValue.Name = locName;
            }
            if (dishData.LocalizedDescription != null)
            {
                string locDesc = dishData.LocalizedDescription.GetDescription(lang);
                if (locDesc != null) returnValue.Description = locDesc;
            }
            return returnValue;
        }
        public void UpdateDishAndCarbs(DishModel Dish)
        {
            log.InfoFormat("[UpdateDishAndCarbs] Dish={0} ", Dish.ToString());
            var dishModel = GetDish(Dish.MenuPartId, Dish.RestaurantId, Dish.Id);
            //SaveUserActivity(new UserActivity()
            //{
            //    Type = "UpdateDish",
            //    RestaurantID = Dish.RestaurantId,
            //    Location = Dish.ItemLocation.toLoaction(),
            //    MenuPartID = Dish.MenuPartId,
            //    DishID = Dish.Id
            //});
            if (dishModel != null &&
                dishModel.NutritionFacts.TotalCarbohydrate != Dish.NutritionFacts.TotalCarbohydrate)
            {
                Dish.State.Index += 10;
            }
            UpdateDish(Dish);

            //SaveUserActivity(new UserActivity()
            //{
            //    Type = "UpdateDish",
            //    RestaurantID = Dish.RestaurantId,
            //    Location = Dish.ItemLocation.toLoaction(),
            //    MenuPartID = Dish.MenuPartId,
            //    DishID = Dish.Id
            //});
        }
 public void UpdateDish(DishModel dishModel)
 {
     log.InfoFormat("[UpdateDish] dishModel={0}.", dishModel.ToString());
     RestaurantBasicData rest = GetRestaurantBasicById(dishModel.RestaurantId);
     Dish dbDish = rest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == dishModel.MenuPartId).Dishes.First(dish => dish.Id == dishModel.Id);
     dishModel.UpdatedAt = DateTime.Now;
     if (dbDish.BaseLineNutritionFacts == null && dbDish.NutritionFacts != null)
     {
         dbDish.BaseLineNutritionFacts = dbDish.NutritionFacts;
     }
     dishModel.ToDish(dbDish);
     UpdateRestaurant(rest);
 }
 public void DeleteDish(DishModel Dish)
 {
     log.InfoFormat("[DeleteDish] Dish={0} ", Dish.ToString());
     RestaurantBasicData tempRest = GetRestaurantBasicById(Dish.RestaurantId);
     //RestaurantModel tempRest = GetRestaurantById(Dish.RestaurantId);
     tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == Dish.MenuPartId).Dishes.RemoveAll(dish => dish.Id == Dish.Id);
     UpdateRestaurant(tempRest);
 }
Beispiel #10
0
 public int AddNewDish(DishModel dish)
 {
     log.InfoFormat("[AddNewDish] Dish={0} ", dish.ToString());
     try
     {
         RestaurantModel tempRest = GetRestaurantById(dish.RestaurantId);
         if (tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == dish.MenuPartId).Dishes.Count > 0)
             dish.Id = tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == dish.MenuPartId).Dishes.Max(c => c.Id) + 1;
     }
     catch (Exception ex)
     {
         log.ErrorFormat("[AddNewDish] Exception={0}, DishModel={1}", ex.ToString(), dish);
         throw new ApplicationException("Problem in saving new dish, contact administraitor.");
     }
     return AddNewDishBasic(dish.RestaurantId, dish.MenuPartId, dish.ToDish());
 }
 public JsonResult GetDish(string id)
 {
     try
     {
         log.InfoFormat("[GetDish] Dish ID={0}", id);
         Stopwatch stop = Stopwatch.StartNew();
         GeneralDish genDish = m_serviceLayer.GetGeneralDishById(id);
         DishModel dish = new DishModel();
         if (genDish != null)
         {
             log.InfoFormat("[GetDish] id={0}.", id);
             dish = genDish.GeneralDishToDishModel();
         }
         log.DebugFormat("[GetDish] exec={0}", stop.ElapsedMilliseconds);
         return Json(dish, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         log.ErrorFormat("[GetDish] id={0}, exception={1}.", id, ex);
         throw;
     }
 }
Beispiel #12
0
 public int AddNewDish(DishModel Dish)
 {
     log.InfoFormat("[AddNewDish] Dish={0} ", Dish.ToString());
     try
     {
         Dish.CreatedAt = DateTime.Now;
         Dish.UpdatedAt = DateTime.Now;
         RestaurantModel tempRest = GetRestaurantById(Dish.RestaurantId);
         if (tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == Dish.MenuPartId).Dishes.Count > 0)
             Dish.Id = tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == Dish.MenuPartId).Dishes.Max(c => c.Id) + 1;
         Dish.ItemLocation = tempRest.Location;
         tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == Dish.MenuPartId).Dishes.Add(Dish);
         UpdateRestaurant(tempRest);
         return Dish.Id;
     }
     catch (Exception ex) {
         log.InfoFormat("[AddNewDish] Exception={0} ", ex.ToString());
         throw new ApplicationException("Problem in saving new dish, contact administraitor.");
     }
 }
Beispiel #13
0
 public static DishModel ToDishModel(this Dish dishData, string restId)
 {
     DishModel returnValue = new DishModel()
     {
         Id = dishData.Id,
         OrderBy = dishData.OrderBy,
         Name = dishData.Name,
         Description = dishData.Description,
         ItemLocation = new LocationModel(dishData.ItemLocation),
         RestaurantId = restId,
         //MenuPartId = MenuPId,
         RecipeId = dishData.RecipeId,
         //Images = item.Images,
         //OverrideIngredients = item.OverrideIngredients,
         CreatedAt = dishData.CreatedAt.ToLocalTime(),
         UpdatedAt = dishData.UpdatedAt.ToLocalTime(),
         State = dishData.State,
         IsItPublic = dishData.IsItPublic,
         DishState = dishData.DishState,
         NutritionFacts = new NutritionFactsViewModel(dishData.NutritionFacts),
         ImageUrl = dishData.ImageUrl
     };
     if (dishData.Image != null)
     {
         returnValue.LocalUrl = "/Restaurants/GetImage?id=" + dishData.Image.Id.ToString();
     }
     return returnValue;
 }
Beispiel #14
0
        public static List<DishModel> ToDishModel(this List<Dish> DishesData, string RestId, int MenuPId)
        {
            if (DishesData == null) return new List<DishModel>();

            List<DishModel> returnValue = new List<DishModel>();

            foreach (var item in DishesData)
            {
                if (item.State == null) { item.State = new SuspiciousState(); }
                DishModel temp = new DishModel()
                {
                    Id = item.Id,
                    OrderBy = item.OrderBy,
                    Name = item.Name,
                    Description = item.Description,
                    ItemLocation = new LocationModel(item.ItemLocation),
                    RestaurantId = RestId,
                    MenuPartId = MenuPId,
                    RecipeId = item.RecipeId,
                    //Images = item.Images,
                    //OverrideIngredients = item.OverrideIngredients,
                    CreatedAt = item.CreatedAt.ToLocalTime(),
                    UpdatedAt = item.UpdatedAt.ToLocalTime(),
                    State = item.State,
                    IsItPublic = item.IsItPublic,
                    DishState = item.DishState,
                    NutritionFacts = new NutritionFactsViewModel(item.NutritionFacts),
                    ImageUrl = item.ImageUrl
                };
                returnValue.Add(temp);
            }

            return returnValue.OrderBy(c => c.OrderBy).ToList();
        }
Beispiel #15
0
 //public void UpdateDish(DishModel dish)
 //{
 //    log.InfoFormat("[UpdateDish] dish={0} ", dish.ToString());
 //    RestaurantModel rest = GetRestaurantById(dish.RestaurantId);
 //    DeleteDish(dish);               //remove old Dish from Dishes List
 //    dish.UpdatedAt = DateTime.Now;
 //    RestaurantModel tempRest = GetRestaurantById(dish.RestaurantId);
 //    dish.ItemLocation = tempRest.Location;
 //    tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == dish.MenuPartId).Dishes.Add(dish);      //add new Dish to Dishes List
 //    UpdateRestaurant(tempRest);
 //}
 public void UpdateDish(DishModel dishModel)
 {
     RestaurantBasicData rest = GetRestaurantBasicById(dishModel.RestaurantId);
     Dish dbDish = rest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == dishModel.MenuPartId).Dishes.First(dish => dish.Id == dishModel.Id);
     dishModel.UpdatedAt = DateTime.Now;
     dishModel.ToDish(dbDish);
     UpdateRestaurant(rest);
 }
Beispiel #16
0
        public ActionResult DishTranslateConfirmed(DishModel Dish)
        {
            try
            {
                log.InfoFormat("[DishTranslateConfirmed] Dish={0} ", Dish.ToString());
                if (Dish != null || Dish.FromLanguage != null || Dish.ToLanguage != null)
                {
                    var transDish = m_serviceLayer.TranslateDish(Dish.RestaurantId, Dish.MenuPartId, Dish.Id, Dish.FromLanguage, Dish.ToLanguage);
                    if (transDish != null)
                    {
                        m_serviceLayer.UpdateDish(transDish, Dish.RestaurantId, Dish.MenuPartId);
                        return RedirectToAction("DishesIndex", new { MenuPartId = Dish.MenuPartId, RestaurantId = Dish.RestaurantId });
                    }
                }

                ViewBag.Message = "There is no translation on choosed language";
                return View(Dish);
            }
            catch(Exception ex)
            {
                log.InfoFormat("[DishTranslateConfirmed] Exception={0} ", ex.ToString());
                return View(Dish);
            }
        }