public async Task <ActionResult> InsertAsync([FromBody] AddBarbequeParticipantModel data) { try { if (string.IsNullOrEmpty(data.Name)) { throw new ArgumentNullException(nameof(data.Name)); } if (!(data.Contribution >= 0)) { throw new ArgumentException(nameof(data.Contribution)); } if (!(data.BarbequeId >= 1)) { throw new ArgumentException(nameof(data.BarbequeId)); } return(Json(await _bbqParticipantsService.AddAsync(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 <BarbequeParticipant> AddAsync(AddBarbequeParticipantModel participantData) { BarbequeParticipant participant = new BarbequeParticipant( participantData.BarbequeId, participantData.Name, participantData.Contribution, participantData.Paid ); return(await _barbequeParticipantsRepository.AddAsync(participant)); }
public async Task <BarbequeParticipant> UpdateAsync(int id, AddBarbequeParticipantModel participantData) { BarbequeParticipant participant = new BarbequeParticipant( participantData.BarbequeId, participantData.Name, participantData.Contribution, participantData.Paid ); participant.Id = id; return(await _barbequeParticipantsRepository.Update(participant)); }