public async Task Create(FoodAddInfo info) { var model = _mapper.Map <FoodAddInfo, Food>(info); _db.Foods.Add(model); await _db.SaveChangesAsync(); }
public async Task <IActionResult> Create(FoodAddInfo food) { try { var result = await _mediator.Send(new FoodCreateCommand() { Description = food.Description, FoodType = food.FoodType, Name = food.Name, Price = food.Price }); if (result.Success) { return(Ok(result.Result)); } else { return(BadRequest(result.ErrorMessage)); } } catch (Exception e1) { return(BadRequest(e1.Message)); } }
public async Task <IActionResult> Create(FoodAddInfo model) { var result = await _mediator.Send(new FoodCreateCommand { Name = model.Name, Price = model.Price, Description = model.Description, FoodType = model.FoodType }); if (result.Success) { return(Ok(result.Result)); } else { return(BadRequest(result.ErrorMessage)); } }