コード例 #1
0
        public static ImageLayout From(ShippingMethodDTO shippingMethod)
        {
            var offsetX = 0;
            var offsetY = 0;
            var width   = 0;
            var heigth  = 0;

            if (!String.IsNullOrEmpty(shippingMethod.CroppedLayout))
            {
                var parts = shippingMethod.CroppedLayout.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                offsetX = Int32.Parse(parts[0]);
                offsetY = Int32.Parse(parts[1]);
                width   = Int32.Parse(parts[2]);
                heigth  = Int32.Parse(parts[3]);
            }

            return(new ImageLayout()
            {
                IsCrop = shippingMethod.IsCroppedLabel,

                OffsetX = offsetX,
                OffsetY = offsetY,
                Width = width,
                Height = heigth
            });
        }
コード例 #2
0
        private List <ShippingMethodDTO> GetShippingMethods(Langs l)
        {
            List <ShippingMethodDTO> ShippingMethodDTOs = new List <ShippingMethodDTO>();
            var lang    = Utils.getLanguage(l);
            var methods = unitOfWork.ShippingBillingMethodRepository.Get(c => c.IsActive == true && c.IsShipping == true).ToList();

            foreach (var method in methods)
            {
                ShippingMethodDTO shippingMethodDTO = new ShippingMethodDTO();
                shippingMethodDTO.Id = method.Id;

                ShippingBillingMethodDescription desc = unitOfWork.ShippingBillingMethodDescriptionRepository.Get(c =>
                                                                                                                  c.LanguageId == lang &&
                                                                                                                  c.ShippingBillingMethodId == method.Id).FirstOrDefault();

                shippingMethodDTO.Name            = desc.Name;
                shippingMethodDTO.MetaDescription = desc.MetaDescription;

                ShippingMethodDTOs.Add(shippingMethodDTO);
            }
            return(ShippingMethodDTOs);
        }
コード例 #3
0
        public OrderDTO GetOrderById(long id, Langs l, Currency c)
        {
            OrderDTO orderDTO = new OrderDTO();
            Order    order    = unitOfWork.OrderRepository.GetByID(id);

            orderDTO.BillingAddress  = GetOrderAddress(order.BillingAddress);
            orderDTO.ShippingAddress = GetOrderAddress(order.ShippingAddress);
            orderDTO.OrderItems      = GetOrderItems(order.Id, l, c);
            orderDTO.CurrencyName    = Utils.getCurrencyName(c, l);
            orderDTO.InvoiceId       = order.InvoiceId;
            orderDTO.ClosingDate     = order.ClosingDate;
            orderDTO.UserIpAddress   = order.UserIpAddress;
            orderDTO.UserAgent       = order.UserAgent;
            if (!String.IsNullOrEmpty(order.CouponCode))
            {
                orderDTO.CouponCode     = order.CouponCode;
                orderDTO.CouponValue    = order.CouponValue;
                orderDTO.CouponCurrency = orderDTO.CurrencyName;
                if (!order.CouponIsPercentage)
                {
                    orderDTO.CouponValue    = Utils.getCurrency(c, l, order.CouponValue).Item1;
                    orderDTO.CouponCurrency = "-";
                }
                else
                {
                    orderDTO.CouponCurrency = "%";
                }
            }

            // get Order Owner
            var user = _userService.getuserById(order.UserId);

            orderDTO.CreationDate       = order.CreationDate.Value;
            orderDTO.DateModified       = order.DateModified;
            orderDTO.Discount           = order.Discount;
            orderDTO.Id                 = order.Id;
            orderDTO.InvoiceId          = order.InvoiceId;
            orderDTO.PaymentDate        = order.PaymentDate;
            orderDTO.PaymentNotes       = order.PaymentNotes;
            orderDTO.PaymentDate        = order.PaymentDate;
            orderDTO.ShippingCost       = order.ShippingCost;
            orderDTO.Status             = order.Status;
            orderDTO.SubTotal           = Utils.getCurrency(c, l, order.SubTotal).Item1;
            orderDTO.Total              = Utils.getCurrency(c, l, order.Total).Item1;
            orderDTO.TransactionDetails = order.TransactionDetails;
            orderDTO.TransactionId      = order.TransactionId;
            orderDTO.UserId             = order.UserId;
            orderDTO.Phone              = order.ShippingAddress.Phone;
            orderDTO.UserName           = user.FirstName + " " + user.LastName;
            orderDTO.Email              = user.Email;
            orderDTO.OrderHistories     = GetOrderHistory(id);


            ShippingMethodDTO  shippingMethodDTO  = new ShippingMethodDTO();
            BillingMethodDTO   billingMethodDTO   = new BillingMethodDTO();
            ShippingCompanyDTO shippingCompanyDTO = new ShippingCompanyDTO();

            if (l == Langs.English)
            {
                shippingMethodDTO.Name  = order.EnglishShippingName;
                billingMethodDTO.Name   = order.EnglishBillingName;
                shippingCompanyDTO.Name = order.EnglishCompanyName;
            }
            else
            {
                shippingMethodDTO.Name  = order.ArabicShippingName;
                billingMethodDTO.Name   = order.ArabicBillingName;
                shippingCompanyDTO.Name = order.ArabicCompanyName;
            }

            orderDTO.ShippingMethod = shippingMethodDTO;
            orderDTO.BillingMethod  = billingMethodDTO;
            return(orderDTO);
        }
