public static void CopyFromEntity(ConfirmPickupOrderResponse response, TeleOrder order)
        {
            PickupOrderDto odt = new PickupOrderDto();

            response.orders    = odt;
            odt.order_id       = order.TeleOrdID;
            odt.order_date     = Common.ToDateFormat(order.OrderDate);
            odt.invoice_number = order.InvoiceNumber;
            odt.order_status   = order.StatusId;
            odt.grand_total    = order.GrantTotal;

            //dto.oder = odtos.ToArray();
            List <ProductsDto> pdtos = new List <ProductsDto>();

            foreach (TeleOrderDetail det in order.TeleOrderDetails)
            {
                ProductsDto pdt = new ProductsDto();
                pdt.product_id      = det.Product.ProdID;
                pdt.product_name    = det.Product.ProductName;
                pdt.product_promo   = det.PromoProduct ?? 0M;
                pdt.quantity        = det.Quantity;
                pdt.shipping_cost   = det.ShippingCharge ?? 0M;
                pdt.shipping_promo  = det.PromoShipping ?? 0M;
                pdt.refill_price    = det.RefillPrice;
                pdt.refill_promo    = det.PromoRefill;
                pdt.refill_quantity = det.RefillQuantity;
                pdt.sub_total       = det.SubTotal;
                pdt.unit_price      = det.UnitPrice;
                pdtos.Add(pdt);
            }
            odt.products     = pdtos.ToArray();
            odt.has_exchange = (order.TeleOrderPrdocuctExchanges.Count > 0 ? 1 : 0);
            if (odt.has_exchange == 1)
            {
                if (odt.exchange == null)
                {
                    odt.exchange = new List <ExchangeDto>();
                }
                foreach (var item in order.TeleOrderPrdocuctExchanges)
                {
                    ExchangeDto exDto = new ExchangeDto();
                    TeleOrderHelper.CopyFromEntity(exDto, item);
                    odt.exchange.Add(exDto);
                }
            }
        }
