Esempio n. 1
0
        public async Task <IHttpActionResult> Post([FromBody] Dish dish)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (await DishRepository.ExistsAsync(elem => elem.Name == dish.Name))
            {
                return(BadRequest("The dish name already exists.Please type another one."));
            }
            dish.Id = await DishRepository.GenerateIdAsync();

            DishRepository.Add(dish);
            await UnitOfWork.CommitAsync();

            return(CreatedAtRoute("GetDishById", new { id = dish.Id }, dish));
        }