public async Task <IActionResult> Post([FromBody] AddNewInvoiceRequest request) { AddNewInvoiceResponse result = await _InvoiceAppService.addNewInvoice(request); if (result.Success) { return(Ok(result)); } return(NotFound(result)); }
public Task <AddNewInvoiceResponse> addNewInvoice(AddNewInvoiceRequest request) { DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(request.DeliveryTime).ToLocalTime(); List <InvoiceItem> items = new List <InvoiceItem>(); int totalPrice = 0; decimal totalWeight = 0; foreach (InvoiceItemModel invoiceItem in request.Items) { totalPrice += invoiceItem.TotalPrice; decimal weightPerUnit = _ProductRepository.GetWeightPerUnit(invoiceItem.ProductID, invoiceItem.UnitID); invoiceItem.Weight = weightPerUnit * invoiceItem.Quantity; totalWeight += invoiceItem.Weight; } AddNewInvoiceCommand command = new AddNewInvoiceCommand() { Address = request.Address, CustomerCode = request.CustomerCode, CustomerID = request.CustomerID, CustomerName = request.CustomerName, DeliveryTime = dtDateTime, Code = Guid.NewGuid().ToString().Substring(0, 8), TotalPrice = totalPrice, WeightTotal = totalWeight, Items = request.Items }; Task <object> Invoice = (Task <object>)Bus.SendCommand(command); RabbitMQBus.Publish(command); AddNewInvoiceResponse response = new AddNewInvoiceResponse(); response = Common <AddNewInvoiceResponse> .checkHasNotification(_notifications, response); if (response.Success) { response.Data = (int)Invoice.Result; } return(Task.FromResult(response)); }