public bool CheckIfAlreadyVotedForResolution(string resolutionId) { string userId = _context.GetUserByEmail(GetUserEmailFromRequest()).Id; bool voteExist = _context.CheckIfVoteExist(resolutionId, userId); return(voteExist); }
public IActionResult EditUser(EditUserViewModel updatedUser) { if (ModelState.IsValid) { User LegacyUser = _context.GetUserByEmail(updatedUser.EmailBeforeEdit); LegacyUser.FirstName = updatedUser.FirstName; LegacyUser.LastName = updatedUser.LastName; LegacyUser.Email = updatedUser.Email; LegacyUser.Address = updatedUser.Address; _context.SaveChanges(); var role = _userManager.GetRolesAsync(LegacyUser).Result.FirstOrDefault(); if (role != updatedUser.Role) { _userManager.UpdateAsync(LegacyUser); _context.SaveChanges(); _userManager.RemoveFromRoleAsync(LegacyUser, role).Wait(); _userManager.UpdateAsync(LegacyUser); _context.SaveChanges(); _userManager.AddToRoleAsync(LegacyUser, updatedUser.Role).Wait(); _userManager.UpdateAsync(LegacyUser); _context.SaveChanges(); } _context.SaveChanges(); return(Ok()); } else { ModelState.AddModelError("Overall", "Niepoprawnie wprowadzone dane użytkownika"); return(BadRequest(ModelState)); } }