public GroupRoles GetUserRoleInGroup(int userId, int groupId) { if (dbContext.ReaderProfiles.Any(p => p.GroupId == groupId && p.UserId == userId)) { ReaderProfile profile = dbContext.ReaderProfiles.Where(p => p.GroupId == groupId && p.UserId == userId) .First(); GroupRole role = dbContext.GroupRoles.Where(r => r.Id == profile.GroupRoleId).First(); if (role.Title == GroupRoles.Admin.ToString()) { return(GroupRoles.Admin); } else if (role.Title == GroupRoles.Moder.ToString()) { return(GroupRoles.Moder); } else { return(GroupRoles.Reader); } } else { return(GroupRoles.Reader); } }
public void Subscribe(int groupId, int userId, GroupRoles role) { GroupRole groupRole = dbContext.GroupRoles.Where(r => r.Title == role.ToString()).First(); ReaderProfileState state = dbContext.ReaderProfileStates .Where(s => s.Title == ReaderProfileStates.FullAccess.ToString()).First(); ReaderProfile profile = new ReaderProfile() { GroupId = groupId, UserId = userId, GroupRoleId = groupRole.Id, ReaderProfileStateId = state.Id }; dbContext.ReaderProfiles.Add(profile); dbContext.SaveChanges(); }