public ActionResult <Coffee> Post([FromBody] Coffee coffee) { //Exceptions! //Mangler Exception for samme navn! if (string.IsNullOrEmpty(coffee.CoffeeName)) { return(BadRequest("Coffee Name Required!")); } if (double.IsNegative(coffee.CoffeePrice) || coffee.CoffeePrice < 1) { return(BadRequest("Coffee needs a price above 1!")); } if (coffee.CoffeeStrength < 0) { return(BadRequest("The lowest strength is 0!")); } if (coffee.CoffeeStrength > 5) { return(BadRequest("The highest coffee strength is 5!")); } if (string.IsNullOrEmpty(coffee.CoffeeDescription)) { return(BadRequest("You need to insert a description!")); } return(_CoffeeService.CreateCoffee(coffee)); }
public async Task <ActionResult> AddCoffee([FromBody] AddCoffeeDto coffeeDto) { try { using (_cofeelogger.BeginScope($"API-AddCoffee {DateTime.UtcNow}")) { var result = await _coffeeService.CreateCoffee(coffeeDto).ConfigureAwait(false); _cofeelogger.LogInformation($"API-AddCoffee {DateTime.UtcNow}"); return(StatusCode((int)result.statusCode, result.coffeeId)); } } catch (Exception ex) { _cofeelogger.LogError (ex, $"API-AddCoffee-Exception {DateTime.UtcNow}" ); return(StatusCode((int)HttpStatusCode.BadRequest, _apiSettings.IsSecuredEnvironment ? "An error occured while processing AddCoffee" : ex.ToString())); } }