public async Task Create(DrinkDTO drink) { if (drink.Name == "") { throw new Exception("o nome deve ser informado"); } else { drink.Name = drink.Name.Trim(); if (drink.Name.Length < 2 || drink.Name.Length > 50) { throw new Exception("o nome deve conter de 2 a 50 caracteres"); } } if (drink.Description == "") { throw new Exception("a descirção deve ser informada"); } else { if (drink.Description.Length < 2 || drink.Description.Length > 100) { throw new Exception("o descirção deve conter de 2 a 100 caracteres"); } } await _drinkRepository.Create(drink); }
//[Authorize(Roles = "ADMIN")] public async Task <IActionResult> Create(Drink drink) { _drinkRepository.Create(drink); await _context.SaveChangesAsync(); return(Redirect("/")); }
public IActionResult Create([FromBody] DrinkDto drinkDto) { var drink = _mapper.Map <Drink>(drinkDto); if (ModelState.IsValid) { try { // save _drinkRepository.Create(drink); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(ex.Message)); } } return(BadRequest(ModelState)); }
public Drink Create(Drink drink) { return(_repository.Create(drink)); }