public IActionResult AcceptInvite(int id) { var user = _userManager.GetUserAsync(User).Result; var wishList = WishListRepository.Find(id); if (wishList.PendingInvites.Any(pi => pi.UserId == user?.Id)) { return(BadRequest("subscription already exists")); } wishList.PendingInvites.RemoveAll(pi => pi.UserId == user?.Id); var subscriber = new WishListSubscriber { User = _userManager.GetUserAsync(User).Result, WishList = wishList }; wishList.AddSubscriber(subscriber); WishListRepository.Update(wishList); // _userManager.UpdateAsync(user); return(Ok()); }
private async Task InitializeUsers() { var firstUser = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; var wishList = new WishList("Birthday") { CreatorName = firstUser.UserName, Wishes = new List <Wish> { new Wish { Name = "Car", Description = "Vehicle with four wheels", Price = 10000 }, new Wish { Name = "Teddy bear", Description = "Plushy toy", Price = 20, Claimed = true }, new Wish { Name = "iPhone X", Description = "Cool phone", Price = 999999 }, new Wish { Name = "Guitar", Description = "For playing music", Price = 200, Claimed = true }, new Wish { Name = "Money", Description = "It's money", Price = 20, Claimed = true } } }; firstUser.CreateWishList(wishList); firstUser.CreateWishList(new WishList("Christmas")); var secondUser = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; var secondWishList = new WishList("Easter") { CreatorName = secondUser.UserName, Wishes = new List <Wish> { new Wish { Name = "New Wish" } } }; secondUser.CreateWishList(secondWishList); var invite = new PendingInvite { User = firstUser, WishList = secondWishList }; var subscription = new WishListSubscriber { User = secondUser, WishList = wishList }; secondWishList.AddInvite(invite); secondUser.Subscribe(subscription); await _userManager.CreateAsync(firstUser, "P@ssword1"); await _userManager.CreateAsync(secondUser, "P@ssword1"); }