/// <summary> /// Converts regular User objects into FilteredUser objects. This will remove all sensitive information from them. /// </summary> /// <param name="users"></param> /// <returns></returns> private List <FilteredUser> FilterSensitiveInformation(List <User> users) { List <FilteredUser> filteredUsers = new List <FilteredUser>(users.Count); users.ForEach(x => filteredUsers.Add(FilteredUser.FromUser(x))); return(filteredUsers); }
private void ClearOldVoteIfNotMultipleChoice(Question question, FilteredUser user) { if (question.AllowMultipleVotes == false) { var oldVotes = user.Votes.Where(v => question.Responses.Any(r => r.Id == v.ResponseId)).ToList(); oldVotes.ForEach(o => Context.Votes.Remove(o)); } }
private FilteredUser ConvertFrom_Entity_To_FilteredUser(UserEf entity, FilteredUser model) { var instance = model ?? new FilteredUser(); instance.Id = entity.Id; instance.Email = entity.Email; instance.FullName = $"{entity.Name} {entity.LastName}"; return(instance); }
/// <summary> /// Gets the non-sensitive information of the user with the given id. /// </summary> /// <param name="id"></param> /// <returns></returns> private FilteredUser GetUserInformation(int id) { var user = context.Users.FirstOrDefault(u => u.Id == id); if (user != null) { return(FilteredUser.FromUser(user)); } else { throw new UserIdDoesNotExistException(); } }
private void ClearOldVotesWithMatchingResponseId(FilteredUser user, int responseId) { var oldVotes = user.Votes.Where(v => v.ResponseId == responseId).ToList(); oldVotes.ForEach(o => Context.Votes.Remove(o)); }
private FilteredUser FetchUserVotes(FilteredUser user) { var detailedUser = Context.Users.Include(u => u.Votes).ThenInclude(v => v.Response).First(u => user.Id == u.Id); return(detailedUser); }