public CheckResult Check(IUnitOfWork db, DTOMarketOrder order, IList <ListingOrderDTO> items, AddressValidationStatus addressValidationStatus) { if (order.Id == 0) { throw new ArgumentOutOfRangeException("order.Id", "Should be non zero"); } if (order.OrderStatus == OrderStatusEnumEx.Pending) { throw new ArgumentException("order.OrderStatus", "Not supported status Pending"); } //International order has issue with PersonName if (!AddressHelper.IsStampsValidPersonName(order.FinalPersonName) && (order.AddressValidationStatus == (int)AddressValidationStatus.InvalidRecipientName || ShippingUtils.IsInternationalState(order.FinalShippingState) || ShippingUtils.IsInternational(order.FinalShippingCountry))) { //If can resolved using BuyerName var nameKeywords = (order.FinalPersonName ?? "").Split(", .".ToCharArray()).Where(n => n.Length > 2).ToArray(); if (!nameKeywords.Any()) { nameKeywords = (order.FinalPersonName ?? "").Split(", .".ToCharArray()).ToArray(); } if (AddressHelper.IsStampsValidPersonName(order.BuyerName) //NOTE: #1 Exclude prefix Mr., initials, like a.cheszes //NOTE: #2 Include when name has only one letter && StringHelper.ContrainOneOfKeywords(order.BuyerName, nameKeywords)) { db.OrderComments.Add(new OrderComment() { OrderId = order.Id, Message = "[System] Incomplete recipient name was replaced with buyer name: " + order.FinalPersonName + "=>" + order.BuyerName, Type = (int)CommentType.Address, CreateDate = _time.GetAppNowTime() }); if (order.IsManuallyUpdated) { order.ManuallyPersonName = order.BuyerName; } else { order.PersonName = order.BuyerName; } return(new CheckResult() { IsSuccess = true, AdditionalData = new[] { order.PersonName } }); } //Send email else { var emailInfo = new IncompleteNameEmailInfo(_emailService.AddressService, null, order.OrderId, (MarketType)order.Market, order.GetAddressDto(), items, order.BuyerName, order.BuyerEmail); _emailService.SendEmail(emailInfo, CallSource.Service); _log.Info("Send incomplete person name email, orderId=" + order.Id); db.OrderEmailNotifies.Add(new OrderEmailNotify() { OrderNumber = order.OrderId, Reason = "System emailed, incomplete name", Type = (int)OrderEmailNotifyType.OutputIncompleteNameEmail, CreateDate = _time.GetUtcTime(), }); db.OrderComments.Add(new OrderComment() { OrderId = order.Id, Message = "[System] Incomplete name email sent", Type = (int)CommentType.Address, CreateDate = _time.GetAppNowTime(), UpdateDate = _time.GetAppNowTime() }); db.Commit(); return(new CheckResult() { IsSuccess = false, AdditionalData = new List <string>() { "OnHold" } }); } } return(new CheckResult() { IsSuccess = false }); }