Exemplo n.º 1
0
        public static GetAgentAdminDetailsResponse GetDetails(GetAgentAdminDetailsRequest request)
        {
            GetAgentAdminDetailsResponse response = new GetAgentAdminDetailsResponse();
            AgentAdmin admin = null;

            try
            {
                if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                {
                    return(response);
                }
                using (AgentAdminDao dao = new AgentAdminDao())
                {
                    admin = dao.FindById(request.user_id);
                    response.agent_admin_details = new AgentAdminDetailsDto();
                    response.agent_admin_details.agent_admin_id    = admin.AgadmID;
                    response.agent_admin_details.agent_admin_name  = admin.AgentAdminName;
                    response.agent_admin_details.mobile_number     = admin.MobileNumber;
                    response.agent_admin_details.profile_image     = ImagePathService.agentAdminImagePath + admin.ProfileImage;
                    response.agent_admin_details.agent_admin_email = admin.email;
                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("admin.details");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Exemplo n.º 2
0
        public ConfirmPickupOrderResponse ConfirmPickupOrder(ConfirmPickupOrderRequest request)
        {
            ConfirmPickupOrderResponse response = new ConfirmPickupOrderResponse();

            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);
                    order.StatusId = OrdersServices.ID_ORDER_CLOSED;
                    string invNo = InvoiceService.GenerateInvoiceNumber(order.AgentAdmin.AgenID);
                    order.InvoiceNumber = invNo;
                    dao.Update(order);
                    dao.Update(order);
                    OrderPickupHelper.CopyFromEntity(response, order);

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

            return(response);
        }
Exemplo n.º 3
0
        public static ResponseDto ChangeProfile(ChangeProfileAgentAdminRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            ResponseDto response = new ResponseDto();
            AgentAdmin  admin    = null;

            try
            {
                if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                {
                    return(response);
                }
                using (AgentAdminDao dao = new AgentAdminDao())
                {
                    admin = dao.FindById(request.user_id);
                    admin.AgentAdminName = request.agent_admin_name;
                    //admin.MobileNumber = request.mobile_number;
                    //admin.ProfileImage = string.IsNullOrWhiteSpace(request.profile_image) ? admin.ProfileImage : request.profile_image; //Commented bcz image is uploading as multipart
                    admin.email = request.agent_admin_email;
                    dao.Update(admin);
                    response.code         = 0;
                    response.has_resource = 0;
                    response.message      = MessagesSource.GetMessage("profile.changed");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Exemplo n.º 4
0
        public static bool CheckAdmin(int userId, string authToken, ResponseDto response)
        {
            AgentAdmin admin = AgentAdminServices.GetAuthAdmin(userId, authToken, response);

            if (admin == null || admin.AccToken != authToken)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
        public GetProductDetailsResponse GetProductDetails(GetProductDetailsRequest request)
        {
            GetProductDetailsResponse response = new GetProductDetailsResponse();

            try
            {
                if (request.is_admin)
                {
                    if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                    {
                        //_userServices.MakeNouserResponse(response);
                        return(response);
                    }
                }
                else
                {
                    if (!_userServices.CheckAuthUser(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                }

                using (ProductDao dao = new ProductDao())
                {
                    ProductDetailsDto dto = new ProductDetailsDto();
                    Product           prd = dao.FindProductById(request.product_id);
                    ProductHelper.CopyFromEntity(dto, prd);
                    response.product_details = dto;
                    response.code            = 0;
                    response.has_resource    = 1;
                    response.message         = MessagesSource.GetMessage("has.prod.details");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }
            return(response);
        }
Exemplo n.º 6
0
        public static ResponseDto ChangePassword(ChangePasswordAgentAdminRequest request)
        {
            ResponseDto response        = new ResponseDto();
            AgentAdmin  admin           = null;
            string      oldPasswordHash = TokenGenerator.GetHashedPassword(request.old_password, 49);

            try
            {
                if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                {
                    return(response);
                }
                using (AgentAdminDao dao = new AgentAdminDao())
                {
                    admin = dao.FindById(request.user_id);
                    if (admin.Password == oldPasswordHash)
                    {
                        admin.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(admin);
                        response.code         = 0;
                        response.has_resource = 0;
                        response.message      = MessagesSource.GetMessage("password.changed");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public Dictionary <string, object> UploadProfilePicture(HttpRequest httpRequest, int userType)
        {
            string message = string.Empty;
            Dictionary <string, object> dict = new Dictionary <string, object>();
            string _imgname = "";

            try
            {
                if (httpRequest.Files.Count > 0)
                {
                    foreach (string file in httpRequest.Files)
                    {
                        var postedFile = httpRequest.Files[file];
                        if (postedFile != null && postedFile.ContentLength > 0)
                        {
                            int MaxContentLength = 1024 * 1024 * 5; //5 MB

                            IList <string> AllowedFileExtensions = new List <string> {
                                ".jpg", ".gif", ".png"
                            };
                            var ext       = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
                            var extension = ext.ToLower();
                            if (!AllowedFileExtensions.Contains(extension))
                            {
                                message = string.Format("Please Upload image of type .jpg,.gif,.png.");
                                dict.Add("error", "0");
                                dict.Add("message", message);
                            }
                            else if (postedFile.ContentLength > MaxContentLength)
                            {
                                message = string.Format("Please Upload a file upto 1 mb.");
                                dict.Add("error", "0");
                                dict.Add("message", message);
                            }
                            else
                            {
                                string path = HttpContext.Current.Server.MapPath("~/extfiles/profile/");

                                int userId = 0;
                                if (httpRequest.Form["user_id"] != null)
                                {
                                    userId = httpRequest.Form["user_id"].ToInt();
                                }

                                string auth_token = string.Empty;
                                if (httpRequest.Form["auth_token"] != null)
                                {
                                    auth_token = httpRequest.Form["auth_token"].ToString();
                                }

                                if (userId > 0 && userType > 0)
                                {
                                    bool userExist = false;
                                    switch ((UserType)userType)
                                    {
                                    case UserType.SuperUser:
                                        path      = HttpContext.Current.Server.MapPath("~/extfiles/profile/superuser/");
                                        userExist = SuperUserServices.CheckSuperUser(userId, auth_token, null);
                                        break;

                                    case UserType.AgentBoss:
                                        path      = HttpContext.Current.Server.MapPath("~/extfiles/profile/agentboss/");
                                        userExist = AgentBossServices.CheckAgentBoss(userId, auth_token, null);
                                        break;

                                    case UserType.AgentAdmin:
                                        path      = HttpContext.Current.Server.MapPath("~/extfiles/profile/agentadmin/");
                                        userExist = AgentAdminServices.CheckAdmin(userId, auth_token, null);
                                        break;

                                    case UserType.Driver:
                                        path      = HttpContext.Current.Server.MapPath("~/extfiles/profile/driver/");
                                        userExist = DriverServices.CheckAuthDriver(userId, auth_token);
                                        break;

                                    case UserType.Consumer:
                                        path      = HttpContext.Current.Server.MapPath("~/extfiles/profile/customer/");
                                        userExist = _userServices.CheckAuthUser(userId, auth_token);
                                        break;
                                    }

                                    if (!userExist)
                                    {
                                        message = string.Format("Invalid User");
                                        dict.Add("error", "0");
                                        dict.Add("message", message);
                                    }

                                    if (!Directory.Exists(path))
                                    {
                                        Directory.CreateDirectory(path);
                                    }
                                    _imgname = string.Format("ProfileImg_{0}{1}", Guid.NewGuid().ToString(), extension);
                                    var _comPath = string.Format("{0}{1}", path, _imgname);

                                    postedFile.SaveAs(_comPath);
                                }
                                else
                                {
                                    message = string.Format("userId or userType cannot be empty");
                                    dict.Add("error", "0");
                                    dict.Add("message", message);
                                }

                                dict.Add("user_id", userId);
                                dict.Add("auth_token", auth_token);
                            }
                        }

                        dict.Add("success", "1");
                        dict.Add("message", _imgname);
                    }
                }
                else
                {
                    message = string.Format("Please Upload a image.");
                    dict.Add("error", "0");
                    dict.Add("message", message);
                }
                return(dict);
            }
            catch (Exception ex)
            {
                dict.Add("error", "ex");
                dict.Add("message", ex.Message);
                return(dict);
            }
        }
Exemplo n.º 10
0
        public GetProductListResponse GetProductList(GetProductListRequest request)
        {
            GetProductListResponse response = new GetProductListResponse();

            try
            {
                if (request.is_admin)
                {
                    if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                    {
                        //_userServices.MakeNouserResponse(response);
                        return(response);
                    }
                }
                else
                {
                    if (!_userServices.CheckAuthUser(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                }

                using (ProductDao dao = new ProductDao())
                {
                    List <Product> pList      = dao.GetProducts(request.page_number, request.row_per_page);
                    int            totalCount = dao.GetTotalCount();
                    response.product_details = new ProductPagenationDetailsDto();
                    response.product_details.total_num_products = totalCount;
                    ProductDto[] prodDtos = new ProductDto[pList.Count()];
                    for (int i = 0; i < pList.Count; i++)
                    {
                        ProductDto dto = new ProductDto();
                        ProductHelper.CopyFromEntity(dto, pList[i]);
                        prodDtos[i] = dto;

                        response.products = prodDtos;
                        //response.has_exchange = (pList[i].ProductExchanges.Count > 0 ? 1 : 0);
                        //if (response.has_exchange == 1)
                        //{
                        //    if (response.exchange == null)
                        //        response.exchange = new List<ExchangeDto>();
                        //    foreach (var item in pList[i].ProductExchanges.ToList())
                        //    {
                        //        ExchangeDto exDto = new ExchangeDto();
                        //        ProductHelper.CopyFromEntity(exDto, item);
                        //        response.exchange.Add(exDto);
                        //    }
                        //}
                    }

                    var reminder = dao.GetRemindersForProducts();
                    response.has_reminder = (reminder == null ? 0 : 1);
                    ProductHelper.CopyFromEntity(response, reminder);

                    response.has_resource = 1;
                    response.code         = 0;
                    response.message      = MessagesSource.GetMessage("has.products");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }
            return(response);
        }
Exemplo n.º 11
0
        public InfoBannerResponse GetInfoBanner(GetInfoBannerRequest request)
        {
            InfoBannerResponse response = new InfoBannerResponse();

            try
            {
                switch (request.user_type)
                {
                case (int)UserType.SuperUser:
                    if (!SuperUserServices.CheckSuperUser(request.user_id, request.auth_token, response))
                    {
                        response.message = MessagesSource.GetMessage("invalid.super.user");
                        return(response);
                    }
                    break;

                case (int)UserType.AgentBoss:
                    if (!AgentBossServices.CheckAgentBoss(request.user_id, request.auth_token, response))
                    {
                        return(response);
                    }
                    break;

                case (int)UserType.AgentAdmin:
                    if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                    {
                        return(response);
                    }
                    break;

                case (int)UserType.Driver:
                    if (!DriverServices.CheckAuthDriver(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                    break;

                case (int)UserType.Consumer:
                    if (!_userServices.CheckAuthUser(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                    break;

                default:
                {
                    response.has_resource = 0;
                    response.code         = 1;
                    response.message      = MessagesSource.GetMessage("invalid.user.type");
                    return(response);
                }
                }

                using (PromoDao dao = new PromoDao())
                {
                    List <PromoInfo> bList = dao.GetInfoBanners();
                    if (bList.Count <= 0)
                    {
                        response.has_resource = 1;
                        response.code         = 0;
                        response.message      = MessagesSource.GetMessage("promo.info.not.found");
                        return(response);
                    }
                    InfoBannerDto[] promoDtos = new InfoBannerDto[bList.Count()];
                    for (int i = 0; i < bList.Count; i++)
                    {
                        InfoBannerDto dto = new InfoBannerDto();
                        PromoHelper.CopyFromEntity(dto, bList[i]);
                        promoDtos[i] = dto;
                    }
                    response.info_banners = promoDtos;
                    response.has_resource = 1;
                    response.code         = 0;
                    response.message      = MessagesSource.GetMessage("promo.info.found");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Exemplo n.º 12
0
        public GetBannerResponse GetBanner(GetBannerRequest request)
        {
            GetBannerResponse response = new GetBannerResponse();

            try
            {
                switch (request.user_type)
                {
                case (int)UserType.SuperUser:
                    if (!SuperUserServices.CheckSuperUser(request.user_id, request.auth_token, response))
                    {
                        response.message = MessagesSource.GetMessage("invalid.super.user");
                        return(response);
                    }
                    break;

                case (int)UserType.AgentBoss:
                    if (!AgentBossServices.CheckAgentBoss(request.user_id, request.auth_token, response))
                    {
                        return(response);
                    }
                    break;

                case (int)UserType.AgentAdmin:
                    if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                    {
                        return(response);
                    }
                    break;

                case (int)UserType.Driver:
                    if (!DriverServices.CheckAuthDriver(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                    break;

                case (int)UserType.Consumer:
                    if (!_userServices.CheckAuthUser(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                    break;

                default:
                {
                    response.has_resource = 0;
                    response.code         = 1;
                    response.message      = MessagesSource.GetMessage("invalid.user.type");
                    return(response);
                }
                }

                using (PromoDao dao = new PromoDao())
                {
                    GetBannerResponse dto   = new GetBannerResponse();
                    PromoBanner       promo = dao.FindByCategoty(request.category);
                    if (promo == null)
                    {
                        response.has_resource = 1;
                        response.code         = 0;
                        response.message      = MessagesSource.GetMessage("promo.banner.not.found");
                        return(response);
                    }
                    if (promo != null)
                    {
                        PromoHelper.CopyFromEntity(dto, promo);
                    }
                    response              = dto;
                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("promo.banner.found");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Exemplo n.º 13
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);
        }