Beispiel #1
0
 public static long GetUserId(SPUser user)
 {
     if (user == null)
     {
         return(0);
     }
     else
     {
         string name = user.LoginName;
         //检查用户
         List <ProjectDll.User> dt = DAL.User.GetUserByAccount(name.Substring(name.LastIndexOf("\\") + 1));
         if (dt.Count == 0)
         {
             ProjectDll.User dr = new ProjectDll.User();
             dr.Account = user.LoginName.Split('\\')[1];
             dr.Name    = user.Name;
             dr.Flag    = 1;
             return(DAL.User.InsertUser(dr));
         }
         else
         {
             return(dt[0].UserID);
         }
     }
 }
Beispiel #2
0
 public static ProjectDll.User GetUserByUserID(long userID)
 {
     using (ProjectEntities db = new ProjectEntities())
     {
         ProjectDll.User atList = db.User.SingleOrDefault(at => at.UserID == userID);
         return(atList);
     }
 }
Beispiel #3
0
        /// <summary>
        /// 获取当前用户ID,如果数据库中没有数据,根据活动目录写入数据库中
        /// </summary>
        /// <returns>mUser.UserID</returns>
        public static long GetUserId()
        {
            string account = GetAccount();
            var    db      = new ProjectEntities();//定义数据库连接接口

            ProjectDll.User mUser = db.User.FirstOrDefault(u => u.Account.Equals(account));
            if (mUser != null)
            {
                return(mUser.UserID);
            }
            else
            {
                mUser         = new ProjectDll.User();
                mUser.Account = account;
                mUser.Created = DateTime.Now;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    DirectoryEntry adUser = AdHelper.GetDirectoryEntryByAccount(account);
                    if (adUser != null)
                    {
                        mUser.Name = adUser.Properties["displayName"][0].ToString();
                        if (adUser.Properties.Contains("telephoneNumber"))
                        {
                            mUser.Telephone = adUser.Properties["telephoneNumber"][0].ToString();
                        }
                        if (adUser.Properties.Contains("mail"))
                        {
                            mUser.Email = adUser.Properties["mail"][0].ToString();
                        }
                    }
                });
                db.User.Add(mUser);
                db.SaveChanges();
                return(mUser.UserID);
            }
        }
Beispiel #4
0
        //public static long InsertWorksExpert(ProjectEntities db,WorksExpert dr)
        //{
        //        ProjectDll.WorksExpert at = new WorksExpert();
        //        at.Comments = dr.Comments;
        //        at.Created = dr.Created;
        //        at.ExpertID = dr.ExpertID;
        //        at.Flag = 1;
        //        at.Score = dr.Score;
        //        at.ScoreState = dr.ScoreState;
        //        at.WorksID = dr.WorksID;
        //        db.WorksExpert.Add(at);
        //        db.SaveChanges();
        //        return at.WorksExpertID;
        //}
        //public static long InsertWorksExpert(WorksExpert  dr)
        //{
        //    using (ProjectEntities db = new ProjectEntities())
        //    {
        //        ProjectDll.WorksExpert at = new WorksExpert();
        //        at.Comments = dr.Comments;
        //        at.Created = dr.Created;
        //        at.ExpertID = dr.ExpertID;
        //        at.Flag = 1;
        //        at.Score = dr.Score;
        //        at.ScoreState = dr.ScoreState;
        //        at.WorksID = dr.WorksID;
        //        db.WorksExpert.Add(at);
        //        db.SaveChanges();
        //        return at.WorksExpertID;
        //    }
        //}


        /// <summary>
        /// 创建新用户
        /// </summary>
        /// <param name="dr">用户记录</param>
        /// <returns></returns>
        public static long InsertUser(ProjectDll.User dr)
        {
            using (ProjectEntities db = new ProjectEntities())
            {
                ProjectDll.User at = new ProjectDll.User();
                at.Account    = dr.Account;
                at.Department = dr.Department;
                at.Duty       = dr.Duty;
                at.Email      = dr.Email;
                at.Department = dr.Department;
                at.Telephone  = dr.Telephone;
                at.IDCard     = dr.IDCard;
                at.Name       = dr.Name;
                at.SchoolID   = dr.SchoolID;
                at.Major      = dr.Major;
                at.RoleID     = dr.RoleID;
                at.Sex        = dr.Sex;
                at.StateID    = dr.StateID;
                at.Created    = DateTime.Now;
                db.User.Add(at);
                db.SaveChanges();
                return(at.UserID);
            }
        }