public async Task <ActionResult <VendaApiModel> > Put(int id, [FromBody] VendaApiModel input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } if (await _BlazorSupervisor.GetVendaByIdAsync(id, ct) == null) { return(NotFound()); } var errors = JsonConvert.SerializeObject(ModelState.Values .SelectMany(state => state.Errors) .Select(error => error.ErrorMessage)); Debug.WriteLine(errors); if (await _BlazorSupervisor.UpdateVendaAsync(input, ct)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <VendaApiModel> AddVendaAsync(VendaApiModel newVendaApiModel, CancellationToken ct = default) { var Venda = newVendaApiModel.Convert(); Venda = await _vendaRepository.AddAsync(Venda, ct); newVendaApiModel.VendaId = Venda.VendaId; return(newVendaApiModel); }
public async Task <bool> UpdateVendaAsync(VendaApiModel VendaApiModel, CancellationToken ct = default) { var Venda = await _vendaRepository.GetByIdAsync(VendaApiModel.VendaId, ct); if (Venda is null) { return(false); } Venda.VendaId = VendaApiModel.VendaId; return(await _vendaRepository.UpdateAsync(Venda, ct)); }
public async Task <ActionResult <VendaApiModel> > Post([FromBody] VendaApiModel entity, CancellationToken ct = default) { try { if (entity == null) { return(BadRequest()); } return(StatusCode(201, await _BlazorSupervisor.AddVendaAsync(entity, ct))); } catch (Exception ex) { return(StatusCode(500, ex)); } }