public GroupModel FormGroupModel(int groupId, string email) { GroupDescription group = _groupRepo.GetElement(groupId); // Информация о текущей группе if (group == null) { return(null); } UserDescription user = _userRepo.GetElementByEmail(email); var part = _participationRepo.GetElement(user.Id, groupId); string role = null; if (part == null && !group.Private) { _participationRepo.Create(new Participation { UserId = user.Id, GroupId = groupId, Role = 0 }); _participationRepo.Save(); role = _roleRepo.GetElement(0).Name; } else { role = _roleRepo.GetElement(part.Role).Name; } List <RequestList> requests = _requestListRepo.GetElementsForGroup(groupId); // Список заявок в текущую группу List <UserDescription> requested_users = new List <UserDescription>(); // Пользователи подавшие заявку for (int i = 0; i < requests.Count(); i++) { requested_users.Add(_userRepo.GetElement(requests[i].UserId)); } List <Participation> users_ids = _participationRepo.GetUsersForGroup(groupId); // список id участников текущей группы List <UserDescription> users = new List <UserDescription>(); // участники текущей группы for (int i = 0; i < users_ids.Count(); i++) { users.Add(_userRepo.GetElement(users_ids[i].UserId)); users[i].Role = _roleRepo.GetElement(_participationRepo.GetElement(users[i].Id, groupId).Role).Name; } List <Files> files = _filesRepo.GetFilesForGroup(groupId); // загруженные материалы текущей группы return(new GroupModel { Id = group.Id, Name = group.Name, requests = requested_users, members = users, files = files, Private = group.Private, Role = role }); }
public ClaimsPrincipal Authenticate(string email) { UserDescription user = _userRepo.GetElementByEmail(email); var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, user.Email), new Claim(ClaimsIdentity.DefaultRoleClaimType, user.Role) }; ClaimsIdentity id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); return(new ClaimsPrincipal(id)); }
public HomeGroupsViewModel FormHomeModel(string email) { var part = _participation.GetAll(); var user = _userDescription.GetElementByEmail(email); var groups = _groupDescription.GetAll(); List <KeyValuePair <bool, bool> > valuePair = new List <KeyValuePair <bool, bool> >(); bool isUserAlreadyExistInGroup = false; bool isUserAwaitsClaim = false; if (user is null) { return(new HomeGroupsViewModel(user, groups, valuePair)); } for (int gr = 0; gr < groups.Count(); gr++) { if (_participation.GetParticipationByUserAndGroup(user.Id, groups.ElementAt(gr).Id) != null) { isUserAwaitsClaim = false; isUserAlreadyExistInGroup = true; } else { var rq = _requestList.GetRequestByUserAndGroup(user.Id, groups.ElementAt(gr).Id); if (rq != null) { if (rq.IsAwaiting == true) { isUserAlreadyExistInGroup = false; isUserAwaitsClaim = true; } else { isUserAlreadyExistInGroup = false; isUserAwaitsClaim = false; } } else { isUserAlreadyExistInGroup = false; isUserAwaitsClaim = false; } } valuePair.Add(new KeyValuePair <bool, bool>(isUserAlreadyExistInGroup, isUserAwaitsClaim)); } return(new HomeGroupsViewModel(user, groups, valuePair)); }