public virtual ActionResult CheckAddress(OrderEditViewModel model)
        {
            var serviceFactory   = new ServiceFactory();
            var addressProviders = AccessManager.Company.AddressProviderInfoList
                                   .Where(a => a.Type != (int)AddressProviderType.SelfCorrection)
                                   .ToList(); //NOTE: exclude self correction
            var addressCheckService = serviceFactory.GetAddressCheckServices(LogService,
                                                                             Time,
                                                                             DbFactory,
                                                                             addressProviders);

            var addressService = new AddressService(addressCheckService,
                                                    null,
                                                    null);

            var validatorService = new OrderValidatorService(LogService,
                                                             DbFactory,
                                                             EmailService,
                                                             Settings,
                                                             OrderHistoryService,
                                                             ActionService,
                                                             PriceService,
                                                             HtmlScraper,
                                                             addressService,
                                                             null,
                                                             null,
                                                             Time,
                                                             AccessManager.Company);

            var        sourceAddress    = model.ComposeAddressDto();
            AddressDTO correctedAddress = null;
            var        checkResults     = validatorService.CheckAddress(CallSource.UI, Db, sourceAddress, null, out correctedAddress);

            foreach (var checkResult in checkResults)
            {
                checkResult.Message = AddressHelper.GeocodeMessageToDisplay(checkResult.Message, true);
            }

            var isSuccess = checkResults.Any(r => r.Status < (int)AddressValidationStatus.Invalid &&
                                             r.Status != (int)AddressValidationStatus.None);

            AddressViewModel correctedModel = correctedAddress != null ?
                                              new AddressViewModel(correctedAddress) : null;

            var result = new AddressValidationResultViewModel()
            {
                IsSuccess        = isSuccess,
                CheckResults     = checkResults,
                CorrectedAddress = correctedModel
            };

            return(new JsonResult
            {
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public OrderEditViewModel(IUnitOfWork db,
                                  ILogService log,
                                  DTOOrder order,
                                  IList <ShipmentProviderDTO> shipmentProviders,
                                  bool isFulfilmentUser)
        {
            EntityId      = order.Id;
            Market        = (MarketType)order.Market;
            MarketplaceId = order.MarketplaceId;
            BatchId       = order.BatchId;
            OrderStatus   = order.OrderStatus;

            OrderId          = order.OrderId;
            ExpectedShipDate = order.EarliestShipDate;
            OnHold           = order.OnHold;
            OnHoldUpdateDate = order.OnHoldUpdateDate;
            IsRefundLocked   = order.IsRefundLocked ?? false;

            AddressValidationStatus    = order.AddressValidationStatus;
            IsDismissAddressValidation = order.IsDismissAddressValidation;
            AddressVerifyRequestDate   = order.AddressVerifyRequestDate;

            AttachedToOrderId = order.AttachedToOrderString;

            PersonName         = order.PersonName;
            BuyerEmail         = order.BuyerEmail;
            ShippingAddress1   = order.ShippingAddress1;
            ShippingAddress2   = order.ShippingAddress2;
            ShippingCity       = order.ShippingCity;
            ShippingState      = order.ShippingState;
            ShippingCountry    = order.ShippingCountry;
            ShippingZip        = order.ShippingZip;
            ShippingZipAddon   = order.ShippingZipAddon;
            ShippingPhone      = order.ShippingPhone;
            SourceShippingName = order.InitialServiceType;

            log.Info("OnEditOrder, Id=" + order.Id + " Before GetByOrderIdDto");
            Comments = db.OrderComments.GetByOrderIdDto(order.Id).OrderBy(c => c.CreateDate)
                       .Select(c => new CommentViewModel
            {
                Id            = c.Id,
                Comment       = c.Message,
                Type          = c.Type,
                LinkedEmailId = c.LinkedEmailId,
                CommentDate   = c.CreateDate,
                CommentByName = c.CreatedByName
            }).ToList();
            Comments.ForEach(c =>
            {
                c.OrderNumber = OrderId; //NOTE: for View Email Url (reply button)
            });

            log.Info("OnEditOrder, Id=" + order.Id + " Before GetByOrderIdDto");
            var addressGoogleValidationMessage = db.OrderNotifies.GetAll()
                                                 .OrderByDescending(n => n.CreateDate)
                                                 .FirstOrDefault(n => n.Type == (int)OrderNotifyType.AddressCheckGoogleGeocode &&
                                                                 n.OrderId == order.Id);

            if (addressGoogleValidationMessage != null)
            {
                AddressGoogleValidationMessage = AddressHelper.GeocodeMessageToDisplay(addressGoogleValidationMessage.Message, false);
            }

            log.Info("OnEditOrder, Id=" + order.Id + " Before GetShippingOptions");
            ShippingOptions = OrderViewModel.GetShippingOptions(order.ShippingInfos,
                                                                (MarketType)order.Market,
                                                                order.IsSignConfirmation,
                                                                order.IsInsured,
                                                                isFulfilmentUser,
                                                                showOptionsPrices: false,
                                                                showProviderName: false);
            ShippingProviders = OrderViewModel.GetShippingProviders(shipmentProviders,
                                                                    (MarketType)order.Market,
                                                                    order.MarketplaceId,
                                                                    order.ShippingCountry,
                                                                    order.SourceShippingService,
                                                                    order.OrderType);

            Shippings = order.ShippingInfos.Select(sh => new OrderShippingViewModel(sh)).ToList();

            Packages = Shippings
                       .Where(sh => sh.IsActive)
                       .OrderBy(sh => sh.ShippingInfoId)
                       .Select(p => new PackageViewModel()
            {
                ShippingId    = p.ShippingInfoId,
                PackageLength = p.PackageLength,
                PackageWidth  = p.PackageWidth,
                PackageHeight = p.PackageHeight,
            })
                       .ToList();

            ManuallyShipmentProviderType = order.ShipmentProviderType;

            var shippingGroup = ShippingOptions.FirstOrDefault(x => x.Selected);

            ManuallyShippingGroupId = shippingGroup == null ? null : shippingGroup.Value;
            RequiredPackageSize     = shippingGroup != null && shippingGroup.RequiredPackageSize;

            if (order.IsManuallyUpdated)
            {
                ManuallyPersonName       = order.ManuallyPersonName;
                ManuallyShippingAddress1 = order.ManuallyShippingAddress1;
                ManuallyShippingAddress2 = order.ManuallyShippingAddress2;
                ManuallyShippingCity     = order.ManuallyShippingCity;
                ManuallyShippingState    = order.ManuallyShippingState;
                ManuallyShippingUSState  = order.ManuallyShippingState;
                ManuallyShippingCountry  = order.ManuallyShippingCountry;
                ManuallyShippingZip      = order.ManuallyShippingZip;
                ManuallyShippingZipAddon = order.ManuallyShippingZipAddon;
                ManuallyShippingPhone    = order.ManuallyShippingPhone;
            }
            else
            {
                ManuallyPersonName       = order.PersonName;
                ManuallyShippingAddress1 = order.ShippingAddress1;
                ManuallyShippingAddress2 = order.ShippingAddress2;
                ManuallyShippingCity     = order.ShippingCity;
                ManuallyShippingState    = order.ShippingState;
                ManuallyShippingUSState  = order.ShippingState;
                ManuallyShippingCountry  = order.ShippingCountry;
                ManuallyShippingZip      = order.ShippingZip;
                ManuallyShippingZipAddon = order.ShippingZipAddon;
                ManuallyShippingPhone    = order.ShippingPhone;
            }

            IsManuallyUpdated = order.IsManuallyUpdated;

            IsPrime = order.OrderType == (int)OrderTypeEnum.Prime;

            //InsuredValue = order.TotalPrice;
            InsuredValue       = order.Items.Sum(i => i.ItemPrice);
            IsInsured          = order.IsInsured;
            IsSignConfirmation = order.IsSignConfirmation;

            HasBatchLabel = order.ShippingInfos.Any(sh => !String.IsNullOrEmpty(sh.TrackingNumber));
            Items         = SplitItems(order.Items).ToList();

            if (order.Notifies != null)
            {
                var cancelationRequest =
                    order.Notifies.FirstOrDefault(n => n.Type == (int)OrderNotifyType.CancellationRequest);
                if (cancelationRequest != null)
                {
                    HasCancelationRequest = true;
                }

                var oversoldNotify = order.Notifies.FirstOrDefault(n => n.Type == (int)OrderNotifyType.OversoldItem ||
                                                                   n.Type == (int)OrderNotifyType.OversoldOnHoldItem);
                if (oversoldNotify != null)
                {
                    IsOversold = true;
                }
            }
            log.Info("OnEditOrder, Id=" + order.Id + " End OrderEditViewModel");
        }