//Helper methods private FoodItemService CreateFoodItemService() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new FoodItemService(userId); return(service); }
private bool SetStarState(int foodItemId, bool newState) { // Create the service var userId = User.Identity.GetUserId(); var service = new FoodItemService(userId); // Get the food item var detail = service.GetFoodItemById(foodItemId); // Create the FoodItemEdit model instance with the new star state var updatedFoodItem = new FoodItemEdit { FoodItemId = detail.FoodItemId, Name = detail.Name, Description = detail.Description, Calories = detail.Calories, CarbohydrateGrams = detail.CarbohydrateGrams, FiberGrams = detail.FiberGrams, FatGrams = detail.FatGrams, ProteinGrams = detail.ProteinGrams, SodiumMilligrams = detail.SodiumMilligrams, PotassiumMilligrams = detail.PotassiumMilligrams, IsStarred = newState }; // Return a value indicating whether the update succeeded return(service.UpdateFoodItem(updatedFoodItem)); }
public async Task<IActionResult> Index() { var foodItems = await FoodItemService.GetAllFoodItemsAsync(); ViewBag.FoodItems = Mapper.Map<IList<FoodItemViewModel>>(foodItems); return View(); }
private void lblInventory_Click(object sender, EventArgs e) { FoodItemService foodItemService = serviceFactory.GetFoodItemService(); ShowDetailsOfFoodMenu(foodItemService.GetFoodMenu()); grpBxInventory.Show(); grpProfile.Hide(); }
private async void GetFoodItems() { var foods = new FoodItemService(); var items = await foods.GetFoodItemsAsync(); foreach (var item in items) { FoodItems.Add(item); } }
public async Task<IActionResult> DeleteFoodItem(Guid foodId) { if (foodId == null) { throw new ArgumentException("Id wrong", nameof(foodId)); } if (await FoodItemService.DeleteFoodItemAsync(foodId)) { } return Json(true); }
public async Task<IActionResult> EditFoodItem(FoodItemViewModel model) { if (!ModelState.IsValid) { throw new ArgumentException("Model wrong", nameof(model)); } var mappedModel = Mapper.Map<FoodItem>(model); if (await FoodItemService.EditFoodItemAsync(mappedModel)) { Response.StatusCode = (int)HttpStatusCode.OK; return RedirectToAction("Index"); } return Json(new { success = false }); }
private void dataGridViewFoodItem_CellClick(object sender, DataGridViewCellEventArgs e) { FoodItemService foodItemService = serviceFactory.GetFoodItemService(); ShowDetailsOfFoodItems(foodItemService.GetFoodItem(foodMenuList[e.RowIndex].Id)); }
public FoodItemController(FoodItemService foodItemService) { _foodItemService = foodItemService; }