Beispiel #1
0
 public Dictionary <string, object> add([FromBody] sysUser user)
 {
     user.Valid(message, db);
     if (message.Count == 0)
     {
         user.Password   = Ricky.Common.EncryptString(user.Password);
         user.CreateTime = Ricky.Common.NowDate;
         db.sysUsers.Add(user);
         db.SaveChanges();
         foreach (int RoleId in user.RoleIds)
         {
             sysUserInRole userRole = new sysUserInRole();
             userRole.RoleId = RoleId;
             userRole.UserId = user.UserId;
             db.sysUserInRoles.Add(userRole);
         }
         foreach (int EstateId in user.EstateIds)
         {
             sysUserInEstate userEstate = new sysUserInEstate();
             userEstate.EstateId = EstateId;
             userEstate.UserId   = user.UserId;
             db.sysUserInEstates.Add(userEstate);
         }
         db.SaveChanges();
     }
     else
     {
         result["code"] = "failed";
     }
     result["message"] = message;
     return(result);
 }
Beispiel #2
0
 public Dictionary <string, object> modify([FromBody] sysUser user)
 {
     user.Valid(message, db, false);
     if (message.Count == 0)
     {
         sysUser newUser = db.sysUsers.FirstOrDefault(w => w.UserId == user.UserId);
         if (!user.LoginName.Equals(newUser.LoginName) && db.sysUsers.Count(w => w.LoginName == user.LoginName) > 0)
         {
             message.Add("账户名称已存在");
         }
         else
         {
             Ricky.ObjectCopy.Copy <sysUser>(user, newUser, new string[] { "Password", "CreateTime", "IsSuper", "LastLoginIp", "LastLoginTime", "Status" });
             if (!string.IsNullOrEmpty(user.Password))
             {
                 newUser.Password = Ricky.Common.EncryptString(user.Password);
             }
             var a = from b in db.sysUserInRoles where b.UserId == user.UserId select b;
             db.sysUserInRoles.RemoveRange(a);
             var userOldEsates = from b in db.sysUserInEstates where b.UserId == user.UserId select b;
             db.sysUserInEstates.RemoveRange(userOldEsates);
             db.SaveChanges();
             foreach (int RoleId in user.RoleIds)
             {
                 sysUserInRole userRole = new sysUserInRole();
                 userRole.RoleId = RoleId;
                 userRole.UserId = user.UserId;
                 db.sysUserInRoles.Add(userRole);
             }
             foreach (int EstateId in user.EstateIds)
             {
                 sysUserInEstate userEstate = new sysUserInEstate();
                 userEstate.EstateId = EstateId;
                 userEstate.UserId   = user.UserId;
                 db.sysUserInEstates.Add(userEstate);
             }
             db.SaveChanges();
         }
     }
     else
     {
         result["code"] = "failed";
     }
     result["message"] = message;
     return(result);
 }