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 })); }
private FavouriteList FindFavouriteListByProductId(FavouriteProduct favouriteProduct) { var favouriteList = this.dbContext.FavouriteLists .Include(x => x.FavouriteProducts) .FirstOrDefault(x => x.Id == favouriteProduct.FavouriteListId); return(favouriteList); }
private FavouriteProduct CreateFavouriteProduct(Product product, FavouriteList favouriteList) { var favouriteProduct = new FavouriteProduct { Product = product, ProductId = product.Id, FavouriteList = favouriteList, FavouriteListId = favouriteList.Id, }; return(favouriteProduct); }
public async Task Create(FavouriteProduct _favourite) { await _context.FavouriteProducts.AddAsync(_favourite); await _context.SaveChangesAsync(); }