private async Task SetWishlistModelAsync() { if (_signInManager.IsSignedIn(HttpContext.User)) { WishlistModel = await _wishlistViewModelService.GetOrCreateWishlistForUser(User.Identity.Name); } else { GetOrSetWishlistCookieAndUserName(); WishlistModel = await _wishlistViewModelService.GetOrCreateWishlistForUser(_username); } }
private async Task <WishlistViewModel> GetWishlistViewModelAsync() { if (_signInManager.IsSignedIn(HttpContext.User)) { return(await _wishlistService.GetOrCreateWishlistForUser(User.Identity.Name)); } string anonymousId = GetWishlistIdFromCookie(); if (anonymousId == null) { return(new WishlistViewModel()); } return(await _wishlistService.GetOrCreateWishlistForUser(anonymousId)); }
public async Task <IActionResult> OnPost(int wishListItemId) { var wishlist = await _wishlistViewModelService.GetOrCreateWishlistForUser(User.Identity.Name); if (wishlist == null) { //throw new Exception("Invalid Wishlist"); return(BadRequest("Invalid Wishlist")); } var wishListItem = wishlist.Items.Where(x => x.Id == wishListItemId).FirstOrDefault(); if (wishListItem == null) { //throw new Exception("Invalid Wishlist"); return(BadRequest("Item already in Wishlist")); } var basket = await _basketViewModelService.GetOrCreateBasketForUser(User.Identity.Name); if (basket == null) { return(RedirectToPage("/Login")); } var catalogItem = await _catalogItemRepository.GetByIdAsync(wishListItem.CatalogItemId); await _basketService.AddItemToBasket(basket.Id, wishListItem.CatalogItemId, catalogItem.Price); return(RedirectToPage("/Basket/Index")); }