public async Task <ActionResult <ProductAJAXViewModel> > AddToFavourites(ProductAJAXViewModel productAJAXViewModel) { var user = await this.userManager.GetUserAsync(this.User); var userId = user.Id; if (!await this.favouriteProductsService.AddAsync(productAJAXViewModel.ProductId, userId)) { productAJAXViewModel.Message = ProductExistsInFavourites; } else { productAJAXViewModel.Message = ProductAddedToFavourites; } return(productAJAXViewModel); }
public async Task <ActionResult <ProductAJAXViewModel> > AddToCart(ProductAJAXViewModel productAJAXViewModel) { var user = await this.userManager.GetUserAsync(this.User); var userId = user.Id; var shoppingCartId = await this.shoppingCartService.GetIdByUserId(userId); if (!await this.shoppingCartProductsService.AddAsync(productAJAXViewModel.ProductId, shoppingCartId)) { productAJAXViewModel.Message = ProductExistsInCart; } else { productAJAXViewModel.Message = ProductAddedInCart; } var productsCount = await this.shoppingCartService.GetProductsCountAsync(userId); productAJAXViewModel.Count = productsCount; return(productAJAXViewModel); }