public async Task <ActionResult> ChangeUserRole(long groupId, long userId, GroupUser groupUser) { GroupUser currentUser = await repository.GetGroupUser(groupId, CurrentUserId); GroupUser adjustedUser = await repository.GetGroupUser(groupId, userId); Role role = currentUser.Role; if (role == Role.user || role == Role.creator) { return(Unauthorized("Must be a group admin or owner to adjust other user's roles.")); } if (role == Role.admin && (adjustedUser.Role == Role.admin || adjustedUser.Role == Role.owner)) { return(Unauthorized("Admins cannot change the role of other admins.")); } bool didDelete = await groupRepo.RemoveUserAsync(currentUser, adjustedUser); if (!didDelete) { return(Unauthorized("That user does not currently exist in this group. Something must have gone wrong. We're working on it.")); } await groupRepo.AddUserAsync(groupId, adjustedUser.User.UserName, groupUser.Role); return(Ok()); }
public async Task <IEnumerable <GroupEventDto> > GetAllCalendar(Repeat repeat, long groupId, long userId) { List <GroupEventDto> events = new List <GroupEventDto>(); GroupUser groupUser = await guRepo.GetGroupUser(groupId, userId); List <GroupEventDto> groupEvents = FindAllGroupEvents(groupId, userId, groupUser).ToList(); events.AddRange( groupEvents.Where(ge => ge.ERepeat == repeat) ); return(events); }
public async Task <GroupDto> GetGroup(long id) { GroupUser currentUser = await guRepo.GetGroupUser(id, UserId); long userId = UserId; return(repository.Find(id, userId, currentUser)); }