コード例 #4
0
        public void Process(IUnitOfWork db, EmailReadingResult result)
        {
            if (result.Status == EmailMatchingResultStatus.New &&
                result.HasMatches)
            {
                var subject = (result.Email.Subject ?? "");
                var today   = _time.GetAppNowTime().Date;

                //TASK: 1.	Emails which have these in subjects: "Order delivery inquiry" or " Where's My Stuff?”
                //CHANGE: When client sends an email with subject “Package didn’t arrive..” like 113-7086092-7521857, process it same way as emails with subject “Lost Package”…
                var isWhereMyStaff = subject.StartsWith("Order delivery inquiry", StringComparison.OrdinalIgnoreCase) ||
                                     subject.IndexOf("Where's My Stuff?", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                     subject.IndexOf("Where's My Stuff ?", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                     subject.IndexOf("Package didn’t arrive:", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                     subject.IndexOf("Package didn?t arrive", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                     subject.IndexOf("Shipping inquiry", StringComparison.InvariantCultureIgnoreCase) >= 0;    //NOTE: actually came with ? instead of '

                if (isWhereMyStaff)
                {
                    _log.Info("Received 'Where my stuff'");
                    var orderNumber = result.MatchedIdList.FirstOrDefault();
                    if (!String.IsNullOrEmpty(orderNumber))
                    {
                        //TASK: 2.	 Which were successfully delivered to client.
                        var order         = db.Orders.GetByOrderNumber(orderNumber);
                        var shippingInfos = db.OrderShippingInfos.GetByOrderIdAsDto(order.Id).Where(sh => sh.IsActive).ToList();
                        //a.	 delivered to client (not returned to us)
                        var delivered    = shippingInfos.Any() && shippingInfos.All(sh => sh.DeliveredStatus == (int)DeliveredStatusEnum.Delivered);
                        var deliveryDate = shippingInfos.Select(sh => sh.ActualDeliveryDate).FirstOrDefault();
                        //b.	Delivered within last 2 month.
                        if (delivered && deliveryDate.HasValue && deliveryDate > today.AddMonths(-2))
                        {
                            _log.Info("Package was delivered, withing last 2 month");

                            var alreadySendLostTemplate = db.OrderEmailNotifies.IsExist(order.AmazonIdentifier,
                                                                                        OrderEmailNotifyType.OutputLostPackageEmail);

                            //3.	To which we didn’t answer yet with Lost Package template
                            if (!alreadySendLostTemplate)
                            {
                                _log.Info("Not send package lost template");

                                var orderEmails = db.Emails.GetAllByOrderId(order.AmazonIdentifier)
                                                  .Select(m => new
                                {
                                    m.Id,
                                    m.ReceiveDate,
                                    m.Subject
                                }).ToList();
                                var isAnyOtherSimilarEmails = orderEmails.Any(e => e.Id != result.Email.Id &&
                                                                              (e.ReceiveDate <= result.Email.ReceiveDate &&
                                                                               e.Subject.Contains("Where's My Stuff?") ||
                                                                               e.Subject.Contains("Order delivery inquiry")));

                                var isAnyOtherEmailAfterDelivery = deliveryDate.HasValue && orderEmails.Any(e => e.Id != result.Email.Id &&
                                                                                                            e.ReceiveDate >= deliveryDate.Value);

                                //4.	If it’s the first email with that subject ("Order delivery inquiry" or " Where's My Stuff?”)
                                if (!isAnyOtherSimilarEmails && !isAnyOtherEmailAfterDelivery)
                                {
                                    _log.Info("Pass to Order Delivery Inquiry Rule");

                                    OrderShippingInfoDTO shippingInfo   = null;
                                    ShippingMethodDTO    shippingMethod = null;
                                    if (shippingInfos.Any())
                                    {
                                        shippingInfo = shippingInfos.OrderByDescending(sh => sh.ActualDeliveryDate)
                                                       .FirstOrDefault(i => i.IsActive);
                                        if (shippingInfo != null)
                                        {
                                            shippingMethod = db.ShippingMethods.GetByIdAsDto(shippingInfo.ShippingMethodId);
                                        }
                                    }
                                    var emailInfo = new LostPackageEmailInfo(_emailService.AddressService,
                                                                             null,
                                                                             order.AmazonIdentifier,
                                                                             (MarketType)order.Market,
                                                                             shippingInfo != null ? shippingInfo.ActualDeliveryDate : null,
                                                                             shippingInfo != null ? shippingInfo.TrackingStateEvent : null,
                                                                             shippingMethod != null ? shippingMethod.CarrierName : null,
                                                                             shippingInfo != null ? shippingInfo.TrackingNumber : null,
                                                                             order.GetAddressDto(),
                                                                             order.BuyerName,
                                                                             order.BuyerEmail);

                                    _emailService.SendEmail(emailInfo, CallSource.Service);

                                    db.OrderEmailNotifies.Add(new OrderEmailNotify()
                                    {
                                        OrderNumber = order.CustomerOrderId,
                                        Type        = (int)OrderEmailNotifyType.OutputLostPackageEmail,
                                        Reason      = "Email: " + StringHelper.Substring(subject, 40),
                                        CreateDate  = _time.GetUtcTime()
                                    });

                                    db.OrderComments.Add(new OrderComment()
                                    {
                                        OrderId    = order.Id,
                                        Type       = (int)CommentType.OutputEmail,
                                        Message    = "[System] \"Lost Package\" email sent",
                                        CreateDate = _time.GetAppNowTime(),
                                    });

                                    db.Commit();

                                    result.WasEmailProcessed = true;
                                }
                                else
                                {
                                    if (isAnyOtherSimilarEmails)
                                    {
                                        _log.Info("Similar email was found");
                                    }
                                    if (isAnyOtherEmailAfterDelivery)
                                    {
                                        _log.Info("Other email was found after delivery");
                                    }
                                }
                            }
                            else
                            {
                                _log.Info("Already sent Lost Package template");
                            }
                        }
                        else
                        {
                            _log.Info("Package not yet delivered");
                        }
                    }
                }
            }
        }
コード例 #5
0
        public static CustomShippingViewModel Get(IUnitOfWork db, long orderId, long?defaultShippingMethodId)
        {
            var result = new CustomShippingViewModel();

            var order           = db.Orders.GetById(orderId);
            var isIntl          = ShippingUtils.IsInternational(order.ShippingCountry);
            var shippingMethods = db.ShippingMethods.GetAllAsDto()
                                  .Where(m => m.ShipmentProviderType == order.ShipmentProviderType &&
                                         m.IsInternational == isIntl &&
                                         m.IsActive)
                                  .ToList();

            result.PackageList = new List <SelectListItemTag>();
            foreach (var shippingMethod in shippingMethods)
            {
                for (int i = 0; i <= 6; i++)
                {
                    result.PackageList.Add(new SelectListItemTag()
                    {
                        Text  = shippingMethod.Name + " - #" + (i + 1),
                        Value = shippingMethod.Id.ToString() + "-" + (i + 1),
                    });
                }
            }

            var customShippings = db.OrderShippingInfos.GetAllAsDto()
                                  .Where(sh => sh.OrderId == orderId &&
                                         sh.ShippingGroupId == RateHelper.CustomPartialGroupId)
                                  .OrderBy(sh => sh.ShippingNumber)
                                  .ToList();

            var orderItems = db.Listings.GetOrderItems(orderId)
                             .OrderBy(oi => oi.ItemOrderId)
                             .ToList();

            //var orderItems = db.OrderItems.GetWithListingInfo()
            //    .Where(oi => oi.OrderId == orderId)
            //    .OrderBy(oi => oi.ItemOrderId)
            //    .ToList();

            var itemToShipping = new List <OrderShippingInfoDTO>();

            if (customShippings.Any())
            {
                var shippingIds = customShippings.Select(sh => sh.Id).ToList();

                itemToShipping = (from m in db.ItemOrderMappings.GetAll()
                                  join sh in db.OrderShippingInfos.GetAll() on m.ShippingInfoId equals sh.Id
                                  join sm in db.ShippingMethods.GetAll() on sh.ShippingMethodId equals sm.Id
                                  where shippingIds.Contains(m.ShippingInfoId)
                                  select new OrderShippingInfoDTO()
                {
                    Id = m.ShippingInfoId,
                    Items = new List <DTOOrderItem>()
                    {
                        new DTOOrderItem()
                        {
                            OrderItemEntityId = m.OrderItemId,
                            Quantity = m.MappedQuantity
                        }
                    },
                    ShippingMethod = new ShippingMethodDTO()
                    {
                        Id = sm.Id,
                        Name = sm.Name,
                        ShortName = sm.ShortName,
                        RequiredPackageSize = sm.RequiredPackageSize
                    }
                }).ToList();
            }

            var shippingNumbers    = new Dictionary <long, int>();
            var shippings          = itemToShipping.GroupBy(sh => sh.Id).Select(sh => sh.First()).ToList();
            var processedShippings = new List <OrderShippingInfoDTO>();

            foreach (var shipping in shippings)
            {
                var count = processedShippings.Count(sh => sh.ShippingMethod.Id == shipping.ShippingMethod.Id);
                shippingNumbers.Add(shipping.Id, count + 1);
                processedShippings.Add(shipping);
            }

            ShippingMethodDTO defaultShippingMethod = null;

            if (defaultShippingMethodId.HasValue)
            {
                defaultShippingMethod = shippingMethods.FirstOrDefault(m => m.Id == defaultShippingMethodId.Value);
            }
            if (defaultShippingMethod == null)
            {
                defaultShippingMethod = shippingMethods.FirstOrDefault(m => m.Id == ShippingUtils.AmazonFedEx2DayOneRatePakShippingMethodId ||
                                                                       m.Id == ShippingUtils.FedexOneRate2DayPak);
            }

            var defaultPackageNumber = defaultShippingMethod != null ? 1 : (int?)null;

            var items = new List <CustomShippingItemViewModel>();

            foreach (var orderItem in orderItems)
            {
                for (int q = 0; q < orderItem.QuantityOrdered; q++)
                {
                    var existCustomMapping = itemToShipping.FirstOrDefault(i => i.Items.First().OrderItemEntityId == orderItem.OrderItemEntityId &&
                                                                           i.Items.First().Quantity > 0);

                    if (existCustomMapping != null)
                    {
                        existCustomMapping.Items.First().Quantity--;
                    }

                    var image = orderItem.Picture;
                    if (String.IsNullOrEmpty(image))
                    {
                        image = orderItem.StyleImage;
                    }
                    if (orderItem.ReplaceType == (int)ItemReplaceTypes.Combined)
                    {
                        image = orderItem.StyleImage;
                    }
                    var pictureUrl = ImageHelper.GetFirstOrDefaultPicture(image);

                    items.Add(new CustomShippingItemViewModel()
                    {
                        ASIN        = orderItem.ASIN,
                        StyleString = orderItem.StyleID,
                        StyleSize   = orderItem.StyleSize,

                        Weight = orderItem.Weight ?? 0,

                        PictureUrl = pictureUrl,

                        OrderItemId        = orderItem.OrderItemEntityId,
                        ShippingInfoId     = existCustomMapping != null ? existCustomMapping.Id : (long?)null,
                        ShippingMethodName = existCustomMapping != null ? existCustomMapping.ShippingMethod.Name : defaultShippingMethod?.Name,
                        ShippingMethodId   = existCustomMapping != null ? existCustomMapping.ShippingMethod.Id : defaultShippingMethod?.Id,

                        PackageNumber = existCustomMapping != null ? shippingNumbers[existCustomMapping.Id] : defaultPackageNumber,
                    });
                }
            }

            items.ForEach(i =>
            {
                if (i.PackageNumber.HasValue && i.ShippingMethodId.HasValue)
                {
                    i.PackageValue = i.ShippingMethodId.Value + "-" + i.PackageNumber;
                }
            });

            result.Items = items.OrderBy(i => i.ShippingMethodId)
                           .ThenBy(i => i.PackageNumber)
                           .ThenBy(i => i.StyleString) //TODO: by location
                           .ThenBy(i => SizeHelper.GetSizeIndex(i.StyleSize))
                           .ToList();

            return(result);
        }