Beispiel #1
0
        private void InsertOrder()
        {
            var customer = Session[Values.CUSTOMER_SESSION] as CustomerModel;
            var cart     = Session[Values.CartSession] as List <CartItem>;

            if (cart != null && cart.Count > 0)
            {
                var order = new OrderModel()
                {
                    ReceiverName    = _receiverInformation.FullName,
                    ReceiverPhone   = _receiverInformation.MobileNumber,
                    ReceiverAddress = _receiverInformation.Address + ", " + _receiverInformation.Street,
                    CreatedDateTime = DateTime.Now,
                    Amount          = cart.Sum(item => item.Product.Price * item.Quantity),
                    CustomerId      = customer.Id, //Edit later
                    Code            = _codeGeneratingService.GenerateCode(Values.OrderPrefix),
                    PaymentId       = payment.id
                };
                _orderService.InsertOrder(order);

                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetailModel()
                    {
                        OrderId   = order.Id,
                        ProductId = item.Product.Id,
                        UnitPrice = item.Product.Price,
                        Quantity  = item.Quantity
                    };
                    _orderService.InsertOrderDetail(orderDetail);
                    _productService.DescreaseProduct(item.Product.Id, item.Quantity);
                }
                Session.Remove(Values.CartSession);
            }
        }
Beispiel #2
0
        public InvoiceModel CreateNewInvoice(int currentUserId, OrderModel order = null)
        {
            var invoiceModel = new InvoiceModel();

            invoiceModel.CreatedDateTime = DateTime.Now;
            invoiceModel.CreatedBy       = currentUserId;
            invoiceModel.Code            = _codeGeneratingService.GenerateCode(Values.InvoicePrefix);
            if (order != null)
            {
                invoiceModel.OrderId         = order.Id;
                invoiceModel.CustomerAddress = order.ReceiverAddress;
                invoiceModel.CustomerPhone   = order.ReceiverPhone;
                invoiceModel.CustomerName    = order.ReceiverName;
            }

            return(invoiceModel);
        }