Exemple #1
0
        public async Task <IActionResult> Create(DishEditViewModel dishEditViewModel, IFormFile uploadedImage)
        {
            try
            {
                DishEditDTO dishEditDTO = new DishEditDTO()
                {
                    Name        = dishEditViewModel.Name,
                    Description = dishEditViewModel.Description,
                    Weight      = dishEditViewModel.Weight,
                    Price       = dishEditViewModel.Price,
                    DishGroupId = dishEditViewModel.DishGroupId,
                    ImageURL    = "/images/No_Image_Available.jpg"
                };

                bool response = await _dishService.CreateNewDishAsync(dishEditDTO);

                if (response)
                {
                    dishEditDTO.ImageURL = await SaveDishImageAsync(uploadedImage, dishEditDTO.Id);

                    bool responseImg = await _dishService.EditDishImageAsync(dishEditDTO);

                    if (responseImg)
                    {
                        return(RedirectToAction("Info", new { id = dishEditDTO.Id }));
                    }
                }
            }
            catch (Exception ex)
            {
                //logging
            }

            return(ErrorView());
        }