Exemplo n.º 1
0
        public IActionResult Wishlist(int productId)
        {
            var success          = true;
            var favouriteProduct = (FavouriteProduct)null;

            try
            {
                favouriteProduct = UnitOfWork.FavouriteProducts.FirstOrDefault(x => x.UserId == SystemUser.Id && x.ProductId == productId, true);
                if (favouriteProduct == null)
                {
                    favouriteProduct = new FavouriteProduct
                    {
                        ProductId = productId,
                        UserId    = SystemUser.Id
                    };
                    success = UnitOfWork.FavouriteProducts.Merge(favouriteProduct);
                }
                else
                {
                    success = UnitOfWork.FavouriteProducts.DeleteOrRestore(favouriteProduct);
                }
            }
            catch (System.Exception)
            {
                success = false;
            }
            return(Json(new { success, isDeleted = favouriteProduct?.IsDeleted }));
        }
Exemplo n.º 2
0
        private FavouriteList FindFavouriteListByProductId(FavouriteProduct favouriteProduct)
        {
            var favouriteList = this.dbContext.FavouriteLists
                                .Include(x => x.FavouriteProducts)
                                .FirstOrDefault(x => x.Id == favouriteProduct.FavouriteListId);

            return(favouriteList);
        }
Exemplo n.º 3
0
        private FavouriteProduct CreateFavouriteProduct(Product product, FavouriteList favouriteList)
        {
            var favouriteProduct = new FavouriteProduct
            {
                Product         = product,
                ProductId       = product.Id,
                FavouriteList   = favouriteList,
                FavouriteListId = favouriteList.Id,
            };

            return(favouriteProduct);
        }
Exemplo n.º 4
0
        public async Task Create(FavouriteProduct _favourite)
        {
            await _context.FavouriteProducts.AddAsync(_favourite);

            await _context.SaveChangesAsync();
        }