public static string GetName(ListingsModeType type) { switch (type) { case ListingsModeType.All: return("All"); case ListingsModeType.OnlyFBA: return("Only FBA"); case ListingsModeType.WithoutFBA: return("w/o FBA"); } return("-"); }
/// <summary> /// Get items for grid /// </summary> /// <param name="db"></param> /// <param name="parentASIN"></param> /// <returns></returns> public static IEnumerable <ItemViewModel> GetAll(IUnitOfWork db, MarketType market, string marketplaceId, string parentASIN, ListingsModeType listingMode) { var query = db.Items.GetAllActualWithSold() .Where(i => i.ParentASIN == parentASIN); if (market != MarketType.None) { query = query.Where(i => i.Market == (int)market); } if (!String.IsNullOrEmpty(marketplaceId)) { query = query.Where(i => i.MarketplaceId == marketplaceId); } switch (listingMode) { case ListingsModeType.OnlyFBA: query = query.Where(l => l.IsFBA); break; case ListingsModeType.WithoutFBA: query = query.Where(l => !l.IsFBA); break; } var items = query .ToList() .Select(i => new ItemViewModel(i)) .ToList(); var skuList = items.Select(i => i.SKU); var itemIds = items.Select(i => i.ItemId); //Fill Item Messages var itemMessagesQuery = db.ItemAdditions.GetAllAsDTO().Where(i => itemIds.Contains(i.ItemId) && (i.Field == ItemAdditionFields.PublishError || i.Field == ItemAdditionFields.PrePublishError || i.Field == ItemAdditionFields.UpdateImageError //|| i.Field == ItemAdditionFields.UpdateRelationshipError )).ToList(); var itemMessages = itemMessagesQuery.ToList(); foreach (var item in items) { if (item.RealQuantity > 0) { item.ItemMessages = itemMessages .Where(m => m.ItemId == item.ItemId) .Select(d => new MessageString() { //Message = d.Value, Status = MessageStatus.Error }) .ToList(); } else { item.ItemMessages = new List <MessageString>(); } if (!String.IsNullOrEmpty(item.PublishedStatusReason) && item.PublishedStatus != (int)PublishedStatuses.Published) { item.ItemMessages.Add(new MessageString() { //Message = item.PublishedStatusReason, Status = MessageStatus.Error }); } } //Update Listing Defects var listingsDefectsQuery = db.ListingDefects.GetAllAsDto().Where(d => skuList.Contains(d.SKU) && d.MarketType == (int)market && d.MarketplaceId == marketplaceId); var listingDefects = listingsDefectsQuery.ToList(); foreach (var item in items) { item.ItemMessages.AddRange(listingDefects .Where(d => d.SKU == item.SKU) .Select(d => new MessageString() { Status = d.AlertName == "Suppressed" ? MessageStatus.Error : MessageStatus.Warning }) .ToList()); } //Update Related Markets var allMarketItems = db.Items.GetAllViewActual() .Where(i => skuList.Contains(i.SKU)) .Select(i => new ItemMarketInfoDTO() { SKU = i.SKU, ASIN = i.ASIN, ParentASIN = i.ParentASIN, Market = i.Market, MarketplaceId = i.MarketplaceId }).ToList(); foreach (var item in items) { item.RelatedMarkets = allMarketItems .Where(i => i.SKU == item.SKU && !(i.MarketplaceId == item.MarketplaceId && i.Market == item.Market)) .Select(i => new ItemMarketInfoViewModel(i)) .ToList() .OrderBy(i => i.MarketIndex) .ToList(); } return(items); }