Example #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 DualOrderMonthViewModel GetDualOrderMonth(string country)
        {
            if (string.IsNullOrEmpty(country))
            {
                LoggerHelper.Error("country is null - MobileDualOrderMonthController");
                return(null);
            }

            try
            {
                var _businessSettings   = new DualOrderMonthProvider(new DualOrderMonthLoader());
                var result              = new DualOrderMonthResponseViewModel();
                var localNow            = DateUtils.GetCurrentLocalTime(country);
                var isDualOrderMonth    = _businessSettings.IsDualOrderMonth(country, localNow);
                var dualOrderMonthModel = new DualOrderMonthViewModel
                {
                    PreviousOrderMonth = localNow.Month - 1,
                };

                if (isDualOrderMonth)
                {
                    var monthEndDate = _businessSettings.GetDualMonthEndValue(country, localNow);
                    dualOrderMonthModel.PreviousOrderMonthEndDate = null != monthEndDate
                        ? monthEndDate.Value.ToString("yyyy-MM-ddTHH:mm:sszzz")
                        : "calendar";
                }
                else
                {
                    dualOrderMonthModel.PreviousOrderMonthEndDate = "calendar";
                }
                return(dualOrderMonthModel);
            }
            catch (Exception ex)
            {
                LoggerHelper.Exception("General", ex, "error in DualOrderMonthViewModel GetDualOrderMonth");
                return(null);
            }
        }
        public QuoteResponseViewModel Quote(OrderViewModel order, ref List <ValidationErrorViewModel> errors)
        {
            try
            {
                if (null == errors)
                {
                    errors = new List <ValidationErrorViewModel>();
                }
                if (ValidateOrderViewModel(order))
                {
                    if (_mobileQuoteHelper.CheckIfOrderCompleted(order.Id))
                    {
                        errors.Add(
                            new ValidationErrorViewModel
                        {
                            Code   = 109999,
                            Reason = string.Format("order for guid {0} already completed", order.Id)
                        });
                        string countrydup = order.Locale.Substring(3, 2);
                        DualOrderMonthViewModel orderMonthDatadup = _dualOrderMonthProvider.GetDualOrderMonth(countrydup);
                        return(new QuoteResponseViewModel
                        {
                            Order = order,
                            DualOrderMonth =
                                new DualOrderMonthViewModel
                            {
                                PreviousOrderMonthEndDate = orderMonthDatadup != null ? orderMonthDatadup.PreviousOrderMonthEndDate : string.Empty,
                                PreviousOrderMonth = orderMonthDatadup != null ? orderMonthDatadup.PreviousOrderMonth : 0,
                            },
                        });
                    }

                    var shoppingCart = _mobileQuoteHelper.PriceCart(ref order, ref errors, checkSkuAvalability: true, checkUnSupportedAddress: true);
                    if (shoppingCart != null)
                    {
                        var ruleErrors = CheckForError(shoppingCart.RuleResults);
                        if (null != ruleErrors && ruleErrors.Any())
                        {
                            errors.AddRange(ruleErrors);
                        }
                        if (errors != null && errors.Count > 1 && errors.Find(f => f.Code.Equals(110430)) != null)
                        {
                            errors.RemoveAll(e => e.Code.Equals(10416));
                        }
                        string country = order.Locale.Substring(3, 2);
                        DualOrderMonthViewModel orderMonthData = _dualOrderMonthProvider.GetDualOrderMonth(country);
                        var dualOrderMonth = new DualOrderMonthResponseViewModel
                        {
                            PreviousOrderMonth        = orderMonthData != null? orderMonthData.PreviousOrderMonth :0,
                            PreviousOrderMonthEndDate = orderMonthData != null? orderMonthData.PreviousOrderMonthEndDate : string.Empty
                        };
                        var result = new QuoteResponseViewModel
                        {
                            Order          = order,
                            DualOrderMonth =
                                new DualOrderMonthViewModel
                            {
                                PreviousOrderMonthEndDate = dualOrderMonth.PreviousOrderMonthEndDate,
                                PreviousOrderMonth        = dualOrderMonth.PreviousOrderMonth
                            },
                        };
                        SaveMobileQuoteResponse(result, shoppingCart.ShoppingCartID);
                        return(result);
                    }
                }
                errors.Add(
                    new ValidationErrorViewModel
                {
                    Code   = 100416,
                    Reason = "Quote failed"
                });
                return(new QuoteResponseViewModel
                {
                    Order = order,
                });
            }
            catch (Exception ex)
            {
                LoggerHelper.Exception("System.Exception", ex, "Exception in Quote method MobileQuoteProvider");
                errors.Add(
                    new ValidationErrorViewModel
                {
                    Code   = 100416,
                    Reason = "Quote failed"
                });
                return(new QuoteResponseViewModel
                {
                    Order = order,
                });
            }
        }