public async Task <ActionResult> InsertAsync([FromBody] AddBarbequeModel model) { try { if (string.IsNullOrEmpty(model.Description)) { throw new ArgumentNullException(nameof(model.Description)); } if (model.EventDateTime == null) { throw new ArgumentNullException(nameof(model.EventDateTime)); } return(Json(await _barbequeService.AddAsync(model))); } catch (Exception ex) { if (ex is ArgumentNullException || ex is ArgumentException) { return(BadRequest(ex)); } if (ex is ApplicationException) { return(UnprocessableEntity(ex)); } return(StatusCode(500, new Exception("Ops, tivemos um problema"))); } }
public async Task <Barbeque> UpdateAsync(int id, AddBarbequeModel updatedBbq) { Barbeque bbq = new Barbeque(updatedBbq.Description, updatedBbq.EventDateTime); bbq.Id = id; return(await _barbequeRepository.Update(bbq)); }
public async Task <ActionResult> UpdateAsync(int id, [FromBody] AddBarbequeModel data) { try { if (data.EventDateTime == null) { throw new ArgumentNullException(nameof(data.EventDateTime)); } if (!(id >= 1)) { throw new ArgumentException(nameof(id)); } return(Json(await _barbequeService.UpdateAsync(id, data))); } catch (Exception ex) { if (ex is ArgumentNullException || ex is ArgumentException) { return(BadRequest(ex)); } if (ex is ApplicationException) { return(UnprocessableEntity(ex)); } return(StatusCode(500, new Exception("Ops, tivemos um problema"))); } }
public async Task <Barbeque> AddAsync(AddBarbequeModel insertedBbq) { Barbeque bbq = new Barbeque(insertedBbq.Description, insertedBbq.EventDateTime); return(await _barbequeRepository.AddAsync(bbq)); }