public async Task <IActionResult> Share(ShareWishListForm model) { if (ModelState.IsValid) { var user = await _workContext.GetCurrentUser(); var wishList = await _wishListRepository .Query() .SingleOrDefaultAsync(x => x.UserId == user.Id); string sharingCode = String.Empty; if (wishList.SharingCode == null) { sharingCode = _wishListService.GenerateSharingCode(wishList.Id); wishList.SharingCode = sharingCode; await _wishListRepository.SaveChangesAsync(); } else { sharingCode = wishList.SharingCode; } var wishListUrl = Url.Action("PublicList", "WishList", new { id = sharingCode }, protocol: HttpContext.Request.Scheme); string emailBody = $"{user.Email} would like to share their wish list with you: {wishListUrl}" + Environment.NewLine + Environment.NewLine + model.Message; await _emailSender.SendEmailAsync(model.EmailAddress, "Wish List Sharing", emailBody); return(RedirectToAction("PrivateList")); } return(View(model)); }