public ActionResult Save(FoodItem model, int vendorId) { SaveFoodItemResponse resp = _vendorMgr.SaveFoodItem(new SaveFoodItemRequest { Subject = model }); if (resp.Status == Status.Success) { var uiresponse = resp.ToUIResult<FoodItemsListViewModel , FoodItem>((Options) => GetList(vendorId) , (vm) => RenderPartialViewToString("FoodItemList", vm)); return Json(uiresponse); } else { var uiresponse = resp.ToUIResult<FoodItemEditModel , FoodItem>((Options) => new FoodItemEditModel(Options) , (vm) => { vm.Merge(resp); vm.Categories = _vendorMgr.GetFoodCategoriesByVendor(new GetFoodCategoriesByVendorRequest { VendorId = vendorId }).FoodCategories; return RenderPartialViewToString("AddEdit", vm); }); return Json(uiresponse); } }
public static C.FoodItem ToContract(this FoodItem data) { if (data == null) return null; var model = new C.FoodItem() { Name = data.Name, Description = data.Description, FoodCategoryId = data.VendorFoodCategoryID, FoodItemId = data.FoodItemId, IsActive = data.IsActive, Category = data.VendorFoodCategory != null ? data.VendorFoodCategory.Name : string.Empty, Cost = data.Cost, Options = data.FoodItemOptions.Select(x => x.VendorFoodOption.ToContract()).ToList(), Price = data.Price }; return model; }