Example #1
0
        public int SaveSalesOrderHeader(SalesOrderDTO salesOrder)
        {
            ProductDetails         productDetails     = GetListOfProductsForThisOrder(salesOrder.ProductWithQuantity);
            List <CustomerAddress> lstCustomerAddress = _customerAddressRepository.GetMany(x => x.CustomerID == salesOrder.CustomerID).ToList();
            var objSalesOrder = new SalesOrderHeader();

            objSalesOrder.RevisionNumber      = 2;
            objSalesOrder.OrderDate           = DateTime.Now;
            objSalesOrder.DueDate             = objSalesOrder.OrderDate.AddDays(12);
            objSalesOrder.ShipDate            = objSalesOrder.OrderDate.AddDays(7);
            objSalesOrder.Status              = 5;
            objSalesOrder.PurchaseOrderNumber = "PO" + salesOrder.CustomerID + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Hour;
            objSalesOrder.OnlineOrderFlag     = true;
            objSalesOrder.CustomerID          = salesOrder.CustomerID;
            foreach (CustomerAddress customerAddress in lstCustomerAddress)
            {
                if (customerAddress.AddressType.Equals("Shipping"))
                {
                    objSalesOrder.ShipToAddressID = customerAddress.AddressID;
                }
                else
                {
                    objSalesOrder.BillToAddressID = customerAddress.AddressID;
                }
            }
            objSalesOrder.ShipMethod   = "CARGO TRANSPORT 5";
            objSalesOrder.SubTotal     = productDetails.totalPrice;
            objSalesOrder.TaxAmt       = decimal.Multiply(productDetails.totalPrice, 0.08M);
            objSalesOrder.Freight      = decimal.Multiply(objSalesOrder.TaxAmt, 0.30M);
            objSalesOrder.Comment      = "Online Order";
            objSalesOrder.rowguid      = Guid.NewGuid();
            objSalesOrder.ModifiedDate = DateTime.Now;

            _salesOrderHeaderRepository.Add(objSalesOrder);
            _unitOfWork.Commit();

            SaveSalesOrderDetails(productDetails, objSalesOrder.SalesOrderID);
            return(objSalesOrder.SalesOrderID);
        }
Example #2
0
        private void SaveOrUpdateAddress(CustomerDTO customer, int customerID)
        {
            List <CustomerAddress> lstCustomerAddress = _customerAddressRepository.GetMany(x => x.CustomerID == customer.CustomerID).ToList();

            if (lstCustomerAddress.Count == 0)
            {
                Address objBillingAddress = new Address();
                objBillingAddress.AddressLine1  = customer.BillingAddressLine1;
                objBillingAddress.AddressLine2  = customer.BillingAddressLine2;
                objBillingAddress.City          = customer.BillingCity;
                objBillingAddress.StateProvince = customer.BillingStateProvince;
                objBillingAddress.CountryRegion = customer.BillingCountryRegion;
                objBillingAddress.PostalCode    = customer.BillingPostalCode;
                objBillingAddress.ModifiedDate  = DateTime.Now;
                objBillingAddress.rowguid       = Guid.NewGuid();
                _addressRepository.Add(objBillingAddress);
                _unitOfWork.Commit();

                CustomerAddress objCustomerBillingAddress = new CustomerAddress();
                objCustomerBillingAddress.CustomerID   = customerID;
                objCustomerBillingAddress.AddressID    = objBillingAddress.AddressID;
                objCustomerBillingAddress.AddressType  = "Main Office";
                objCustomerBillingAddress.ModifiedDate = DateTime.Now;
                objCustomerBillingAddress.rowguid      = Guid.NewGuid();
                _customerAddressRepository.Add(objCustomerBillingAddress);
                _unitOfWork.Commit();

                Address objShippingAddress = new Address();
                objShippingAddress.AddressLine1  = customer.ShippingAddressLine1;
                objShippingAddress.AddressLine2  = customer.ShippingAddressLine2;
                objShippingAddress.City          = customer.ShippingCity;
                objShippingAddress.StateProvince = customer.ShippingStateProvince;
                objShippingAddress.CountryRegion = customer.ShippingCountryRegion;
                objShippingAddress.PostalCode    = customer.ShippingPostalCode;
                objShippingAddress.ModifiedDate  = DateTime.Now;
                objShippingAddress.rowguid       = Guid.NewGuid();
                _addressRepository.Add(objShippingAddress);
                _unitOfWork.Commit();

                CustomerAddress objCustomerShippingAddress = new CustomerAddress();
                objCustomerShippingAddress.CustomerID   = customerID;
                objCustomerShippingAddress.AddressID    = objShippingAddress.AddressID;
                objCustomerShippingAddress.AddressType  = "Shipping";
                objCustomerShippingAddress.ModifiedDate = DateTime.Now;
                objCustomerShippingAddress.rowguid      = Guid.NewGuid();
                _customerAddressRepository.Add(objCustomerShippingAddress);
                _unitOfWork.Commit();
            }
            else
            {
                foreach (CustomerAddress objCustomerAddress in lstCustomerAddress)
                {
                    Address objAddress = _addressRepository.GetById(objCustomerAddress.AddressID);

                    if (objCustomerAddress.AddressType.Equals("Shipping"))
                    {
                        objAddress.AddressLine1  = customer.ShippingAddressLine1;
                        objAddress.AddressLine2  = customer.ShippingAddressLine2;
                        objAddress.City          = customer.ShippingCity;
                        objAddress.StateProvince = customer.ShippingStateProvince;
                        objAddress.CountryRegion = customer.ShippingCountryRegion;
                        objAddress.PostalCode    = customer.ShippingPostalCode;
                        objAddress.ModifiedDate  = DateTime.Now;
                        objAddress.rowguid       = Guid.NewGuid();
                        _addressRepository.Update(objAddress);
                        _unitOfWork.Commit();
                    }
                    else
                    {
                        objAddress.AddressLine1  = customer.BillingAddressLine1;
                        objAddress.AddressLine2  = customer.BillingAddressLine2;
                        objAddress.City          = customer.BillingCity;
                        objAddress.StateProvince = customer.BillingStateProvince;
                        objAddress.CountryRegion = customer.BillingCountryRegion;
                        objAddress.PostalCode    = customer.BillingPostalCode;
                        objAddress.ModifiedDate  = DateTime.Now;
                        objAddress.rowguid       = Guid.NewGuid();
                        _addressRepository.Update(objAddress);
                        _unitOfWork.Commit();
                    }
                }
            }
        }