public async Task <OperationResult <InvoiceDetailsVM> > AddInvoice(InvoiceCreateDto invoice, CancellationToken cancellationToken) { var requestUrl = $"{_url}"; var result = await _apiClient.PostAsync <InvoiceCreateDto, OperationResult <InvoiceDetailsVM> >(requestUrl, invoice); return(result); }
//C public async Task <Invoice> CreateInvoiceAsync(InvoiceCreateDto obj) { var invoice = _mapper.Map <Invoice>(obj); _invoiceRepo.Insert(invoice); await _invoiceRepo.Save(); return(_invoiceRepo.GetInvoiceWithCustomerById(invoice.Id)); }
public void Add(InvoiceCreateDto item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } base.Add(Mapper.Map <Invoice>(item)); SaveChanges(); }
public async Task <IActionResult> Create([Bind("Supplier,DateIssued,Currency,Amount,Description")] InvoiceCreateDto invoiceCreateDto) { if (!ModelState.IsValid) { return(View(invoiceCreateDto)); } var result = await _invoiceManagerApi.AddInvoice(invoiceCreateDto, new CancellationToken()); if (!result.Success) { return(View("InvoiceError")); } return(RedirectToAction(nameof(Index))); }
public IActionResult AddInvoice([FromBody, Required] InvoiceCreateDto invoiceCreateDto) { invoiceRepository.Add(invoiceCreateDto); return(Ok()); //if (!_InvoiceRepository.Save()) //{ // throw new Exception("Creating a Invoiceitem failed on save."); //} //Invoice newInvoiceItem = _InvoiceRepository.GetSingle(toAdd.Id); //return CreatedAtRoute(nameof(GetSingleInvoice), new { id = newInvoiceItem.Id }, // Mapper.Map<InvoiceDto>(newInvoiceItem)); }
public async Task <IActionResult> AddInvoice([FromBody] InvoiceCreateDto obj) { var customer = _salesService.GetCustomerById(obj.CustomerId); if (customer is null) { return(BadRequest("Customer not exists")); } try { Invoice invoice = await _salesService.CreateInvoiceAsync(obj); return(Ok(invoice)); } catch (Exception ex) { _logger.LogError(ex, "Couldn't add invoice to database"); return(BadRequest("Failed to add invoice to database")); } }
public InvoicesCreateCommand(InvoiceCreateDto dto) { Dto = dto ?? throw new ArgumentNullException($"dto cant be null {nameof(dto)}"); }