public IActionResult UpdateTopping(long id, [FromBody] ToppingDto updatedTopping) { var updatingTopping = _context.Toppings.IgnoreQueryFilters() .FirstOrDefault(x => x.Id == id); if (updatingTopping == null) { return(BadRequest(new { Success = false, Message = $"Couldn't find a topping with the ID {id}!" })); } updatingTopping.Name = updatedTopping.Name; updatingTopping.Active = updatedTopping.Active; _context.SaveChanges(); return(Ok(new { Success = true, Toppings = _context.Toppings.ToList() })); }
public IActionResult InsertTopping([FromBody] ToppingDto newTopping) { if (!ModelState.IsValid) { return(BadRequest(new { Success = false, Message = ModelState.Values.FirstOrDefault()?.Errors.FirstOrDefault()?.ErrorMessage })); } var topping = new Topping { Name = newTopping.Name }; _context.Toppings.Add(topping); _context.SaveChanges(); return(Ok(new { Success = true, Toppings = _context.Toppings.ToList() })); }