public Food(AddFoodModel model) { this.Description = model.Description; this.Discount = model.Discount; this.FoodType = model.FoodType; this.Name = model.Name; this.PaymentOption = model.PaymentOption; this.PreparationTime = model.PreparationTime; this.Price = model.Price; }
public IActionResult Post([FromBody] AddFoodModel model) { Food food = new Food(model); _foodrepo.Add(food); if (_foodrepo.SaveChanges() == 0) { throw new ApplicationException("failed to create food"); } var foodDto = _foodMapper.MapFoodDto(food); return(Ok(foodDto)); }
public IActionResult addFood([FromBody] AddFoodModel foodDto) { foodDto.name = foodDto.name.ToLower(); try { // save var food = new Food() { name = foodDto.name, price = foodDto.price, SellerId = foodDto.SellerId, CategoryId = foodDto.CategoryId }; _foodService.Add(food); return(Ok()); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }