Exemplo n.º 1
0
        public DualOrderMonthResponseViewModel Get()
        {
            try
            {
                var locale              = Thread.CurrentThread.CurrentCulture.Name;
                var country             = locale.Substring(3, 2);
                var result              = new DualOrderMonthResponseViewModel();
                var dualOrderMonthModel = _imMobileDualOrderMonthProvider.GetDualOrderMonth(country);
                result.PreviousOrderMonth        = dualOrderMonthModel.PreviousOrderMonth;
                result.PreviousOrderMonthEndDate = dualOrderMonthModel.PreviousOrderMonthEndDate;

                MobileActivityLogProvider.ActivityLog(string.Empty, result, string.Empty, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      locale);

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            throw new Exception("Method Get on MobileDualOrderMonthController not return values.");
        }
        public MobileResponseWrapper Get([FromUri] PreferredCustomerRequestViewModel request)
        {
            try
            {
                string obj      = JsonConvert.SerializeObject(request);
                var    response = new MobileResponseWrapper
                {
                    Data = _mobileCustomersProvider.GetPreferredCustomers(request)
                };
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, response, request.MemberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      request.Locale);

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            throw new Exception("Method Get on MobileCustomersController not return values.");
        }
        public PickUpResponseViewModel Post(ModifyPickUpRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Location not found, request Null", "300404");
            }
            string obj = JsonConvert.SerializeObject(request);

            request.Locale = Thread.CurrentThread.CurrentCulture.Name;
            var result = _iMobilePickUpProvider.SavePickUpPreference(request.MemberId, request.PickUpModel,
                                                                     request.Locale);

            if (result != null)
            {
                if (result.IDSaved == -2)
                {
                    //return an error duplicate nick name / Alias
                    return(new PickUpResponseViewModel
                    {
                        Data = null,
                        Error =
                            new ErrorViewModel
                        {
                            Code = 0416,
                            Message =
                                "Invalid or Incomplete Location information: Pick Up Location Alias Duplicated"
                        }
                    });
                }
                if (result.IDSaved == -3)
                {
                    //return an error, PU location saved previousli
                    return(new PickUpResponseViewModel
                    {
                        Data = null,
                        Error =
                            new ErrorViewModel
                        {
                            Code = 0416,
                            Message =
                                "Invalid or Incomplete Location information : Pick Up Location previously saved"
                        }
                    });
                }

                var pickupResponseViewModel = new PickUpResponseViewModel {
                    Data = result, Error = null
                };
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, pickupResponseViewModel, request.MemberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      request.Locale);

                return(pickupResponseViewModel);
            }

            throw CreateException(HttpStatusCode.InternalServerError, "Invalid or Incomplete Location information: Error Occurs", "300416");
        }
        public MobileResponseWrapper GetSavedOptions([FromUri] PickUpRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Location not found, request Null", "300404");
            }
            string obj = JsonConvert.SerializeObject(request);

            request.Locale = Thread.CurrentThread.CurrentCulture.Name;
            var result = _iMobilePickUpProvider.GetSavedDeliveryOptions(request.MemberId, request.Locale);

            if (result != null)
            {
                var mobileResponseWrapper = new MobileResponseWrapper
                {
                    Data = new PickUpListResponseViewModel {
                        Pickup = result
                    }
                };
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, mobileResponseWrapper, request.MemberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      request.Locale);

                return(mobileResponseWrapper);
            }
            return(new MobileResponseWrapper
            {
                Data = null,
                //Error = new ErrorViewModel {Code = "0404", Message = "No Data Available"}
            });
        }
        public MobileResponseWrapper Get([FromUri] PickUpRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Location not found, request Null", "300404");
            }
            string obj = JsonConvert.SerializeObject(request);

            request.Locale = Thread.CurrentThread.CurrentCulture.Name;
            var result = _iMobilePickUpProvider.GetDeliveryOptions(request.Locale,
                                                                   new AddressViewModel
            {
                StateProvinceTerritory = request.State,
                City           = request.City,
                Country        = request.Country,
                PostalCode     = request.PostalCode,
                CountyDistrict = request.District
            });

            if (result != null)
            {
                if (request.City != null && !string.IsNullOrEmpty(request.City) &&
                    !string.IsNullOrWhiteSpace(request.City))
                {
                    result = result.FindAll(x => !string.IsNullOrEmpty(x.Address.City) ? x.Address.City.Trim() == request.City :
                                            x.Address.City == request.City);
                }
                if (request.State != null && !string.IsNullOrEmpty(request.State) &&
                    !string.IsNullOrWhiteSpace(request.State))
                {
                    result = result.FindAll(x => !string.IsNullOrEmpty(x.Address.StateProvinceTerritory) ?  x.Address.StateProvinceTerritory.Trim() == request.State :
                                            x.Address.StateProvinceTerritory == request.State);
                }
                if (request.District != null && !string.IsNullOrEmpty(request.District) &&
                    !string.IsNullOrWhiteSpace(request.District))
                {
                    result = result.FindAll(x => !string.IsNullOrEmpty(x.Address.CountyDistrict) ? x.Address.CountyDistrict.Trim() == request.District :
                                            x.Address.CountyDistrict == request.District);
                }

                var mobileListResponseWrapper = new MobileResponseWrapper
                {
                    Data = new PickUpListResponseViewModel {
                        Pickup = result
                    }
                };
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, mobileListResponseWrapper, request.MemberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      request.Locale);

                return(mobileListResponseWrapper);
            }

            throw CreateException(HttpStatusCode.InternalServerError, "Location not found", "300404");
        }
Exemplo n.º 6
0
        public SaveAddressResponseViewModel Post(AddressRequestViewModel request, string memberId)
        {
            try
            {
                string obj = JsonConvert.SerializeObject(request);
                //added country to this validation, because Country field is required to retrieve the address list
                if (request == null || request.Data == null || request.Data.Country == null)
                {
                    //200423 Address is readonly
                    //200404 404 Customer associated to the address does not exist
                    throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Address information (Null Data)", 200416);
                }
                var locale  = Thread.CurrentThread.CurrentCulture.Name;
                var address = request.Data;
                var result  = _iMobileAddressProvider.Save(ref address, memberId, locale);

                if (result == -3 || result == 0)
                {
                    //200422 422 Address Validation errors occurred
                    return(new SaveAddressResponseViewModel
                    {
                        Data = request.Data,
                        Error =
                            new ErrorViewModel
                        {
                            Code = 200422,
                            Message = "Address Validation errors occurred"
                        }
                    });
                }

                var response = new SaveAddressResponseViewModel {
                    Data = address, Error = null
                };
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, response, memberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      locale);

                return(response);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror for Save Address" + ex.Message, 200416);
            }
            return(null);
        }
Exemplo n.º 7
0
        public MobileResponseWrapper Get([FromUri] OrderTrackingRequestViewModel request)
        {
            try
            {
                request.Locale = Thread.CurrentThread.CurrentCulture.Name;
                if (request == null || request.MemberId == null || string.IsNullOrEmpty(request.MemberId) ||
                    string.IsNullOrWhiteSpace(request.MemberId) ||
                    request.Locale == null || string.IsNullOrEmpty(request.Locale) ||
                    string.IsNullOrWhiteSpace(request.Locale))
                {
                    throw CreateException(HttpStatusCode.BadRequest, "Get Order Tracking incomplete/invalid information sended", 210416);
                }
                string obj    = JsonConvert.SerializeObject(request);
                var    result = _iMobileOrderTrackingProvider.Get(request);

                if (result != null)
                {
                    var response = new MobileResponseWrapper
                    {
                        Data =
                            new OrderTrackingResponseViewModel
                        {
                            ExpressInfo = result,
                            Locale      = request.Locale,
                            OrderId     = request.OrderId,
                            MemberId    = request.MemberId
                        }
                    };

                    Object json = JObject.Parse(obj);
                    MobileActivityLogProvider.ActivityLog(json, string.Empty, request.MemberId, true,
                                                          this.Request.RequestUri.ToString(),
                                                          this.Request.Headers.ToString(),
                                                          this.Request.Headers.UserAgent.ToString(),
                                                          request.Locale);

                    return(response);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError, "Internal server errror searching for Get Order Tracking Express Info" + ex.Message, 166767);
            }

            throw CreateException(HttpStatusCode.InternalServerError, "Internal server errror searching for Get Order Tracking Express Info", 210416);
        }
        public MobileSandboxResponseWrapper Put(MobileSandboxRequestViewModel parameters)
        {
            try
            {
                var sandboxEvents = MobileActivityLogProvider.GetSandboxEvents(parameters.Page, parameters.PageSize, parameters.DistributorId, parameters.Locale, parameters.AppName, parameters.StartDate, parameters.EndDate);

                var response = new MobileSandboxResponseWrapper
                {
                    Parameters    = parameters,
                    SandboxEvents = sandboxEvents
                };

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public MobileResponseWrapper Put(OrderRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "request is null", 166767);
            }
            string obj = JsonConvert.SerializeObject(request);

            SetOrderMemberId(request.Data);
            request.Data.Locale = Thread.CurrentThread.CurrentCulture.Name;
            var orderNumber      = string.Empty;
            var isOrderSubmitted = false;

            if (_mobileQuoteHelper.CheckIfAnyOrderInProcessing(request.Data.MemberId, request.Data.Locale, ref orderNumber, ref isOrderSubmitted, request.Data.OrderNumber))
            {
                throw CreateException(HttpStatusCode.NotAcceptable,
                                      "order still processing", 110406, orderNumber);
            }

            //If SR Pricing an order for PC then check whether the PC is expired or not.
            if (request.Data.Locale == "zh-CN" && !string.IsNullOrEmpty(request.Data.CustomerId) && request.Data.CustomerId != request.Data.MemberId && _mobileQuoteHelper.IsPCExpired(request))
            {
                throw CreateException(HttpStatusCode.NotAcceptable,
                                      "PC membership is expired", 110421);
            }

            List <ValidationErrorViewModel> errors = null;
            var data = _iMobileQuoteProvider.Quote(request.Data, ref errors);
            var mobileResponseWrapper = new MobileResponseWrapper
            {
                Data             = data,
                ValidationErrors = null != errors && errors.Any() ? errors : null
            };
            JObject json = JObject.Parse(obj);

            MobileActivityLogProvider.ActivityLog(json, mobileResponseWrapper, request.Data.MemberId, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  request.Data.Locale);

            return(mobileResponseWrapper);
        }
        public OrderResponseViewModel Get(Guid id, string memberId)
        {
            if (id == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Order information", 101416);
            }
            try
            {
                var locale = Thread.CurrentThread.CurrentCulture.Name;
                var result = _iMobileOrderProvider.GetOrder(id, memberId, locale);
                if (result != null)
                {
                    var response = new OrderResponseViewModel {
                        Data = result
                    };

                    MobileActivityLogProvider.ActivityLog(response, response, memberId, true,
                                                          this.Request.RequestUri.ToString(),
                                                          this.Request.Headers.ToString(),
                                                          this.Request.Headers.UserAgent.ToString(),
                                                          locale);

                    return(response);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Get Orders" + ex.Message, 500);
            }
            var orderResponseViewModel3 = new OrderResponseViewModel {
                Data = null
            };

            MobileActivityLogProvider.ActivityLog(string.Empty, orderResponseViewModel3, memberId, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  Thread.CurrentThread.CurrentCulture.Name);

            return(orderResponseViewModel3);
        }
Exemplo n.º 11
0
        public MobileResponseWrapper Get([FromUri] OrderSummaryRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "request is null", 500);
            }
            string obj = JsonConvert.SerializeObject(request);

            request.Locale = Thread.CurrentThread.CurrentCulture.Name;
            var mobileResponseWrapper = new MobileResponseWrapper {
                Data = _mobileSummaryProvider.GetOrderList(request)
            };
            JObject json = JObject.Parse(obj);

            MobileActivityLogProvider.ActivityLog(json, mobileResponseWrapper, request.MemberId, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  request.Locale);

            return(mobileResponseWrapper);
        }
Exemplo n.º 12
0
        public MobileResponseWrapper Get(Guid id, string memberId)
        {
            try
            {
                var locale = Thread.CurrentThread.CurrentCulture.Name;
                if (id == null || string.IsNullOrEmpty(memberId))
                {
                    throw CreateException(HttpStatusCode.BadRequest, "Get Addresses incomplete/invalid information sended", 210416);
                }

                var result = _iMobileAddressProvider.GetShippingMethods(memberId, id, locale);

                if (result != null)
                {
                    var mobileResponseWrapper = new MobileResponseWrapper
                    {
                        Data = new ShippingMethodsResponseViewModel {
                            ShippingMethods = result
                        },
                    };

                    MobileActivityLogProvider.ActivityLog(string.Empty, mobileResponseWrapper, memberId, true,
                                                          this.Request.RequestUri.ToString(),
                                                          this.Request.Headers.ToString(),
                                                          this.Request.Headers.UserAgent.ToString(),
                                                          locale);

                    return(mobileResponseWrapper);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError, "Internal server errror searching for Get shippingMethods" + ex.Message, 166767);
            }

            throw CreateException(HttpStatusCode.InternalServerError, "Internal server errror searching for Get shippingMethods", 210416);
        }
Exemplo n.º 13
0
        public MobileResponseWrapper Get([FromUri] PayByPhoneRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "request is null", 500404);
            }
            string obj = JsonConvert.SerializeObject(request);

            request.Locale = Thread.CurrentThread.CurrentCulture.Name;

            var response = new MobileResponseWrapper
            {
                Data = _mobilePayByPhoneProvider.IsEligible(request.MemberId, request.Locale.Substring(3, 2))
            };
            JObject json = JObject.Parse(obj);

            MobileActivityLogProvider.ActivityLog(json, response, request.MemberId ?? string.Empty, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  request.Locale);

            return(response);
        }
