示例#1
0
 public User GetUser(Func<User, bool> predicate)
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Users.Where(user => !user.Deleted).SingleOrDefault(predicate);
     }
 }
示例#2
0
 public IEnumerable<User> GetUsers()
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Users.Where(u => !u.Deleted);
     }
 }
示例#3
0
        public User GetCurrentUser()
        {
            if (HttpContext.Current.User == null)
            {
                var user = new User {RoleId = (int) Role.None};

                return user;
            }

            var identity = HttpContext.Current.User.Identity;

            if (!identity.IsAuthenticated)
            {
                return null;
            }

            using (var db = new UserManagementDBContext())
            {
                return db.Users.Where(u => u.Username == identity.Name).FirstOrDefault();
            }
        }
示例#4
0
        public void AddUserToGroup(Group group, User user)
        {
            using (var db = new UserManagementDBContext())
            {
                db.Users.Attach(user);
                db.Groups.Attach(group);
                
                group.Users.Add(user);

                db.SaveChanges();
            }
        }
示例#5
0
        public IEnumerable<Group> GetGroupsByUser(User user)
        {
            using (var db = new UserManagementDBContext())
            {
                db.Users.Attach(user);

                return user.Groups;
            }
        }
示例#6
0
        public IEnumerable<Group> GetGroupsAvaliableForUser(User user)
        {
            using (var db = new UserManagementDBContext())
            {
                var groupRefsByUser = GetGroupsByUser(user).Select(g => g.Id);

                return db.Groups.Where(g => !groupRefsByUser.Contains(g.Id));
            }
        }
示例#7
0
        public void EditGroup(int id, Group group)
        {
            using (var db = new UserManagementDBContext())
            {
                var oldGroup = db.Groups.Single(g => g.Id == id && !g.Deleted);

                oldGroup.Name = group.Name;
                db.SaveChanges();
            }

            _LmsService.Inform(UserNotifications.GroupEdit, group);
        }
示例#8
0
        public void DeleteGroup(int id)
        {
            using (var db = new UserManagementDBContext())
            {
                var group = db.Groups.Single(g => g.Id == id && !g.Deleted);

                group.Users.Clear();
                group.Deleted = true;
                
                db.SaveChanges();

                _LmsService.Inform(UserNotifications.GroupDelete, group);
            }
        }
示例#9
0
        public void EditUser(Guid id, EditUserModel user)
        {
            using (var db = new UserManagementDBContext())
            {
                var oldUser = db.Users.Single(u => u.Id == id);

                oldUser.Name = user.Name;
                if (user.Password != null && user.Password != string.Empty)
                    oldUser.Password = EncryptPassword(user.Password);
                oldUser.Email = user.Email;
                oldUser.OpenId = user.OpenId ?? string.Empty;
                oldUser.RoleId = user.RoleId;

                db.SaveChanges();

                _LmsService.Inform(UserNotifications.UserEdit, oldUser);
            }
        }
示例#10
0
        public void CreateGroup(Group group)
        {
            using (var db = new UserManagementDBContext())
            {
                group.Deleted = false;

                db.Groups.Add(group);
                db.SaveChanges();
            }
        }
示例#11
0
        public void DeactivateUser(Guid id)
        {
            using (var db = new UserManagementDBContext())
            {
                var user = db.Users.Single(u => u.Id == id);
                user.IsApproved = false;
                user.ApprovedBy = null;

                db.SaveChanges();
            }
        }
示例#12
0
 public IEnumerable<User> GetUsers(Func<User, bool> predicate)
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Users.Where(u => !u.Deleted).Where(predicate);
     }
 }
示例#13
0
        public void RegisterUser(RegisterModel registerModel)
        {
            using (var db = new UserManagementDBContext())
            {
                var user = new User
                                {
                                    Username = registerModel.Username,
                                    Password = EncryptPassword(registerModel.Password),
                                    OpenId = registerModel.OpenId ?? string.Empty,
                                    Email = registerModel.Email,
                                    Name = registerModel.Name,
                                    Role = Role.Student,
                                    IsApproved = false,
                                    Deleted = false,
                                    CreationDate = DateTime.Now,
                                    ApprovedBy = null
                                };

                db.Users.Add(user);
                db.SaveChanges();
            }
        }
