public async Task <Order> AddSingleOrderAsync(Product product, OrderSingleProductDto model) { var order = new Order { CreateDate = _dateService.UtcNow(), ModifyDate = _dateService.UtcNow(), ProductId = product.Id, ProductModelId = model.SelectedProductModelId, ProductTitle = product.Title, Quantity = model.Quantity, Status = InvoiceOrderStatus.Added, UnitPrice = product.Price, TaxAmount = product.TaxAmount, TaxPercent = product.TaxPercent, UnitName = product.UnitName, //DiscountPercent = TODO: Get DiscountPercent from Price entity //DiscountValue TODO : Get DiscountValue form Price entity TotalPrice = product.Price.Calculate(taxAmount: product.TaxAmount, taxPercent: product.TaxPercent, discountValue: 0, discountPercent: null, quantity: model.Quantity) }; product.Orders.Add(order); return(await Task.FromResult(order)); }
public async Task <Basket> AddBasketAsync( Customer customer, Product product, ProductModel productModel, OrderSingleProductDto order) { customer.CheckArgumentIsNull(nameof(customer)); order.CheckArgumentIsNull(nameof(order)); var basket = new Basket { CreateDate = _dateService.UtcNow(), CreatedFormUrl = AppHttpContext.AbsoluteUrl, Ip = AppHttpContext.IpAddress, ModifyDate = _dateService.UtcNow(), SessionId = AppHttpContext.SessionId, UserAgent = AppHttpContext.UserAgent, Status = BasketStatus.Active, WebsiteId = _websiteInfo.Id }; var basketItem = new BasketItem { CreateDate = _dateService.UtcNow(), ModifyDate = _dateService.UtcNow(), ProductId = product.Id, ProductTitle = product.Title, ProductModelId = productModel?.Id, ProductModelTitle = productModel?.Title, Quantity = order.Quantity, Status = BasketItemStatus.Added, UnitName = product.UnitName, UnitPrice = (productModel != null ? productModel.Price : product.Price), //DiscountValue TODO: Calculate Discount TaxAmount = product.TaxAmount, TotalPrice = product.Price.Calculate(taxAmount: product.TaxAmount, taxPercent: product.TaxPercent, discountValue: 0, discountPercent: null, quantity: order.Quantity) }; basketItem.TaxAmount = basketItem.TaxAmount .CalculateTaxAmount(basketItem.TotalPrice, product.TaxPercent); basket.Items.Add(basketItem); basket.TotalPrice = basket.Items.CalculateTotalPrice(); customer.Baskets.Add(basket); return(await Task.FromResult(basket)); }
public async Task <CustomerInvoiceDto> CreateInvoiceAsync(OrderSingleProductDto model) { model.CheckArgumentIsNull(nameof(model)); if (model.NationalCode.IsNullOrEmpty()) { throw new EntityInsufficientDataException(nameof(model.NationalCode)); } var product = await _productRepository.FindAsync(model.ProductId); ProductModel productModel = null; if (model.SelectedProductModelId.HasValue) { productModel = await _productModelRepository .FindAsync(model.SelectedProductModelId.Value); } var customer = await _customerRepository.GetByNationalCodeAsync(model.NationalCode); var shippingAddress = _shippingAddressFactory.BuildShippingAddress(model.ShippingAddress); if (customer == null) { customer = _customerFactory.BuildRealCustomerFromOrder(model); _customerValidator.ValidateCreate(customer); _customerRepository.MarkForAdd(customer); } customer.ShippingAddresses.Add(shippingAddress); var invoice = _customerFactory.AddInvoice( customer, product, productModel, model, _dateService.UtcNow(), shippingAddress); await _customerRepository.SaveChangesAsync(); return(customer.MapToResult(invoice, shippingAddress)); }
public Customer BuildRealCustomerFromOrder(OrderSingleProductDto model) { model.CheckArgumentIsNull(nameof(model)); var customer = new Customer { CreateDate = _dateService.UtcNow(), ModifyDate = _dateService.UtcNow(), Email = model.Email.Trim(), FirstName = model.FirstName.ApplyCorrectYeKe().Trim(), LastName = model.LastName.ApplyCorrectYeKe().Trim(), Mobile = model.Mobile.Trim(), PersonalityType = CustomerPersonalityType.Real, NationalCode = model.NationalCode.Trim(), Status = CustomerStatus.Enabled, WebsiteId = _websiteInfo.Id }; //customer.ShippingAddresses // .Add(_shippingAddressFactory // .BuildShippingAddress(model.ShippingAddress)); return(customer); }
public Invoice AddInvoice( Customer customer, Product product, ProductModel productModel, OrderSingleProductDto order, DateTime dueDate, ShippingAddress shippingAddress, int?shippingId = null) { customer.CheckArgumentIsNull(nameof(customer)); order.CheckArgumentIsNull(nameof(order)); var invoice = new Invoice { CreateDate = _dateService.UtcNow(), CustomerId = customer.Id, ModifyDate = _dateService.UtcNow(), ShippingAddress = shippingAddress, ShippingId = shippingId != null ? shippingId.Value : _websiteInfo.DefaultShippingId.Value, Status = InvoiceStatus.Issued, DueDate = dueDate, WebsiteId = _websiteInfo.Id }; var invoiceItem = new Order { CreateDate = _dateService.UtcNow(), DiscountPercent = null, DiscountValue = 0, ModifyDate = _dateService.UtcNow(), ProductId = product.Id, ProductModelId = productModel?.Id, ProductModelTitle = productModel?.Title, Quantity = order.Quantity, ShippingAddress = shippingAddress, Status = invoice.Status.GetOrderStatus(), ShippingId = invoice.ShippingId, TaxAmount = product.TaxAmount, ProductTitle = product.Title, TaxPercent = product.TaxPercent, UnitPrice = (productModel != null ? productModel.Price : product.Price), UnitName = product.UnitName, TotalPrice = product.Price.Calculate(taxAmount: product.TaxAmount, taxPercent: product.TaxPercent, discountValue: 0, discountPercent: null, quantity: order.Quantity) }; if (productModel != null) { invoiceItem.TotalPrice = productModel.Price.Calculate( taxAmount: product.TaxAmount, taxPercent: product.TaxPercent, discountValue: 0, discountPercent: null, quantity: order.Quantity); } invoiceItem.TaxAmount = invoiceItem.TaxAmount .CalculateTaxAmount(invoiceItem.TotalPrice, product.TaxPercent); invoice.Orders.Add(invoiceItem); invoice.TotalPrice = invoice.Orders.CalculateTotalPrice(); customer.Invoices.Add(invoice); return(invoice); }