Пример #1
0
        //Add to related category
        //by add a related category, the product will show in the category results
        public async Task <IActionResult> AddToRelatedCategory(int categoryId = -1, int productId = -1)
        {
            if (categoryId == -1 || productId == -1)
            {
                return(Json(false));
            }
            try
            {
                RelatedCategory relatedCategory = new RelatedCategory();
                relatedCategory.ProductId  = productId;
                relatedCategory.CategoryId = categoryId;
                await _db.RelatedCategories.AddAsync(relatedCategory);

                await _db.SaveChangesAsync();

                var addedCategory = await _db.Categories.AsNoTracking()
                                    .Where(c => c.CategoryId.Equals(categoryId))
                                    .Select(c => new CategoryTitleDropDown()
                {
                    Id = c.CategoryId, Title = c.Title, Selected = false
                })
                                    .FirstOrDefaultAsync();

                ViewData["ProductId"] = productId;
                return(PartialView(viewName: "_AddedRelatedCategory", model: addedCategory));
            }
            catch (Exception)
            {
                return(Json(false));
            }
        }
    public async Task RelatedCategoryTest()
    {
        RelatedCategory data = (await FredClient.GetRelatedCategories("32073")).FirstOrDefault();

        Assert.IsNotNull(data);
        Assert.IsFalse(IsZeroString(data.CategoryID));
        Assert.IsFalse(IsZeroString(data.RelatedCategoryID));
    }