Beispiel #1
0
        public async Task <AddDishResponse> AddDish(AddDishRequest addDishRequest)
        {
            AddDishResponse addDishResponse = addDishRequest.IsValid();

            if (addDishResponse.Success)
            {
                try
                {
                    Dish dish = MapToDataBaseModel(addDishRequest);
                    await _dishRepository.Create(dish);

                    addDishResponse.Id = dish.Id.ToString();
                }
                catch (TimeoutException)
                {
                    addDishResponse.SetError(ErrorMessage.TimeoutError);
                }
                catch (Exception ex)
                {
                    addDishResponse.SetError(ex);
                }
            }

            return(addDishResponse);
        }
Beispiel #2
0
        public async Task <IActionResult> AddDish([FromBody] DishModel dishModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            List <DishRecipe> recipes = new List <DishRecipe>();
            var Id    = Guid.NewGuid();
            var image = await _imageRepository.GetById(Guid.Parse(dishModel.File));

            foreach (RecipeModel recipe in dishModel.Recipes)
            {
                recipes.Add(new DishRecipe()
                {
                    DishId   = Id,
                    RecipeId = Guid.Parse(recipe.Id)
                });
            }

            Dish dish = new Dish()
            {
                Id        = Id,
                DishImage = image,
                DishPrice = dishModel.Price,
                Name      = dishModel.Dish,
                Recipes   = recipes
            };

            _dishRepository.Create(dish);

            return(Ok());
        }
Beispiel #3
0
 public async Task Create(Dish product)
 {
     if (product is null)
     {
         throw new ArgumentNullException("Dish doesn't exist");
     }
     await _dishRepository.Create(product);
 }
Beispiel #4
0
 // POST: api/Dish
 public void Post([FromBody] Dish value)
 {
     try
     {
         _repo.Create(value);
     }
     catch (Exception e)
     {
         _logger.Error(e);
         throw;
     }
 }
Beispiel #5
0
        public async Task CreateAsync(DishDto dish)
        {
            var origDish = _mapper.Map <DishDto, Dish>(dish);

            var dishes = await _dishRepository.GetAll();

            var isDish = dishes.Any(d => d.Name == dish.Name);

            if (isDish)
            {
                throw new BadRequestException("Dish with the same name is exist.");
            }

            await _dishRepository.Create(origDish);
        }
            async Task <ResponseWrapper <Create> > IRequestHandler <Command, ResponseWrapper <Create> > .Handle(Command request, CancellationToken cancellationToken)
            {
                var dish = _mapper.Map <Command, Dish>(request);

                dish.CreatedAt = DateTime.Now;
                dish.UpdatedAt = DateTime.Now;
                try
                {
                    await _context.Create(dish);

                    _logger.LogInformation("Successfully created the dish");
                    var responseWrapper = ResponseWrapper <Create> .GetInstance((int)HttpStatusCode.OK, null, true, null);

                    return(responseWrapper);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Problem saving new dish");
                    throw new Exception("Problem saving new dish");
                }
            }
Beispiel #7
0
        public async Task <IActionResult> Post(string collection, [FromBody] Dish dish)
        {
            await _dishRepository.Create(collection, dish);

            return(new ObjectResult(dish));
        }