protected async Task HandleValidSubmit() { Mapper.Map(InvoiceViewModel, Invoice); InvoiceServiceResponse response = null; if (Invoice.InvoiceNumber != new Guid()) { Invoice result = null; result = await InvoiceService.UpdateInvoice(Invoice); ToastService.ShowSuccess(Invoice.Description + " was updated successfully"); NavigationManager.NavigateTo("/"); } else { response = await InvoiceService.CreateInvoice(Invoice); if (response.ResponseCode == StatusCodes.Status422UnprocessableEntity || response.ResponseCode == StatusCodes.Status409Conflict) { ToastService.ShowError(response.ResponseMessage); } if (response.ResponseCode == StatusCodes.Status201Created) { ToastService.ShowSuccess(response.ResponseMessage); NavigationManager.NavigateTo("/"); } } }
public async Task <ActionResult <InvoiceServiceResponse> > CreateInvoice(Invoice invoice) { var response = new InvoiceServiceResponse(); try { if (invoice == null) { response.ResponseCode = StatusCodes.Status422UnprocessableEntity; response.ResponseMessage = "Invalid data supplied"; return(response); } var inv = await _invoiceRepository.GetInvoiceByOrderNuber(invoice.OrderNumber); if (inv != null) { response.ResponseCode = StatusCodes.Status409Conflict; response.ResponseMessage = "Duplicate data is not allowed,Order number already in use."; return(response); } var createdInvoice = await _invoiceRepository.AddInvoice(invoice); response.ResponseCode = StatusCodes.Status201Created; response.ResponseMessage = createdInvoice.Description + " was created successfully"; return(response); } catch (Exception exp) { response.ResponseCode = StatusCodes.Status500InternalServerError; response.ResponseMessage = "Internal server error occurred " + exp.StackTrace; return(response); } }