Exemplo n.º 1
0
        private void Validate(Item item, AmznEntry entry)
        {
            if (item.Notes != null)
            {
                if (item.Notes.Contains("PRE") || item.Notes.Contains("NWB") || item.Notes.Contains("NWD"))
                {
                    entry.Message = "only new products allowed";
                    entry.Status  = StatusCode.Error;
                }
            }

            if (string.IsNullOrWhiteSpace(entry.Format))
            {
                entry.Message = "invalid format";
                entry.Status  = StatusCode.Error;
            }

            if (entry.Q > item.QtyAvailable)
            {
                entry.Message = "out of stock";
                entry.Status  = StatusCode.Error;
            }

            if (string.IsNullOrEmpty(item.GTIN))
            {
                entry.Message = "UPC or EAN required";
                entry.Status  = StatusCode.Error;
            }

            if (item.Department == null)
            {
                entry.Message = "department classification required";
                entry.Status  = StatusCode.Error;
            }
        }
Exemplo n.º 2
0
        private void UpdateGroup(Item item, IEnumerable <AmznEntry> group)
        {
            var active = item.AmznListingItems.Where(p => p.IsActive && p.Marketplace.Code.Equals(_marketplaceCode));

            var entries = group.ToList();

            foreach (var listingItem in active)
            {
                var entry = entries.FirstOrDefault(p => p.IsValid() && p.Format.Equals("GTC"));

                if (entry != null)
                {
                    entry.ASIN = listingItem.ASIN;

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

                        if (listingItem.Quantity == entry.Q.Value)
                        {
                            entry.Q = null;
                        }

                        if (decimal.Compare(listingItem.Price, entry.P.Value) == 0)
                        {
                            entry.P = null;
                        }
                    }

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

                    if (entry != null)
                    {
                        entry.Message = "modified by program";
                        entries.Remove(entry);
                    }
                    else
                    {
                        entry           = new AmznEntry();
                        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.Format = "GTC";
                    entry.ASIN   = listingItem.ASIN;
                    entry.P      = listingItem.Price;
                    entry.Q      = listingItem.Quantity;
                    entry.Title  = listingItem.Title;
                    entry.Status = StatusCode.Completed;
                }
            }
        }