コード例 #1
0
        public M_UserInfo GetUser()
        {
            int uid = DataConvert.CLng(Uids.Replace("\"", "").Replace(" ", "").Split(',')[0]);

            return(buser.SelReturnModel(uid));
        }
コード例 #2
0
        /*******Begin code to modify********/

        /// <summary>
        /// Create a new user of the LMS with the specified information.
        /// Assigns the user a unique uID consisting of a 'u' followed by 7 digits.
        /// </summary>
        /// <param name="fName">First Name</param>
        /// <param name="lName">Last Name</param>
        /// <param name="DOB">Date of Birth</param>
        /// <param name="SubjectAbbrev">The department the user belongs to (professors and students only)</param>
        /// <param name="role">The user's role: one of "Administrator", "Professor", "Student"</param>
        /// <returns>A unique uID that is not be used by anyone else</returns>
        public string CreateNewUser(string fName, string lName, DateTime DOB, string SubjectAbbrev, string role)
        {
            // TODO: Implement
            UInt32 lastUID = 0;

            var prevUID =
                (from id in db.Uids
                 orderby id.UId
                 descending
                 select id.UId).FirstOrDefault();

            lastUID = UInt32.Parse(prevUID.Substring(1));
            UInt32 nextUID = lastUID + 1;
            string ret     = "u" + nextUID.ToString("D7");
            Uids   u       = new Uids();

            u.UId  = ret;
            u.Type = role;
            db.Uids.Add(u);
            if (role == "Administrator")
            {
                Administrators a = new Administrators();
                a.UId   = ret;
                a.First = fName;
                a.Last  = lName;
                a.Dob   = DOB;
                db.Administrators.Add(a);
            }

            else if (role == "Student")
            {
                var dept =
                    from d in db.Departments
                    where d.Abbr == SubjectAbbrev
                    select d;
                Students s = new Students();
                s.UId             = ret;
                s.First           = fName;
                s.Last            = lName;
                s.Dob             = DOB;
                s.Major           = SubjectAbbrev;
                s.MajorNavigation = dept.SingleOrDefault();
                db.Students.Add(s);
            }

            else if (role == "Professor")
            {
                var dept =
                    from d in db.Departments
                    where d.Abbr == SubjectAbbrev
                    select d;
                Professors p = new Professors();
                p.UId             = ret;
                p.First           = fName;
                p.Last            = lName;
                p.Dob             = DOB;
                p.Major           = SubjectAbbrev;
                p.MajorNavigation = dept.SingleOrDefault();
                db.Professors.Add(p);
            }

            try
            {
                db.SaveChanges();
                return(ret);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return("");
            }
        }