Exemplo n.º 1
0
        //Helper methods
        private FoodItemService CreateFoodItemService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new FoodItemService(userId);

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

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

            return View();
        }
Exemplo n.º 4
0
        private void lblInventory_Click(object sender, EventArgs e)
        {
            FoodItemService foodItemService = serviceFactory.GetFoodItemService();

            ShowDetailsOfFoodMenu(foodItemService.GetFoodMenu());

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

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

            ShowDetailsOfFoodItems(foodItemService.GetFoodItem(foodMenuList[e.RowIndex].Id));
        }
Exemplo n.º 9
0
 public FoodItemController(FoodItemService foodItemService)
 {
     _foodItemService = foodItemService;
 }