Ejemplo n.º 1
0
        public static ExchangeDto CopyFromEntity(ExchangeDto dto, ProductExchange product_Exchange)
        {
            if (dto == null)
            {
                dto = new ExchangeDto();
                return(dto);
            }
            if (dto.exchange_quantity > 0)
            {
                dto.exchange_id          = product_Exchange.PrExID;
                dto.exchange_quantity    = product_Exchange.ExchangeQuantity;
                dto.exchange_price       = product_Exchange.ExchangePromoPrice;
                dto.exchange_promo_price = product_Exchange.ExchangePromoPrice;
                dto.exchange_with        = product_Exchange.ExchangeWith;
            }
            else
            {
                dto.exchange_id          = 0;
                dto.exchange_quantity    = 0;
                dto.exchange_price       = 0;
                dto.exchange_promo_price = 0;
                dto.exchange_with        = "";
            }

            return(dto);
        }
 public static void CopyFromEntity(ExchangeDto response, ProductExchange exchange)
 {
     response.exchange_id          = exchange.PrExID;
     response.exchange_price       = exchange.ExchangePrice ?? 0M;
     response.exchange_promo_price = exchange.ExchangePromoPrice;
     response.exchange_quantity    = exchange.ExchangeQuantity;
     response.exchange_with        = exchange.ExchangeWith;
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public PlaceOrderPickupResponse PlacePickupOrder(PlaceOrderPickupRequest request)
        {
            PlaceOrderPickupResponse response = new PlaceOrderPickupResponse();

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

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

                TeleOrder ord = new TeleOrder();
                PopulateOrder(ord);
                ord.AgadmID   = admin.AgadmID;
                ord.CreatedBy = admin.AgadmID;
                ord.UpdatedBy = admin.AgadmID;
                AddProductsToOrder(ord, request.products);
                using (TeleOrderDao dao = new TeleOrderDao())
                {
                    if (request.has_exchange)
                    {
                        if (request.exchange == null)
                        {
                            MakeInvalidExchangeInputResponse(response);
                            return(response);
                        }
                        foreach (ExchangeDto item in request.exchange)
                        {
                            ProductExchange           pxg  = dao.FindProductExchangeById(item.exchange_id);
                            TeleOrderPrdocuctExchange opex = new TeleOrderPrdocuctExchange();
                            if (pxg == null)
                            {
                                MakeInvalidExchangeInputResponse(response);
                                return(response);
                            }
                            opex.ProdID             = pxg.ProdID;
                            opex.ExchangePrice      = item.exchange_price;
                            opex.CreatedDate        = DateTime.Now;
                            opex.ExchangePromoPrice = item.exchange_promo_price * item.exchange_quantity;
                            opex.ExchangeQuantity   = item.exchange_quantity;
                            opex.ExchangeWith       = item.exchange_with;
                            opex.StatusId           = true;//TODO
                            //ord.GrantTotal -= (opex.ExchangePrice - opex.ExchangePromoPrice) * opex.ExchangeQuantity;
                            //opex.TeleOrder = ord;
                            opex.SubTotal = item.exchange_price * item.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;
                            ord.TeleOrderPrdocuctExchanges.Add(opex);
                            //ord.ShippingCharge += (product.shipping_cost * item.exchange_quantity);
                            //ord.PromoShipping += (product.shipping_promo * item.exchange_quantity);
                            ord.NumberOfProducts += item.exchange_quantity;
                            ord.ExchangeSubTotal += opex.SubTotal;
                            ord.PromoExchange    += opex.ExchangePromoPrice;
                            ord.GrantTotal       += opex.TotalAmount;
                        }
                    }
                    int agId = admin.AgenID;
                    lock (InvoiceService.monitor)
                    {
                        ord.InvoiceNumber = InvoiceService.GenerateInvoiceNumber(agId);
                        dao.Insert(ord);
                    }

                    OrderPickupHelper.CopyFromEntity(response, ord);
                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("place.pickup.order");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }