public async Task <ActionResult <InvoiceLineApiModel> > Put(int id, [FromBody] InvoiceLineApiModel input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } if (await _chinookSupervisor.GetInvoiceLineByIdAsync(id, ct) == null) { return(NotFound()); } var errors = JsonConvert.SerializeObject(ModelState.Values .SelectMany(state => state.Errors) .Select(error => error.ErrorMessage)); Debug.WriteLine(errors); if (await _chinookSupervisor.UpdateInvoiceLineAsync(input, ct)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public ActionResult <InvoiceLineApiModel> Put([FromRoute] int id, [FromBody] InvoiceLineApiModel input) { try { if (input == null) { return(BadRequest()); } if (_chinookSupervisor.GetInvoiceLineById(id) == null) { return(NotFound()); } // var errors = JsonConvert.SerializeObject(ModelState.Values // .SelectMany(state => state.Errors) // .Select(error => error.ErrorMessage)); // Debug.WriteLine(errors); if (_chinookSupervisor.UpdateInvoiceLine(input)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public InvoiceLineApiModel AddInvoiceLine(InvoiceLineApiModel newInvoiceLineApiModel) { var invoiceLine = newInvoiceLineApiModel.Convert(); invoiceLine = _invoiceLineRepository.Add(invoiceLine); newInvoiceLineApiModel.InvoiceLineId = invoiceLine.InvoiceLineId; return(newInvoiceLineApiModel); }
public ActionResult <InvoiceLineApiModel> Post([FromBody] InvoiceLineApiModel input) { try { if (input == null) { return(BadRequest()); } return(StatusCode(201, _chinookSupervisor.AddInvoiceLine(input))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <InvoiceLineApiModel> AddInvoiceLineAsync(InvoiceLineApiModel newInvoiceLineViewModel, CancellationToken ct = default) { var invoiceLine = new InvoiceLine { InvoiceId = newInvoiceLineViewModel.InvoiceId, TrackId = newInvoiceLineViewModel.TrackId, UnitPrice = newInvoiceLineViewModel.UnitPrice, Quantity = newInvoiceLineViewModel.Quantity }; invoiceLine = await _invoiceLineRepository.AddAsync(invoiceLine, ct); newInvoiceLineViewModel.InvoiceLineId = invoiceLine.InvoiceLineId; return(newInvoiceLineViewModel); }
public bool UpdateInvoiceLine(InvoiceLineApiModel invoiceLineApiModel) { var invoiceLine = _invoiceLineRepository.GetById(invoiceLineApiModel.InvoiceId); if (invoiceLine == null) { return(false); } invoiceLine.InvoiceLineId = invoiceLineApiModel.InvoiceLineId; invoiceLine.InvoiceId = invoiceLineApiModel.InvoiceId; invoiceLine.TrackId = invoiceLineApiModel.TrackId; invoiceLine.UnitPrice = invoiceLineApiModel.UnitPrice; invoiceLine.Quantity = invoiceLineApiModel.Quantity; return(_invoiceLineRepository.Update(invoiceLine)); }
public async Task <bool> UpdateInvoiceLineAsync(InvoiceLineApiModel invoiceLineViewModel, CancellationToken ct = default) { var invoiceLine = await _invoiceLineRepository.GetByIdAsync(invoiceLineViewModel.InvoiceId, ct); if (invoiceLine == null) { return(false); } invoiceLine.InvoiceLineId = invoiceLineViewModel.InvoiceLineId; invoiceLine.InvoiceId = invoiceLineViewModel.InvoiceId; invoiceLine.TrackId = invoiceLineViewModel.TrackId; invoiceLine.UnitPrice = invoiceLineViewModel.UnitPrice; invoiceLine.Quantity = invoiceLineViewModel.Quantity; return(await _invoiceLineRepository.UpdateAsync(invoiceLine, ct)); }
public async Task <ActionResult <InvoiceLineApiModel> > Post([FromBody] InvoiceLineApiModel input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } return(StatusCode(201, await _chinookSupervisor.AddInvoiceLineAsync(input, ct))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <InvoiceLineApiModel> AddInvoiceLineAsync(InvoiceLineApiModel newInvoiceLineViewModel, CancellationToken ct = default) { /*var invoiceLine = new InvoiceLine * { * InvoiceId = newInvoiceLineViewModel.InvoiceId, * TrackId = newInvoiceLineViewModel.TrackId, * UnitPrice = newInvoiceLineViewModel.UnitPrice, * Quantity = newInvoiceLineViewModel.Quantity * };*/ var invoiceLine = newInvoiceLineViewModel.Convert; invoiceLine = await _invoiceLineRepository.AddAsync(invoiceLine, ct); newInvoiceLineViewModel.InvoiceLineId = invoiceLine.InvoiceLineId; return(newInvoiceLineViewModel); }