Esempio n. 1
0
 public void CallCheckAddressByMelissaScrapper(string orderId)
 {
     using (var db = new UnitOfWork(_log))
     {
         var inputAddress       = db.Orders.GetAddressInfo(orderId);
         var addressCheckResult = new PersonatorAddressCheckService(_log, _htmlScraper, null)
                                  .ScrappingCheckAddress(inputAddress);
         Console.WriteLine("IsNotServedByUSPSNote: " + addressCheckResult.IsNotServedByUSPSNote);
     }
 }
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            //NOTE: Skipping valid addresses
            if (addressValidationStatus < AddressValidationStatus.Invalid)
            {
                return(new CheckResult()
                {
                    IsSuccess = true
                });
            }

            var checkUSPSService   = new PersonatorAddressCheckService(_log, _htmlScraper, null);
            var address            = order.GetAddressDto();
            var addressCheckResult = checkUSPSService.ScrappingCheckAddress(address);
            var result             = new CheckResult()
            {
                IsSuccess = !addressCheckResult.IsNotServedByUSPSNote
            };

            _log.Info("AddressNotServedByUSPSChecker, hasNote=" + addressCheckResult.IsNotServedByUSPSNote);

            if (addressCheckResult.IsNotServedByUSPSNote)
            {
                var existNotifier = db.OrderEmailNotifies.IsExist(order.OrderId,
                                                                  OrderEmailNotifyType.OutputAddressNotServedByUSPSEmail);

                if (!existNotifier)
                {
                    var emailInfo = new AddressNotServedByUSPSEmailInfo(_emailService.AddressService,
                                                                        null,
                                                                        order.OrderId,
                                                                        (MarketType)order.Market,
                                                                        address,
                                                                        order.BuyerName,
                                                                        order.BuyerEmail,
                                                                        order.EarliestShipDate ?? (order.OrderDate ?? DateTime.Today).AddDays(1));

                    _emailService.SendEmail(emailInfo, CallSource.Service);
                    _log.Info("Send address not served by USPS email, orderId=" + order.Id);

                    db.OrderEmailNotifies.Add(new OrderEmailNotify()
                    {
                        OrderNumber = order.OrderId,
                        Reason      = "Address isn’t served by USPS",
                        Type        = (int)OrderEmailNotifyType.OutputAddressNotServedByUSPSEmail,
                        CreateDate  = _time.GetUtcTime(),
                    });
                }

                db.OrderComments.Add(new OrderComment()
                {
                    OrderId    = order.Id,
                    Message    = "Address isn’t served by USPS. Address verification email sent.",
                    Type       = (int)CommentType.OutputEmail,
                    CreateDate = _time.GetAppNowTime(),
                    UpdateDate = _time.GetAppNowTime()
                });

                db.Commit();
            }
            return(result);
        }