Exemplo n.º 14
0
        public MobileResponseWrapper Get([FromUri] AnnouncementRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "request is null", 500404);
            }
            string obj = JsonConvert.SerializeObject(request);

            request.Locale = Thread.CurrentThread.CurrentCulture.Name;

            var response = new MobileResponseWrapper
            {
                Data = _IMobileAnnouncementProvider.GetAnnouncement(request)
            };
            JObject json = JObject.Parse(obj);

            MobileActivityLogProvider.ActivityLog(json, response, string.Empty, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  request.Locale);

            return(response);
        }
Exemplo n.º 15
0
        public OrderResponseViewModel RequestMobilePin(OrderRequestViewModel request)
        {
            string obj = JsonConvert.SerializeObject(request);
            List <ValidationErrorViewModel> errors = null;

            request.Data.OrderMemberId = string.IsNullOrEmpty(request.Data.OrderMemberId) && !string.IsNullOrEmpty(request.Data.CustomerId) ? request.Data.CustomerId : request.Data.OrderMemberId;
            var viewModel    = request.Data;
            var shoppingcart = _mobileQuoteHelper.PriceCart(ref viewModel, ref errors);
            var quickPayresponseviewModel = new OrderResponseViewModel();

            if (null != errors && errors.Any())
            {
                quickPayresponseviewModel.ValidationErrors = errors;
                return(quickPayresponseviewModel);
            }
            var     orderTotalsV01 = shoppingcart.Totals as ServiceProvider.OrderSvc.OrderTotals_V01;
            var     orderTotalsV02 = shoppingcart.Totals as ServiceProvider.OrderSvc.OrderTotals_V02;
            decimal amount;
            var     order = _mobileQuickPayController.Getorder(viewModel, ref errors, orderTotalsV02, orderTotalsV01,
                                                               out amount);
            var ordernumber = order.OrderID;

            if (string.IsNullOrWhiteSpace(ordernumber))
            {
                ordernumber = _mobileQuickPayController.GetOrderNumber(amount, shoppingcart.CountryCode, shoppingcart.DistributorID);
            }

            //Order_V01 order, string ordernumber, MyHLShoppingCart cart
            var cn99BillQuickPayProvider = new CN_99BillQuickPayProvider();
            var hasrequestedmobilepin    = cn99BillQuickPayProvider.RequestMobilePinForPurchase(ordernumber, order, shoppingcart, request.Data.MemberId);

            if (hasrequestedmobilepin)
            {
                var quickPayPaymentViewModel = request.Data.Payments[0] as QuickPayPaymentViewModel;
                if (quickPayPaymentViewModel != null)
                {
                    quickPayPaymentViewModel.StorablePAN = cn99BillQuickPayProvider.StorablePAN;
                    quickPayPaymentViewModel.Token       = cn99BillQuickPayProvider.Token;
                }

                viewModel.OrderNumber = ordernumber;
            }

            if (!string.IsNullOrEmpty(cn99BillQuickPayProvider.LastErrorMessage))
            {
                if (errors == null)
                {
                    errors = new List <ValidationErrorViewModel>();
                }

                errors.Add(new ValidationErrorViewModel {
                    Code = 126000, Reason = cn99BillQuickPayProvider.LastErrorMessage
                });
            }

            quickPayresponseviewModel.Data = viewModel;

            if (null != errors && errors.Any())
            {
                quickPayresponseviewModel.ValidationErrors = errors;
            }

            JObject json = JObject.Parse(obj);

            MobileActivityLogProvider.ActivityLog(json, quickPayresponseviewModel, request.Data.MemberId, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  request.Data.Locale);

            return(quickPayresponseviewModel);
        }
        public MobileResponseWrapper Get([FromUri] DiscontinuedSkuItemViewModel query)
        {
            try
            {
                if (query == null)
                {
                    throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete GetDiscontinuedSku information",
                                          999999);
                }
                if (string.IsNullOrEmpty(query.ShoppingCartId) && (query.OrderId == Guid.Empty || string.IsNullOrEmpty(query.OrderNumber)))
                {
                    return(new MobileResponseWrapper
                    {
                        Data = new DiscontinuedSkuResponseViewModel {
                            DiscontinuedSkus = null, RecordCount = 0
                        }
                    });
                }
                query.Locale = Thread.CurrentThread.CurrentCulture.Name;

                GetDiscontinuedSkuParam request = new GetDiscontinuedSkuParam
                {
                    DistributorId = query.DistributorId,
                    Locale        = query.Locale,
                };
                var result = _getDisconinuedSkuProvider.GetDiscontinuedSkuRequest(request);

                if (result != null)
                {
                    var response = new MobileResponseWrapper
                    {
                        Data =
                            new DiscontinuedSkuResponseViewModel
                        {
                            DiscontinuedSkus = result,
                            RecordCount      = result.Count
                        }
                    };

                    MobileActivityLogProvider.ActivityLog(query, response, query.DistributorId, true,
                                                          Request.RequestUri.ToString(),
                                                          Request.Headers.ToString(),
                                                          Request.Headers.UserAgent.ToString(),
                                                          query.Locale);

                    return(response);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Get Discontinued SKUs" + ex.Message, 404);
            }
            var responseWrapper = new MobileResponseWrapper
            {
                Data = new DiscontinuedSkuResponseViewModel {
                    DiscontinuedSkus = null, RecordCount = 0
                }
            };

            MobileActivityLogProvider.ActivityLog(query, responseWrapper, query.DistributorId, true,
                                                  Request.RequestUri.ToString(),
                                                  Request.Headers.ToString(),
                                                  Request.Headers.UserAgent.ToString(),
                                                  query.Locale);

            return(responseWrapper);
        }
        public MobileResponseWrapper Post(WechatPrepayIdRequestViewModel request, string memberId)
        {
            if (request == null || request.Data == null || request.Data.Prepay == null || request.Data.Order == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "request is null", 500404);
            }
            string obj = JsonConvert.SerializeObject(request);

            SetOrderMemberId(request.Data.Order);
            request.Data.Prepay.Locale   = Thread.CurrentThread.CurrentCulture.Name;
            request.Data.Prepay.MemberId = memberId;
            var authToken = Guid.Empty;

            if (null != Request && null != Request.Headers && Request.Headers.Any())
            {
                if (Request.Headers.Contains("X-HLUSER-TOKEN"))
                {
                    var authTokenValue = Request.Headers.GetValues("X-HLUSER-TOKEN").FirstOrDefault();
                    if (!string.IsNullOrEmpty(authTokenValue))
                    {
                        Guid.TryParse(authTokenValue, out authToken);
                    }
                }
            }

            WechatPrepayIdResponseViewModel result = null;
            var errors = new List <ValidationErrorViewModel>();

            if (null != request.Data.Order)
            {
                request.Data.Order.Locale = Thread.CurrentThread.CurrentCulture.Name;

                var amount = decimal.Zero;
                var id     = _mobileWechatProvider.InsertToPaymentGatewayRecord(request.Data.Order,
                                                                                authToken == Guid.Empty ? Guid.NewGuid() : authToken, ref amount);
                if (id == 0)
                {
                    errors.Add(new ValidationErrorViewModel
                    {
                        Code   = 101416,
                        Reason = "InsertToPaymentGatewayRecord failed"
                    });
                }

                if (!string.IsNullOrEmpty(request.Data.Order.OrderNumber) && amount > 0)
                {
                    bool   isLockedeach = true;
                    bool   isLocked     = true;
                    string lockfailed   = string.Empty;


                    if (request.Data.Order.pcLearningPointOffSet > 0M && request.Data.Order.CategoryType != "ETO")
                    {
                        isLockedeach = OrderProvider.LockPCLearningPoint(request.Data.Prepay.MemberId, request.Data.Order.OrderNumber,
                                                                         request.Data.Order.OrderMonth,
                                                                         request.Data.Order.pcLearningPointOffSet, HLConfigManager.Platform);
                        if (!isLockedeach)
                        {
                            lockfailed = "PC Learning Point";
                            isLocked   = false;
                        }
                    }
                    else if (request.Data.Order.pcLearningPointOffSet > 0M)
                    {
                        isLockedeach = OrderProvider.LockETOLearningPoint(
                            request.Data.Order.OrderItems.Select(s => s.Sku),
                            request.Data.Prepay.MemberId,
                            request.Data.Order.OrderNumber,
                            request.Data.Order.OrderMonth,
                            request.Data.Order.pcLearningPointOffSet,
                            HLConfigManager.Platform);

                        if (!isLockedeach)
                        {
                            lockfailed = "ETO Learning Point";
                            isLocked   = false;
                        }
                    }
                    var shoppingcart = ShoppingCartProvider.GetShoppingCart(request.Data.Prepay.MemberId, request.Data.Prepay.Locale, true, false);
                    if (shoppingcart.HastakenSrPromotion)
                    {
                        isLockedeach = ChinaPromotionProvider.LockSRPromotion(shoppingcart, request.Data.Order.OrderNumber);
                        if (!isLockedeach)
                        {
                            lockfailed = lockfailed + ", SR Promotion";
                            isLocked   = false;
                        }
                    }
                    if (shoppingcart.HastakenSrPromotionGrowing)
                    {
                        isLockedeach = ChinaPromotionProvider.LockSRQGrowingPromotion(shoppingcart, request.Data.Order.OrderNumber);
                        if (!isLockedeach)
                        {
                            lockfailed = lockfailed + ", SR Query Growing";
                            isLocked   = false;
                        }
                    }
                    if (shoppingcart.HastakenSrPromotionExcelnt)
                    {
                        isLockedeach = ChinaPromotionProvider.LockSRQExcellentPromotion(shoppingcart, request.Data.Order.OrderNumber);
                        if (!isLockedeach)
                        {
                            lockfailed = lockfailed + ", SR Query Excellent";
                            isLocked   = false;
                        }
                    }
                    if (shoppingcart.HastakenBadgePromotion)
                    {
                        isLockedeach = ChinaPromotionProvider.LockBadgePromotion(shoppingcart, request.Data.Order.OrderNumber);
                        if (!isLockedeach)
                        {
                            lockfailed = lockfailed + ", BadgePromotion";
                            isLocked   = false;
                        }
                    }
                    if (shoppingcart.HastakenNewSrpromotion)
                    {
                        isLockedeach = ChinaPromotionProvider.LockNewSRPromotion(shoppingcart, request.Data.Order.OrderNumber);
                        if (!isLockedeach)
                        {
                            lockfailed = lockfailed + ", NewSrPromotion";
                            isLocked   = false;
                        }
                    }

                    if (shoppingcart.HasBrochurePromotion)
                    {
                        isLockedeach = ChinaPromotionProvider.LockBrochurePromotion(shoppingcart, request.Data.Order.OrderNumber);
                        if (!isLockedeach)
                        {
                            lockfailed = lockfailed + ", BrochurePromotion";
                            isLocked   = false;
                        }
                    }

                    if (isLocked)
                    {
                        result = _mobileWechatProvider.GetPrepayId(request.Data.Prepay, request.Data.Order.OrderNumber, amount);
                    }
                    else
                    {
                        errors.Add(new ValidationErrorViewModel
                        {
                            Code   = 101417,
                            Reason = lockfailed.TrimStart(',') + " locking failed"
                        });
                    }
                }
            }

            var response = new MobileResponseWrapper
            {
                Data             = result,
                ValidationErrors = errors.Any() ? errors : null
            };

            JObject json = JObject.Parse(obj);

            MobileActivityLogProvider.ActivityLog(json, response, memberId ?? string.Empty, true,
                                                  Request.RequestUri.ToString(),
                                                  Request.Headers.ToString(),
                                                  Request.Headers.UserAgent.ToString(),
                                                  request.Data.Prepay.Locale);

            return(response);
        }
