Exemplo n.º 1
0
 public IActionResult Update2FoodItem(FoodItemEditModel model)
 {
     if (ModelState.IsValid)
     {
         var fi = _diabetWebData.GetFoodItem(model.Id);
         fi.Id            = model.Id;
         fi.Name          = model.Name;
         fi.Description   = model.Description;
         fi.Protein       = model.Protein;
         fi.Fat           = model.Fat;
         fi.Carbohydrates = model.Carbohydrates;
         fi.GlycemicIndex = model.GlycemicIndex;
         fi.Attribute     = model.Attribute;
         fi.Category      = model.Category;
         DiabetCalcService.CalcEnergy(fi);
         if (Request.Form.ContainsKey("update"))
         {
             fi = _diabetWebData.UpdateFoodItem(fi);
             return(RedirectToAction(nameof(FoodItemDetails), new { id = fi.Id }));
         }
         else if (Request.Form.ContainsKey("delete"))
         {
             _diabetWebData.DeleteFoodItem(fi);
             return(RedirectToAction(nameof(FoodItems)));
         }
         return(View());
     }
     else
     {
         return(View());
     }
 }
Exemplo n.º 2
0
        public ActionResult AddFoodItem(int vendorId)
        {
            var m = new FoodItemEditModel();

            var uiresult = new UIResponse<FoodItemEditModel>();

            m.Categories = _vendorMgr.GetFoodCategoriesByVendor(new GetFoodCategoriesByVendorRequest { VendorId = vendorId }).FoodCategories;

            uiresult.Subject = m;

            uiresult.HtmlResult = RenderPartialViewToString("AddEdit", m);

            return Json(uiresult, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 3
0
        public ActionResult EditFoodItem(int foodItemId, int vendorId)
        {
            var resp = _vendorMgr.GetFoodItemById(new GetFoodItemByIdRequest { FoodItemId = foodItemId });

            var uiresult = resp.ToUIResult(() => {
                var model = new FoodItemEditModel(resp.FoodItem, vendorId);

                model.Categories = _vendorMgr.GetFoodCategoriesByVendor(new GetFoodCategoriesByVendorRequest { VendorId = vendorId }).FoodCategories;

                return model;
                }
                , (vm) => RenderPartialViewToString("AddEdit", vm));

            return Json(uiresult, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        public IActionResult AddFoodItem(FoodItemEditModel model)
        {
            if (ModelState.IsValid)
            {
                var foodItem = new FoodItem();
                foodItem.Name          = model.Name;
                foodItem.Description   = model.Description;
                foodItem.Protein       = model.Protein;
                foodItem.Fat           = model.Fat;
                foodItem.Carbohydrates = model.Carbohydrates;
                foodItem.GlycemicIndex = model.GlycemicIndex;
                foodItem.Attribute     = model.Attribute;
                foodItem.Category      = model.Category;
                foodItem.Favorites     = model.Favorites;
                DiabetCalcService.CalcEnergy(foodItem);
                foodItem = _diabetWebData.AddFoodItem(foodItem);

                return(RedirectToAction(nameof(FoodItemDetails), new { id = foodItem.Id }));
            }
            else
            {
                return(View());
            }
        }