public async Task <bool> AddInvoice(InvoiceAuthRequestViewModel invoice) { try { var url = _routerService.GetRedirectUrl(invoice.Username, invoice.Password); if (string.IsNullOrEmpty(url)) { throw new InvalidCredentialException(); } url += "/api/invoice"; var responseString = await HTTPRequestSender.PostAsync(url, invoice); var responseUser = JsonConvert.DeserializeObject <bool>(responseString); return(responseUser); } catch (Exception e) { var errorResponse = JsonConvert.DeserializeObject <ErrorResponseViewModel>(e.Message); if (errorResponse.Id == (int)ErrorResponseIds.InvoiceAlreadyExist) { throw new InvoiceAlreadyExistException(); } throw; } }
public async Task <IActionResult> AddInvoice([FromBody] InvoiceAuthRequestViewModel invoice) { try { await _utilityService.AddInvoice(invoice); } catch (InvoiceAlreadyExistException) { return(Conflict(new ErrorResponseViewModel { Id = (int)ErrorResponseIds.InvoiceAlreadyExist, Message = "Invoice already added" })); } catch (InvalidCredentialException) { return(Conflict(new ErrorResponseViewModel { Id = 404, Message = "Invalid credentials" })); } catch (Exception) { return(Conflict(new ErrorResponseViewModel { Id = 400, Message = "ceva o crapat" })); } return(Ok(true)); }