Ejemplo n.º 1
0
        private void Validate(Item item, EbayEntry entry)
        {
            if (entry.GetFormat().Equals(EbayMarketplace.FORMAT_AUCTION))
            {
                if (entry.Q > 1)
                {
                    entry.Message = "auction max qty is 1";
                    entry.Status  = StatusCode.Error;
                }
            }

            if (string.IsNullOrWhiteSpace(entry.Code))
            {
                if (entry.StartDate != null && entry.StartDate < DateTime.UtcNow)
                {
                    entry.Message = "cannot schedule in the past";
                    entry.Status  = StatusCode.Error;
                }

                if (string.IsNullOrWhiteSpace(entry.FullDescription))
                {
                    entry.Message = "full description required";
                    entry.Status  = StatusCode.Error;
                }

                if (entry.Q < 1)
                {
                    entry.Message = "quantity must be greater than zero";
                    entry.Status  = StatusCode.Error;
                }

                if (string.IsNullOrWhiteSpace(entry.Title))
                {
                    entry.Message = "title required";
                    entry.Status  = StatusCode.Error;
                }
            }

            if (entry.Q > item.QtyAvailable)
            {
                entry.Message = "out of stock";
                entry.Status  = StatusCode.Error;
            }
            if (item.Department == null)
            {
                entry.Message = "department required";
                entry.Status  = StatusCode.Error;
            }
            if (entry.Title != null && entry.Title.Count() > 80)
            {
                entry.Message = "title max characters is 80";
                entry.Status  = StatusCode.Error;
            }
        }
Ejemplo n.º 2
0
        private void UpdateGroup(Item item, IEnumerable <EbayEntry> group)
        {
            var active = item.EbayListingItems.Where(p => p.Listing.Marketplace.Code.Equals(_marketplaceCode) && p.Listing.Status.Equals(EbayMarketplace.STATUS_ACTIVE));

            var entries = group.ToList();

            foreach (var listingItem in active)
            {
                string format = listingItem.Listing.Format.Equals(EbayMarketplace.FORMAT_STOREFIXEDPRICE) ? EbayMarketplace.FORMAT_FIXEDPRICE : listingItem.Listing.Format;

                EbayEntry entry = entries.FirstOrDefault(p => p.IsValid() && p.GetFormat().Equals(format));

                if (entry != null)
                {
                    entry.Code = listingItem.Listing.Code;

                    entry.SetFormat(listingItem.Listing.Format, listingItem.Listing.Duration, (bool)listingItem.Listing.IsVariation);

                    if (entry.Q.Value == listingItem.Quantity && decimal.Compare(entry.P.Value, listingItem.Price) == 0 && entry.GetUpdateFlags().Count == 0)
                    {
                        entry.Status = StatusCode.Completed;
                    }
                    else
                    {
                        entry.Message = string.Format("({0}|{1}|{2})", listingItem.FormatCode, listingItem.Quantity, Math.Round(listingItem.Price, 2));
                    }

                    entries.Remove(entry);
                }
                else
                {
                    entry = entries.FirstOrDefault(p => p.IsValid() == false);

                    if (entry != null)
                    {
                        entry.Message = "modified by program";
                        entries.Remove(entry);
                    }
                    else
                    {
                        entry           = new EbayEntry();
                        entry.Brand     = item.SubDescription1;
                        entry.ClassName = item.ClassName;
                        entry.Sku       = item.ItemLookupCode;
                        entry.Message   = "added by program";

                        entry.ParentRowIndex = group.First().RowIndex;

                        _addedEntries.Add(entry);
                    }


                    entry.Code = listingItem.Listing.Code;
                    entry.SetFormat(listingItem.Listing.Format, listingItem.Listing.Duration, (bool)listingItem.Listing.IsVariation);
                    entry.P               = listingItem.Price;
                    entry.Q               = listingItem.Quantity;
                    entry.Title           = listingItem.Listing.Title;
                    entry.FullDescription = listingItem.Listing.FullDescription;
                    entry.Status          = StatusCode.Completed;
                }
            }

            foreach (var entry in entries)
            {
                EbayListing listing = _dataContext.EbayListings.SingleOrDefault(p => p.Sku.Equals(item.ClassName) && p.Status.Equals(EbayMarketplace.STATUS_ACTIVE) && p.Marketplace.Code.Equals(_marketplaceCode));

                if (listing != null)
                {
                    if (!entry.IsValid())
                    {
                        entry.Code            = listing.Code;
                        entry.Title           = listing.Title;
                        entry.FullDescription = listing.FullDescription;
                        entry.SetFormat(listing.Format, listing.Duration, (bool)listing.IsVariation);
                        entry.Message = "modified by program";
                    }
                    else if (entry.GetFormat().Equals(EbayMarketplace.FORMAT_FIXEDPRICE))
                    {
                        entry.Code = listing.Code;
                        entry.SetFormat(listing.Format, listing.Duration, (bool)listing.IsVariation);
                        entry.Message = "modified by program";
                    }
                }
            }
        }