예제 #1
0
        //Helper methods
        private FoodItemService CreateFoodItemService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new FoodItemService(userId);

            return(service);
        }
예제 #2
0
        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));
        }
예제 #3
0
        public async Task<IActionResult> Index()
        {
            var foodItems = await FoodItemService.GetAllFoodItemsAsync();

            ViewBag.FoodItems = Mapper.Map<IList<FoodItemViewModel>>(foodItems);

            return View();
        }
예제 #4
0
        private void lblInventory_Click(object sender, EventArgs e)
        {
            FoodItemService foodItemService = serviceFactory.GetFoodItemService();

            ShowDetailsOfFoodMenu(foodItemService.GetFoodMenu());

            grpBxInventory.Show();
            grpProfile.Hide();
        }
예제 #5
0
        private async void GetFoodItems()
        {
            var foods = new FoodItemService();
            var items = await foods.GetFoodItemsAsync();

            foreach (var item in items)
            {
                FoodItems.Add(item);
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
        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 });
        }
예제 #8
0
        private void dataGridViewFoodItem_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            FoodItemService foodItemService = serviceFactory.GetFoodItemService();

            ShowDetailsOfFoodItems(foodItemService.GetFoodItem(foodMenuList[e.RowIndex].Id));
        }
예제 #9
0
 public FoodItemController(FoodItemService foodItemService)
 {
     _foodItemService = foodItemService;
 }