コード例 #1
0
 public DalUser Create(DalUser e)
 {
     if (UserExists(e.Name))
         return null;
     var user = e.ToOrmUser();
     
     var temproles = user.Roles;
     user.Roles.Clear();
     foreach (var role in temproles)
     {
         user.Roles.Add(context.Set<Role>().First(x => x.Id == role.Id));
     }
     user = context.Set<User>().Add(user);
     return user.ToDalUser();
 }
コード例 #2
0
        public void Delete(DalUser e)
        {
            var user = e.ToOrmUser();
            user = context.Set<User>().FirstOrDefault(u => u.Id == user.Id);
            if (user != null)
            {
                while (user.Publications != null && user.Publications.Any())
                {
                    context.Set<Content>().Remove(user.Publications.First());
                }
                while (user.Comments != null && user.Comments.Any())
                {
                    context.Set<Comment>().Remove(user.Comments.First());
                }
                context.Set<User>().Remove(user);
            }

        }
コード例 #3
0
        public void Update(DalUser entity)
        {
            var original = context.Set<User>().FirstOrDefault(u => u.Id == entity.Id);
            if (original != null)
            {
                var updatedUser = entity.ToOrmUser();

                if (updatedUser.Name != null)
                    original.Name = updatedUser.Name;
                if (updatedUser.Password != null)
                    original.Password = updatedUser.Password;
                original.Roles.Clear();
                foreach (var role in updatedUser.Roles)
                {
                    original.Roles.Add(context.Set<Role>().First(x => x.Id == role.Id));
                }
            }
        }
コード例 #4
0
 public void Delete(DalUser e)
 {
     var user = e.ToOrmUser();
     user = _context.Set<UserLogin>().Single(u => u.Id == user.Id);
     _context.Set<UserLogin>().Remove(user);
 }
コード例 #5
0
 public void Create(DalUser e)
 {
     
     _context.Set<UserLogin>().Add(e.ToOrmUser());
 }
コード例 #6
0
 public void Create(DalUser user)
 {
     if (user == null)
         throw new ArgumentNullException(nameof(user));
     context.Set<User>().Add(user.ToOrmUser());
 }