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; }
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; }
public ResultBase RolesPut(UserDetails user) { return Service.RolesPut(user); }
public ResultBase PwdPut(UserDetails user) { return Service.PwdPut(user); }
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; }
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; }