Exemplo n.º 18
0
        public MobileResponseWrapper Get([FromUri] FavouriteSKUItemViewModel query)
        {
            try
            {
                List <FavouriteSKUItemResponseViewModel> result = null;

                if (query == null)
                {
                    throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete GetFavouriteSKU information", 999999);
                }
                string obj = JsonConvert.SerializeObject(query);

                query.Locale = Thread.CurrentThread.CurrentCulture.Name != null ? Thread.CurrentThread.CurrentCulture.Name : null;

                if (string.IsNullOrEmpty(query.MemberId) || string.IsNullOrEmpty(query.Locale))
                {
                    return(new MobileResponseWrapper {
                        Data = new FavouriteSKUResponseViewModel {
                            FavouriteSKUs = null, RecordCount = 0
                        }
                    });
                }

                GetFavouriteParam request = new GetFavouriteParam {
                    DistributorID = query.MemberId, Locale = query.Locale
                };

                result = _mobileFavouriteProvider.GetFavouriteSKUs(request);
                if (result != null)
                {
                    var response = new MobileResponseWrapper
                    {
                        Data =
                            new FavouriteSKUResponseViewModel
                        {
                            FavouriteSKUs = result,
                            RecordCount   = result.Count()
                        }
                    };
                    JObject json = JObject.Parse(obj);
                    MobileActivityLogProvider.ActivityLog(json, response, query.DistributorID, true,
                                                          this.Request.RequestUri.ToString(),
                                                          this.Request.Headers.ToString(),
                                                          this.Request.Headers.UserAgent.ToString(),
                                                          query.Locale);

                    return(response);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString() + query.MemberId);
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Get Favourite SKUs" + ex.Message, 404);
            }
            var responseWrapper = new MobileResponseWrapper
            {
                Data = new FavouriteSKUResponseViewModel {
                    FavouriteSKUs = null, RecordCount = 0
                }
            };

            MobileActivityLogProvider.ActivityLog(query, responseWrapper, query.MemberId, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  query.Locale);

            return(responseWrapper);
        }
