예제 #1
0
        public User UpdateUser(User user)
        {
            var dbUser = _unitOfWork.Users.GetById(user.Id);
            if (dbUser == null)
                throw new DataException(string.Format("User with id {0} could not be found.", user.Id));

            dbUser.IsActive = user.IsActive;
            dbUser.UserName = user.UserName;

            dbUser.Roles.Clear();

            foreach (var dbRole in user.Roles.Select(role => _unitOfWork.Roles.GetById(role.Id)))
            {
                dbUser.Roles.Add(dbRole);
            }

            dbUser = _unitOfWork.Users.Update(dbUser);
            _unitOfWork.Commit();

            return dbUser.ToModel();
        }
예제 #2
0
 public Session(int id, Guid sessionId, User user)
     : base(id)
 {
     SessionId = sessionId;
     User = user;
 }