コード例 #1
0
 public PutResult Put(UserDetails user)
 {
     var result = GetDefault<PutResult>();
     var model = DbEntities.Users.FirstOrDefault(x => x.Id == user.Id);
     if (isHas(user.Name, user.Id))
     {
         result.Message = string.Format("当前用户名“{0}”在数据库中已经存在", user.Name);
         return result;
     }
     if (model == null)
     {
         result.Message = string.Format("当前编辑的用户“{0}”已经不存在", user.Name);
         return result;
     }
     model.isVerify = user.IsVerify;
     model.Email = user.Email;
     DbEntities.SaveChanges();
     result.isSaved = true;
     return result;
 }
コード例 #2
0
 public PostResult<int> Post(UserDetails user)
 {
     var result = GetDefault<PostResult<int>>();
     if (isHas(user.Name, user.Id))
     {
         result.Message = string.Format("当前用户名“{0}”在数据库中已经存在", user.Name);
         return result;
     }
     var model = new User()
     {
         CreateTime = DateTime.Now,
         Password = user.Password,
         Email = user.Email,
         isVerify = user.IsVerify,
         Name = user.Name
     };
     DbEntities.Users.Add(model);
     DbEntities.SaveChanges();
     result.Id = model.Id;
     result.isCreated = true;
     return result;
 }
コード例 #3
0
 public ResultBase RolesPut(UserDetails user)
 {
     return Service.RolesPut(user);
 }
コード例 #4
0
 public ResultBase PwdPut(UserDetails user)
 {
     return Service.PwdPut(user);
 }
コード例 #5
0
        public PutResult RolesPut(UserDetails user)
        {
            var result = GetDefault<PutResult>();
            var model = DbEntities.Users.FirstOrDefault(x => x.Id == user.Id);
            if (model == null)
            {
                result.Message = string.Format("当前编辑的用户“{0}”已经不存在", user.Name);
                return result;
            }

            var list = model.UserToUserRoles.ToList();
            DbEntities.UserToUserRoles.RemoveRange(list.Where(x => !user.Roles.Exists(z => z.Id == x.UserRoleId)));
            var appends = user.Roles.Where(x => !list.Exists(z => z.UserRoleId == x.Id));
            DbEntities.UserToUserRoles.AddRange(appends.Select(x => new UserToUserRole()
            {
                UserId = user.Id,
                UserRoleId = x.Id
            }));
            DbEntities.SaveChanges();
            result.isSaved = true;
            return result;
        }
コード例 #6
0
 public PutResult PwdPut(UserDetails user)
 {
     var result = GetDefault<PutResult>();
     var model = DbEntities.Users.FirstOrDefault(x => x.Id == user.Id);
     if (model == null)
     {
         result.Message = string.Format("当前编辑的用户“{0}”已经不存在", user.Name);
         return result;
     }
     model.Password = user.Password;
     DbEntities.SaveChanges();
     result.isSaved = true;
     return result;
 }