Exemplo n.º 19
0
        public GetFavouriteResponseWrapper Post(SetFavouriteRequestViewModel request, string memberId)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Set Favourite SKU information", 999998);
            }

            if (request.Data.Favourites.Count < 1)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Set Favourite SKU information", 999998);
            }
            string obj      = JsonConvert.SerializeObject(request);
            var    response = new GetFavouriteResponseWrapper
            {
                ValidationErrors = new List <ValidationErrorViewModel>(),
                Data             = new FavouriteSetSKUResponseViewModel
                {
                    Favourites = new List <FavouriteSetSKUResponseViewModelItem>()
                }
            };

            try
            {
                string locale = Thread.CurrentThread.CurrentCulture.Name;

                Dictionary <string, SKU_V01>           allSKU    = CatalogProvider.GetAllSKU(locale);
                List <FavouriteSKUUpdateItemViewModel> favorList = request.Data.Favourites;
                List <ValidationErrorViewModel>        errors    = new List <ValidationErrorViewModel>();

                IEnumerable <FavouriteSKUUpdateItemViewModel> availableList = favorList.Where(x => allSKU.Select(y => y.Key).Contains(x.ProductSKU));
                IEnumerable <FavouriteSKUUpdateItemViewModel> exceptList    = favorList.Except(availableList);


                List <FavouriteSKUUpdateItemViewModel> SKUs = new List <FavouriteSKUUpdateItemViewModel>();
                foreach (var fv in availableList)
                {
                    var sku = allSKU.Where(x => x.Key == fv.ProductSKU); //.Where(x => x.Key == fv.ProductSKU).Select(x => x.Value);

                    if (sku != null)
                    {
                        SKU_V01 pd = (SKU_V01)sku.First().Value;
                        SKUs.Add(new FavouriteSKUUpdateItemViewModel {
                            productID = int.Parse(pd.CatalogItem.StockingSKU), ProductSKU = fv.ProductSKU, Action = fv.Action
                        });
                    }
                }

                string skuList = "";
                foreach (var sku in SKUs)
                {
                    skuList += sku.productID + "," + sku.ProductSKU + "," + sku.Action + "|";
                }


                SetFavouriteParam query = new SetFavouriteParam {
                    DistributorID = memberId,
                    Locale        = Thread.CurrentThread.CurrentCulture.Name,
                    SKUList       = skuList
                };

                var result = _mobileFavouriteProvider.SetFavouriteSKUs(query, ref errors);

                if (result)
                {
                    foreach (var s in SKUs)
                    {
                        response.Data.Favourites.Add(new FavouriteSetSKUResponseViewModelItem {
                            productSKU = s.ProductSKU, Updated = true
                        });
                    }

                    if (exceptList.Any())
                    {
                        foreach (var ex in exceptList)
                        {
                            response.Data.Favourites.Add(new FavouriteSetSKUResponseViewModelItem {
                                productSKU = ex.ProductSKU, Updated = false, reason = "SKU of " + ex.ProductSKU + " not part of product master"
                            });
                        }

                        response.ValidationErrors.Add(
                            new ValidationErrorViewModel
                        {
                            Message = "Update partially successful!"
                        });
                    }
                }
                else
                {
                    response.ValidationErrors.Add(
                        new ValidationErrorViewModel
                    {
                        Message = "Update not successful, kindly contact the administrator!"
                    });
                }
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, response, memberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      locale);


                return(response);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Set Favourite SKU" + ex.Message, 404);
            }
        }
        public OrderResponseViewModel Post([FromBody] OrderRequestViewModel request)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Order information", 101416);
            }
            try
            {
                string obj = JsonConvert.SerializeObject(request);
                request.Data.Locale = Thread.CurrentThread.CurrentCulture.Name;
                SetOrderMemberId(request.Data);
                var response = new OrderResponseViewModel();
                List <ValidationErrorViewModel> errors = null;
                var result = _iMobileOrderProvider.Save(request.Data, ref errors);
                if (result != null)
                {
                    response.Data             = result;
                    response.ValidationErrors = null != errors && errors.Any() ? errors : null;
                    JObject json = JObject.Parse(obj);
                    MobileActivityLogProvider.ActivityLog(json, response, request.Data.CustomerId, true,
                                                          this.Request.RequestUri.ToString(),
                                                          this.Request.Headers.ToString(),
                                                          this.Request.Headers.UserAgent.ToString(),
                                                          request.Data.Locale);

                    return(response);
                }

                if (result != null)
                {
                    var orderResponseViewModel = new OrderResponseViewModel {
                        Data = request.Data
                    };
                    JObject json1 = JObject.Parse(obj);
                    MobileActivityLogProvider.ActivityLog(json1, orderResponseViewModel, request.Data.CustomerId, true,
                                                          this.Request.RequestUri.ToString(),
                                                          this.Request.Headers.ToString(),
                                                          this.Request.Headers.UserAgent.ToString(),
                                                          request.Data.Locale);

                    return(orderResponseViewModel);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Submit Order" + ex.Message, 404);
            }
            var orderResponseViewModel2 = new OrderResponseViewModel {
                Data = null
            };

            MobileActivityLogProvider.ActivityLog(request, orderResponseViewModel2, request.Data.CustomerId, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  request.Data.Locale);

            return(orderResponseViewModel2);
        }
        public OrderResponseViewModel Put(OrderRequestViewModel request)
        {
            if (request == null || request.Data.OrderItems == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Order information", 101416);
            }
            string obj = JsonConvert.SerializeObject(request);

            SetOrderMemberId(request.Data);
            request.Data.Locale = Thread.CurrentThread.CurrentCulture.Name;

            //Logging the bare request before it gets modified as it is a reference type
            //MobileActivityLogProvider.ActivityLog(request, null, request.Data.MemberId, true,
            //            this.Request.RequestUri.ToString(),
            //            this.Request.Headers.ToString(),
            //            this.Request.Headers.UserAgent.ToString(),
            //            request.Data.Locale);


            var orderNumber      = string.Empty;
            var isOrderSubmitted = false;

            if (_mobileQuoteHelper.CheckIfAnyOrderInProcessing(request.Data.MemberId, request.Data.Locale,
                                                               ref orderNumber, ref isOrderSubmitted, request.Data.OrderNumber))
            {
                throw CreateException(HttpStatusCode.NotAcceptable,
                                      "order still processing", 110406, orderNumber);
            }

            var authToken = Guid.Empty;

            if (null != Request && null != Request.Headers && Request.Headers.Any())
            {
                if (Request.Headers.Contains("X-HLUSER-TOKEN"))
                {
                    var authTokenValue = Request.Headers.GetValues("X-HLUSER-TOKEN").FirstOrDefault();
                    if (!string.IsNullOrEmpty(authTokenValue))
                    {
                        Guid.TryParse(authTokenValue, out authToken);
                    }
                }
            }

            var response = new OrderResponseViewModel();
            List <ValidationErrorViewModel> errors = null;
            var result = _iMobileOrderProvider.Submit(request.Data, ref errors, authToken, request.Data.MemberId);

            if (result != null)
            {
                response.Data             = result;
                response.ValidationErrors = null != errors && errors.Any() ? errors : null;
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, response, request.Data.MemberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      request.Data.Locale);

                return(response);
            }

            return(new OrderResponseViewModel {
                Data = null
            });
        }
        public MobileResponseWrapper Get([FromUri] OrderSearchParameter query)
        {
            try
            {
                if (query == null)
                {
                    throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Order information", 101416);
                }
                string obj = JsonConvert.SerializeObject(query);
                query.Locale = Thread.CurrentThread.CurrentCulture.Name;

                var result = _mobileOrderSummaryProvider.GetOrders(query);
                if (result != null)
                {
                    if (!string.IsNullOrEmpty(query.OrderNumber))
                    {
                        result = result.FindAll(r => r.OrderNumber == query.OrderNumber);
                    }
                    var response = new MobileResponseWrapper
                    {
                        Data =
                            new OrdersResponseViewModel
                        {
                            Orders      = result,
                            RecordCount = result != null && result.Any() ? result.Count : 0
                        }
                    };
                    JObject json = JObject.Parse(obj);
                    MobileActivityLogProvider.ActivityLog(json, response, query.MemberId, true,
                                                          this.Request.RequestUri.ToString(),
                                                          this.Request.Headers.ToString(),
                                                          this.Request.Headers.UserAgent.ToString(),
                                                          query.Locale);

                    return(response);
                }

                if (!string.IsNullOrEmpty(query.OrderNumber))
                {
                    var cartId         = 0;
                    var orderViewModel = _iMobileOrderProvider.GetOrderByOrderNumber(query.OrderNumber, query.MemberId,
                                                                                     query.Locale, ref cartId);

                    if (null != orderViewModel)
                    {
                        var mobResponseWrapper = new MobileResponseWrapper
                        {
                            Data =
                                new OrdersResponseViewModel
                            {
                                Orders = new List <OrderViewModel> {
                                    orderViewModel
                                },
                                RecordCount = 1
                            }
                        };
                        JObject json1 = JObject.Parse(obj);
                        MobileActivityLogProvider.ActivityLog(json1, mobResponseWrapper, query.MemberId, true,
                                                              this.Request.RequestUri.ToString(),
                                                              this.Request.Headers.ToString(),
                                                              this.Request.Headers.UserAgent.ToString(),
                                                              query.Locale);

                        return(mobResponseWrapper);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Get Orders" + ex.Message, 404);
            }
            var responseWrapper = new MobileResponseWrapper
            {
                Data = new OrdersResponseViewModel {
                    Orders = null, RecordCount = 0
                }
            };

            MobileActivityLogProvider.ActivityLog(query, responseWrapper, query.MemberId, true,
                                                  this.Request.RequestUri.ToString(),
                                                  this.Request.Headers.ToString(),
                                                  this.Request.Headers.UserAgent.ToString(),
                                                  query.Locale);

            return(responseWrapper);
        }