示例#14
0
        public void EditAccount(EditModel editModel)
        {
            var identity = HttpContext.Current.User.Identity;

            using (var db = new UserManagementDBContext())
            {
                var user = db.Users.Single(u => u.Username == identity.Name);

                user.Name = editModel.Name;
                user.OpenId = editModel.OpenId ?? string.Empty;
                user.Email = editModel.Email;

                db.SaveChanges();

                SendEmail("admin@iudico", user.Email, "Iudico Notification", "Your details have been changed.");
            }
        }
示例#15
0
 public IEnumerable<User> GetUsersNotInGroup(Group group)
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Users.Where(u => !u.Deleted).Except(db.Users.Where(m => m.Groups.Contains(group)));
         //return db.Users.Where(u => !u.Deleted).Except(db.GroupUsers.Where(g => g.GroupRef == group.Id).Select(g => g.User));
     }
 }
示例#16
0
 public IEnumerable<User> GetUsersInGroup(Group group)
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Users.Where(u => u.Groups.Contains(group));
         //return db.GroupUsers.Where(g => g.GroupRef == group.Id && !g.User.Deleted).Select(g => g.User);
     }
 }
示例#17
0
        public void DeleteUser(Func<User, bool> predicate)
        {
            using (var db = new UserManagementDBContext())
            {
                var user = db.Users.Where(u => !u.Deleted).Single(predicate);

                user.Deleted = true;
                user.Groups.Clear();

                db.SaveChanges();

                _LmsService.Inform(UserNotifications.UserDelete, user);
            }
        }
示例#18
0
        public void RemoveUserFromGroup(Group group, User user)
        {
            using (var db = new UserManagementDBContext())
            {
                db.Users.Attach(user);
                db.Groups.Attach(group);
                
                db.Users.Remove(user);

                db.SaveChanges();
            }
        }
示例#19
0
        public void ActivateUser(Guid id)
        {
            using (var db = new UserManagementDBContext())
            {
                var user = db.Users.Single(u => u.Id == id);
                user.IsApproved = true;
                user.ApprovedBy = GetCurrentUser().Id;

                db.SaveChanges();
            }
        }
示例#20
0
        public void ChangePassword(ChangePasswordModel changePasswordModel)
        {
            var user = GetCurrentUser();

            using (var db = new UserManagementDBContext())
            {
                user.Password = EncryptPassword(changePasswordModel.NewPassword);

                db.SaveChanges();
            }

            SendEmail("admin@iudico", user.Email, "Iudico Notification", "Your passord has been changed.");
        }
示例#21
0
        public void CreateUser(User user)
        {
            using (var db = new UserManagementDBContext())
            {
                user.Password = EncryptPassword(user.Password);
                user.OpenId = user.OpenId ?? string.Empty;
                user.Deleted = false;
                user.IsApproved = true;
                user.CreationDate = DateTime.Now;
                user.ApprovedBy = GetCurrentUser().Id;

                db.Users.Add(user);
                db.SaveChanges();
            }
            
            _LmsService.Inform(UserNotifications.UserCreate, user);
        }
示例#22
0
 public Group GetGroup(int id)
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Groups.First(group => group.Id == id && !group.Deleted);
     }
 }
示例#23
0
 public IEnumerable<Group> GetGroups()
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Groups.Where(g => !g.Deleted);
     }
 }
示例#24
0
 public IEnumerable<User> GetUsers(int pageIndex, int pageSize)
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Users.Skip(pageIndex).Take(pageSize);
     }
 }
示例#25
0
 public bool UsernameExists(string username)
 {
     using (var db = new UserManagementDBContext())
     {
         return db.Users.Count(u => u.Username == username && u.Deleted == false) > 0;
     }
 }