public async Task <int> LikeImg(ApplicationUser currentUser, string likeContentId) { var prevLike = _context.Likes.FirstOrDefault(x => x.UserId == currentUser.Id && x.ContentId == likeContentId); if (prevLike == null) { var like = new Like() { UserId = currentUser.Id, ContentId = likeContentId, ContentType = EReactionContentType.Img }; await _context.Likes.AddAsync(like); } else { _context.Likes.Remove(prevLike); } await _context.SaveChangesAsync(); var likesCount = _context.Likes.Count(x => x.ContentId == likeContentId); return(likesCount); }
public async Task <IActionResult> ConfirmEmail(string userId, string email, string code) { if (userId == null || code == null) { _logger.LogInformation("Not found: userid = " + userId + "; code = " + code); return(RedirectToAction(nameof(HomeController.Index), "Home")); } var user = await _userManager.FindByIdAsync(userId); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{userId}'."); } var result = await _userManager.ConfirmEmailAsync(user, code); if (result.Succeeded) { // Used to modify the current email. if (!string.IsNullOrEmpty(email)) { user.Email = email; await TryUpdateModelAsync(user); await _context.SaveChangesAsync(); await _userManager.UpdateAsync(user); return(View("EmailConfirmed")); } } return(View("Error")); }