예제 #1
0
 /// <summary>
 /// 保存用户信息
 /// </summary>
 /// <param name="user"></param>
 public int SaveAccountInfo(T_AdminUser user, string newPwz)
 {
     if (user.id.Equals(Guid.Empty))
     {
         user.id = Guid.NewGuid();
         using (var dbContext = new IPathDBEntities())
         {
             user.Pwz = AESHelper.Encrypt(user.Pwz);
             dbContext.T_AdminUser.Add(user);
             return(dbContext.SaveChanges());
         }
     }
     else
     {
         using (var dbContext = new IPathDBEntities())
         {
             dbContext.T_AdminUser.Attach(user);
             dbContext.Entry(user).Property("UserName").IsModified       = true;
             dbContext.Entry(user).Property("PermissionInfo").IsModified = true;
             if (!string.IsNullOrEmpty(newPwz))
             {
                 user.Pwz = AESHelper.Encrypt(newPwz);
                 dbContext.Entry(user).Property("Pwz").IsModified = true;
             }
             dbContext.Configuration.ValidateOnSaveEnabled = false;
             return(dbContext.SaveChanges());
         }
     }
 }
예제 #2
0
        /// <summary>
        /// 根据id删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Remove(string id)
        {
            Guid _id = new Guid(id);

            using (var dbContext = new IPathDBEntities())
            {
                var entity = new T_AdminUser()
                {
                    id = _id
                };
                dbContext.T_AdminUser.Attach(entity);
                dbContext.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
                return(dbContext.SaveChanges());
            }
        }