Esempio n. 2
0
        public AddTeleOrderResponse AddTeleOrder(AddTeleOrderRequest request)
        {
            AddTeleOrderResponse response = new AddTeleOrderResponse();

            try
            {
                AgentAdmin admin = AgentAdminServices.GetAuthAdmin(request.user_id, request.auth_token, response);
                if (admin == null)
                {
                    return(response);
                }

                if (request.delivery_date <= DateTime.MinValue)
                {
                    _orderService.MakeInvalidDeliveryDateFormat(response);
                    return(response);
                }

                UpdateTeleOrderRequest(request); // To update request from mobile, Reason : not passing expected values from mobile

                TeleCustomer cons = new TeleCustomer();
                cons.Address      = request.customer_details.customer_address;
                cons.CustomerName = request.customer_details.customer_name;
                cons.MobileNumber = request.customer_details.customer_mobile;
                cons.StatusId     = true;
                //cons.Latitude = request.customer_details.latitude;
                //cons.Longitude = request.customer_details.longitude;
                cons.CreatedBy   = admin.AgadmID;
                cons.CreatedDate = DateTime.Now;

                TeleOrder ord = new TeleOrder();
                PopulateOrder(ord, cons.TeleCustID, request, admin);
                AddProductsToOrder(ord, request.products);

                ord.DrvrID         = request.driver_id;
                ord.DeliverySlotID = (short)request.time_slot_id;
                //ord.DeliveredDate = null;

                using (TeleOrderDao odao = new TeleOrderDao())
                {
                    if (request.has_exchange)
                    {
                        if (request.exchange == null)
                        {
                            _orderService.MakeInvalidExchangeInputResponse(response);
                            return(response);
                        }

                        foreach (ExchangeDto exdto in request.exchange)
                        {
                            TeleOrderPrdocuctExchange opex = new TeleOrderPrdocuctExchange();
                            ProductExchange           pxg  = odao.FindProductExchangeById(exdto.exchange_id);
                            if (pxg == null)
                            {
                                _orderService.MakeInvalidExchangeInputResponse(response);
                                return(response);
                            }
                            opex.ProdID             = pxg.ProdID;
                            opex.ExchangePrice      = exdto.exchange_price;
                            opex.CreatedDate        = DateTime.Now;
                            opex.ExchangePromoPrice = exdto.exchange_promo_price * exdto.exchange_quantity;
                            opex.ExchangeQuantity   = exdto.exchange_quantity;
                            opex.ExchangeWith       = exdto.exchange_with;
                            opex.StatusId           = true;//TODO
                            opex.SubTotal           = exdto.exchange_price * exdto.exchange_quantity;
                            //ord.GrandTotal -= (opex.ExchangePrice - opex.ExchangePromoPrice) * opex.ExchangeQuantity;

                            var product = request.products.Where(p => p.product_id == pxg.ProdID).FirstOrDefault();
                            if (product == null)
                            {
                                //MakeInvalidExchangeInputResponse(response);
                                response.code         = 1;
                                response.has_resource = 0;
                                response.message      = "Cannot find product with id " + pxg.ProdID + " in the products array";
                                return(response);
                            }
                            opex.TotalAmount = opex.SubTotal + opex.ExchangePromoPrice + (product.shipping_cost * exdto.exchange_quantity) + (product.shipping_promo * exdto.exchange_quantity);
                            ord.TeleOrderPrdocuctExchanges.Add(opex);
                            ord.ShippingCharge   += (product.shipping_cost * exdto.exchange_quantity);
                            ord.PromoShipping    += (product.shipping_promo * exdto.exchange_quantity);
                            ord.NumberOfProducts += exdto.exchange_quantity;
                            ord.ExchangeSubTotal += opex.SubTotal;
                            ord.PromoExchange    += opex.ExchangePromoPrice;
                            ord.GrantTotal       += opex.TotalAmount;
                        }
                    }
                    //cons.TeleOrder = ord;
                    odao.Insert(ord);
                    cons.TeleOrdID = ord.TeleOrdID;
                    using (TeleOrderCustomerDao tcDao = new TeleOrderCustomerDao())
                    {
                        tcDao.Insert(cons);
                    }
                    ord = odao.FindById(ord.TeleOrdID, true);
                    TeleOrderHelper.CopyFromEntity(response, ord);
                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("add.tele.order");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Esempio n. 3
0
        public ConfirmTeleOrderResponse ConfirmTeleOrder(ConfirmTeleOrderRequest request)
        {
            ConfirmTeleOrderResponse response = new ConfirmTeleOrderResponse();

            try
            {
                if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                {
                    return(response);
                }
                using (TeleOrderDao dao = new TeleOrderDao())
                {
                    TeleOrder order = dao.FindById(request.order_id, true);
                    if (order == null)
                    {
                        MakeNoTeleOrderFoundResponse(response);
                        return(response);
                    }
                    order.StatusId = OrdersServices.ID_ORDER_ACCEPTED;//2;
                    order.DrvrID   = request.driver_id;
                    //Driver drv = order.Driver;
                    //int agId = drv.AgenID;
                    Driver drv = null;
                    using (DriverDao ddao = new DriverDao())
                    {
                        drv = ddao.FindById(request.driver_id);
                        if (drv == null)
                        {
                            DriverServices.MakeNoDriverResponse(response);
                            return(response);
                        }
                        TeleOrderDelivery odel = new TeleOrderDelivery();
                        odel.DrvrID       = drv.DrvrID;
                        odel.AgadmID      = request.user_id;
                        odel.CreatedDate  = DateTime.Now;
                        odel.DeliveryDate = order.DeliveryDate;
                        odel.AcceptedDate = DateTime.Now;
                        odel.StatusId     = OrdersServices.DELIVERY_STATUS_ASSIGNED;//1;
                        odel.TeleOrder    = order;
                        order.TeleOrderDeliveries.Add(odel);
                    }
                    lock (InvoiceService.monitor)
                    {
                        string invNo = InvoiceService.GenerateInvoiceNumber(drv.AgenID);
                        order.InvoiceNumber = invNo;
                        dao.Update(order);
                    }
                    TeleOrderHelper.CopyFromEntity(response, order);
                    using (ConsumerReviewDao conReviewDao = new ConsumerReviewDao())
                    {
                        List <ConsumerReview> conReview = new List <ConsumerReview>();
                        conReview = conReviewDao.GetReviewByDriver(request.driver_id);
                        response.orders.driver.driver_rating = conReview.Count > 0 ? Convert.ToDecimal(conReview.Average(x => x.Rating)) : 0;
                    }

                    if (order.DeliveryDate.HasValue && order.DeliveryDate.Value.ToShortDateString() == DateTime.Now.ToShortDateString())
                    {
                        int orderCount = dao.GetAssignedOrderCount(request.driver_id, OrdersServices.ID_ORDER_ACCEPTED);
                        using (OrderDao ordDao = new OrderDao())
                        {
                            orderCount += ordDao.GetAssignedOrderCount(request.driver_id, OrdersServices.ID_ORDER_ACCEPTED);
                        }
                        _orderService.ReadAndSendPushNotification(OrdersServices.APPSETTING_MSG_TO_ASSIGNED_DRIVER, OrdersServices.APPSETTING_TITLE_FOR_ASSIGNED_DRIVER, drv.AppToken, request.order_id, request.driver_id, orderCount, PushMessagingService.APPSETTING_APPLICATION_ID_DRIVER, PushMessagingService.APPSETTING_SENDER_ID_DRIVER, (int)PushMessagingService.PushType.TypeOne);
                    }

                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("cnfrm.tele.order");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }