private void AddProductsToOrder(TeleOrder ord, ProductsDto[] products)
        {
            if (ord.ShippingCharge == null)
            {
                ord.ShippingCharge = 0;
            }
            if (ord.PromoShipping == null)
            {
                ord.PromoShipping = 0;
            }
            if (ord.PromoProduct == null)
            {
                ord.PromoProduct = 0;
            }

            foreach (var prd in products)
            {
                TeleOrderDetail od = new TeleOrderDetail();
                od.TeleOrder   = ord;
                od.ProdID      = prd.product_id;
                od.CreatedDate = ord.CreatedDate;

                od.Quantity       = prd.quantity;
                od.UnitPrice      = prd.unit_price;
                od.SubTotal       = prd.unit_price * prd.quantity; //prd.sub_total;
                od.PromoProduct   = prd.product_promo;
                od.ShippingCharge = prd.shipping_cost;
                od.PromoShipping  = prd.shipping_promo;

                od.RefillQuantity = prd.refill_quantity;
                od.RefillPrice    = prd.refill_price;
                od.PromoRefill    = prd.refill_promo;
                od.RefillSubTotal = prd.refill_price * prd.refill_quantity;

                if (prd.quantity > 0)
                {
                    ord.ShippingCharge += (prd.shipping_cost * prd.quantity);
                    ord.PromoShipping  += (prd.shipping_promo * prd.quantity);
                    od.TotalAmount      = od.SubTotal + prd.product_promo + (prd.shipping_promo * prd.quantity) + (prd.shipping_cost * prd.quantity); //prd.sub_total;
                }
                if (prd.refill_quantity > 0)
                {
                    ord.ShippingCharge  += (prd.shipping_cost * prd.quantity);
                    ord.PromoShipping   += (prd.shipping_promo * prd.quantity);
                    od.RefillTotalAmount = od.RefillSubTotal + prd.refill_promo + (prd.shipping_promo * prd.refill_quantity) + (prd.shipping_cost * prd.refill_quantity); //prd.sub_total;
                }
                ord.SubTotal        += od.SubTotal;
                ord.RefillSubTotal  += od.RefillSubTotal;
                ord.PromoProduct    += od.PromoProduct.Value;
                ord.PromoRefill     += od.PromoRefill;
                ord.GrantTotal      += (od.TotalAmount + od.RefillTotalAmount); //prd.sub_total;
                ord.NumberOfProducts = prd.quantity + prd.refill_quantity;
                ord.TeleOrderDetails.Add(od);


                //TeleOrderDetail od = new TeleOrderDetail();
                //od.TeleOrder = ord;
                //od.ProdID = prd.product_id;
                //od.CreatedDate = ord.CreatedDate;
                //od.PromoProduct = (prd.unit_price - prd.product_promo) * prd.quantity;
                //od.PromoShipping = (prd.shipping_cost - prd.shipping_promo) * prd.quantity;
                //od.ShippingCharge = prd.shipping_cost;
                //od.SubTotal = prd.sub_total;
                //od.Quantity = prd.quantity;
                //od.UnitPrice = prd.unit_price;
                //ord.SubTotal += prd.sub_total;
                //ord.ShippingCharge += prd.shipping_cost * prd.quantity;
                //ord.PromoProduct += (prd.product_promo - prd.unit_price) * prd.quantity;
                //ord.PromoShipping += (prd.shipping_promo - prd.shipping_cost) * prd.quantity;
                //ord.TeleOrderDetails.Add(od);
                //ord.GrantTotal += (prd.unit_price - prd.product_promo + prd.shipping_cost - prd.shipping_promo) * prd.quantity;
            }
        }
Exemple #2
0
        public static void CopyFromEntity(OrderFullDetailsDto dto, TeleOrder teleOrder, Driver drv = null)
        {
            dto.order_id           = teleOrder.TeleOrdID;
            dto.delivery_date      = Common.ToDateFormat(teleOrder.DeliveryDate.HasValue ? teleOrder.DeliveryDate.Value : DateTime.MinValue);
            dto.delivery_time_slot = teleOrder.MDeliverySlot.SlotName;
            dto.invoice_number     = teleOrder.InvoiceNumber;
            dto.order_status       = teleOrder.StatusId;
            if (teleOrder.TeleCustomers.Count > 0)
            {
                var teleConsumer = teleOrder.TeleCustomers.Where(x => x.TeleOrdID == teleOrder.TeleOrdID).FirstOrDefault();
                if (teleConsumer != null)
                {
                    dto.consumer_name     = teleConsumer.CustomerName;
                    dto.consumer_mobile   = teleConsumer.MobileNumber;
                    dto.consumer_address  = teleConsumer.Address;
                    dto.consumer_location = teleConsumer.Address;
                    //dto.latitude = teleConsumer.Latitude;
                    //dto.longitude = teleConsumer.Longitude;
                }
            }

            dto.driver = new DriverDetailsDto();
            if (teleOrder.TeleOrderDetails.Count > 0)
            {
                TeleOrderDetail od = teleOrder.TeleOrderDetails.First();
                dto.driver = new DriverDetailsDto();
                if (drv == null)
                {
                    drv = teleOrder.Driver;
                }
                CopyFromEntity(dto.driver, drv);
                //dto.driver.driver_id = od.Driver.DrvrID;
                //dto.driver.driver_image = od.Driver.ProfileImage;
                //dto.driver.driver_mobile = od.Driver.MobileNumber;
                //dto.driver.driver_name = od.Driver.DriverName;
                ////dto.driver.driver_rating = od.Driver.ra
            }

            List <ProductsDto> pdtos = new List <ProductsDto>();

            foreach (TeleOrderDetail det in teleOrder.TeleOrderDetails)
            {
                ProductsDto pdt = new ProductsDto();
                pdt.product_id      = det.Product.ProdID;
                pdt.product_name    = det.Product.ProductName;
                pdt.product_promo   = det.PromoProduct.HasValue ? det.PromoProduct.Value : 0;
                pdt.quantity        = det.Quantity;
                pdt.shipping_cost   = det.ShippingCharge.HasValue ? det.ShippingCharge.Value : 0;
                pdt.shipping_promo  = det.PromoShipping.HasValue ? det.PromoShipping.Value : 0;
                pdt.sub_total       = det.SubTotal;
                pdt.unit_price      = det.UnitPrice;
                pdt.refill_price    = det.RefillPrice;
                pdt.refill_promo    = det.PromoRefill;
                pdt.refill_quantity = det.RefillQuantity;
                pdtos.Add(pdt);
            }
            dto.grand_total  = teleOrder.GrantTotal;
            dto.products     = pdtos.ToArray();
            dto.has_exchange = (teleOrder.TeleOrderPrdocuctExchanges.Count > 0 ? 1 : 0);
            if (dto.has_exchange == 1)
            {
                if (dto.exchange == null)
                {
                    dto.exchange = new List <ExchangeDto>();
                }
                foreach (var item in teleOrder.TeleOrderPrdocuctExchanges)
                {
                    ExchangeDto exDto = new ExchangeDto();
                    TeleOrderHelper.CopyFromEntity(exDto, item);
                    dto.exchange.Add(exDto);
                }
            }
        }