Beispiel #1
0
        protected Team63LMSContext AddProfessor2()
        {
            Team63LMSContext db = mockDB();

            Professors p = new Professors();

            p.FName   = "Ron";
            p.LName   = "Weasley";
            p.UId     = uIDGen(db);
            p.WorksIn = "EE";
            p.Dob     = new DateTime(1994, 09, 22);

            db.Professors.Add(p);
            db.SaveChanges();

            Professors p2 = new Professors();

            p2.FName   = "Kanny";
            p2.LName   = "Dopta";
            p2.UId     = uIDGen(db);
            p2.WorksIn = "EE";
            p2.Dob     = new DateTime(1992, 10, 23);

            db.Professors.Add(p2);
            db.SaveChanges();

            return(db);
        }
Beispiel #2
0
        protected Team63LMSContext AddProfessorCourseClass()
        {
            Team63LMSContext db = mockDB();

            AdministratorController controller = new AdministratorController();

            controller.UseLMSContext(db);

            // Create Professor to teach class
            Professors p = new Professors();

            p.FName   = "Danny";
            p.LName   = "Kopta";
            p.UId     = uIDGen(db);
            p.WorksIn = "CS";

            db.Professors.Add(p);
            db.SaveChanges();

            controller.CreateCourse("CS", 5530, "Database Systems");

            controller.CreateClass("CS", 1, "Spring", 2019, new DateTime(2009, 05, 30, 7, 9, 16),
                                   new DateTime(2009, 05, 30, 9, 16, 25), "WEB 1250", "u0000000");

            return(db);
        }
Beispiel #3
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="SubjectAbbrev">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)
        {
            using (Team6LMSContext db = new Team6LMSContext())
            {
                var    query2 = from a in db.Users select a.UId;
                bool   cond   = true;
                string uid    = string.Empty;
                while (true)
                {
                    var random = new Random();
                    uid = "u";
                    for (int i = 0; i < 7; i++)
                    {
                        uid = String.Concat(uid, random.Next(10).ToString());
                    }

                    foreach (string U in query2)
                    {
                        if (U.Equals(uid))
                        {
                            cond = false;
                        }
                    }
                    if (cond)
                    {
                        Users newUser = new Users();
                        newUser.UId   = uid;
                        newUser.FName = fName;
                        newUser.LName = lName;
                        newUser.Dob   = DOB;
                        db.Users.Add(newUser);

                        if (role.Equals("Professor"))
                        {
                            Professors prof = new Professors();
                            prof.UId     = uid;
                            prof.Subject = SubjectAbbrev;
                            db.Professors.Add(prof);
                        }
                        else if (role.Equals("Student"))
                        {
                            Students stu = new Students();
                            stu.UId     = uid;
                            stu.Subject = SubjectAbbrev;
                            db.Students.Add(stu);
                        }
                        else
                        {
                            Administrators adm = new Administrators();
                            adm.UId = uid;
                            db.Administrators.Add(adm);
                        }
                        db.SaveChanges();
                        break;
                    }
                }

                return(uid);
            }
        }
        private void Add_Prof_Click(object sender, RoutedEventArgs e)
        {
            AddProfessorDialog addProfDialog = new AddProfessorDialog();

            addProfDialog.Owner = this;
            addProfDialog.ShowDialog();

            ProfessorList professors = (ProfessorList)Application.Current.Resources["Professor_List_View"];

            if ((bool)Application.Current.Resources["Set_Prof_Success"])
            {
                // Get data about new professor
                string fName       = (string)Application.Current.Resources["Set_Prof_FN"];
                string lName       = (string)Application.Current.Resources["Set_Prof_LN"];
                string id          = (string)Application.Current.Resources["Set_Prof_ID"];
                string colorString = (string)Application.Current.Resources["Set_Prof_Color"];
                // Create new professor object and add to professor list
                Professors prof = new Professors(fName, lName, id);
                prof.profRGB = new RGB_Color(colorString);
                professors.Add(prof);
                // Set the new professor as the comboBox selected value
                Prof_Text.SelectedIndex = (professors.Count - 1);
                // Reset Success flag for the addProfessorDialog
                Application.Current.Resources["Set_Prof_Success"] = false;
            }
        }
        /*******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="SubjectAbbrev">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)
        {
            string uID = "";

            using (Team9LMSContext db = new Team9LMSContext())
            {
                Users newUser = new Users
                {
                    FirstName = fName,
                    LastName  = lName,
                    Dob       = DOB
                };

                db.Users.Add(newUser);
                db.SaveChanges();

                var query = from u in db.Users
                            where u.FirstName == fName && u.LastName == lName
                            select new { uID = u.UId };

                foreach (var q in query)
                {
                    string[] sList = Convert.ToString(q.uID).Split(" ");
                    uID = sList[0];
                }

                if (role == "Administrator")
                {
                    Administrators newAd = new Administrators
                    {
                        UId = uID
                    };
                    db.Administrators.Add(newAd);
                    db.SaveChanges();
                }

                if (role == "Professor")
                {
                    Professors newPro = new Professors
                    {
                        UId     = uID,
                        Subject = SubjectAbbrev
                    };
                    db.Professors.Add(newPro);
                    db.SaveChanges();
                }

                if (role == "Student")
                {
                    Students newStu = new Students
                    {
                        UId     = uID,
                        Subject = SubjectAbbrev
                    };
                    db.Students.Add(newStu);
                    db.SaveChanges();
                }
            }
            return(uID);
        }
Beispiel #6
0
        public void Filter()
        {
            if (searchName == null)
            {
                searchName = string.Empty;
            }

            var result = ProfessorsLocal.Where(p => p.Name.ToLowerInvariant().Contains(SearchName.ToLowerInvariant()))
                         .ToList();

            if (result != null)
            {
                var remove = Professors.Except(result).ToList();

                remove.ForEach(r =>
                {
                    Professors.Remove(r);
                });
            }

            for (int index = 0; index < result.Count; index++)
            {
                var item = result[index];
                if (index + 1 > Professors.Count || !Professors[index].Equals(item))
                {
                    Professors.Insert(index, item);
                }
            }
        }
        /*******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="SubjectAbbrev">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)
        {
            string userID = "";

            var query = db.Students.Select(s => new { s.UId }).Union(db.Professors.Select(p => new { p.UId })).Union(db.Administrators.Select(a => new { a.UId })).OrderByDescending(u => u.UId).Take(1);
            var b     = query.ToArray();

            if (b.Length == 1)
            {
                int i = Int32.Parse(b[0].UId.TrimStart('u'));
                i++;

                userID = "u" + i.ToString();
            }
            else
            {
                userID = "u1000000";
            }


            if (role == "Student")
            {
                Students st = new Students();
                st.FirstName = fName;
                st.LastName  = lName;
                st.Dob       = DOB;
                st.Major     = SubjectAbbrev;
                st.UId       = userID;
                db.Students.Add(st);
                db.SaveChanges();
            }

            else if (role == "Professor")
            {
                Professors p = new Professors();
                p.FirstName = fName;
                p.LastName  = lName;
                p.Dob       = DOB;
                p.Dept      = SubjectAbbrev;
                p.UId       = userID;
                db.Professors.Add(p);
                db.SaveChanges();
            }

            else if (role == "Administrator")
            {
                Administrators p = new Administrators();
                p.FirstName = fName;
                p.LastName  = lName;
                p.Dob       = DOB;
                p.UId       = userID;
                db.Administrators.Add(p);
                db.SaveChanges();
            }



            return(userID.ToString());
        }
Beispiel #8
0
 public Task HandleAsync(DepartmentProfessor message, CancellationToken cancellationToken)
 {
     if (message != null)
     {
         Task.Run(() => Professors.AddRange(_departmentRepository.GetProfessors(message)));
     }
     return(Task.CompletedTask);
 }
Beispiel #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            Professors professors = db.Professors.Find(id);

            db.Professors.Remove(professors);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task OnDeleteProfessor(Professor professor)
        {
            var result = await _confirmationDialogHelper.ConfirmationWindowCall(ElementType.Professor);

            if (result)
            {
                Professors.Remove(professor);
                _professorRepository.DeleteProfessor(professor);
            }
        }
Beispiel #11
0
 public ActionResult Edit([Bind(Include = "ProfessorID,FirstName,LastName")] Professors professors)
 {
     if (ModelState.IsValid)
     {
         db.Entry(professors).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(professors));
 }
Beispiel #12
0
        public EditClassDialog(Classes _class)
        {
            InitializeComponent();
            Application.Current.Resources["Set_Class_Success"] = false;
            Application.Current.Resources["Edit_Class_Check"]  = false;
            targetClass      = _class;
            originalCRN      = _class.CRN;
            originalOnline   = _class.Online;
            originalAssigned = _class.isAssigned;
            ProfessorList profs = (ProfessorList)Application.Current.FindResource("Professor_List_View");

            Prof_Text.ItemsSource = profs;

            oldProfessor = _class.Prof;

            // Initialize fields with available data from class
            Classes c1 = _class;

            CRN_Text.Text      = _class.CRN.ToString();
            Dept_Text.Text     = _class.DeptName;
            ClassNum_Text.Text = _class.ClassNumber.ToString();
            Section_Text.Text  = _class.SectionNumber.ToString();
            Name_Text.Text     = _class.ClassName;
            Credits_Text.Text  = _class.Credits.ToString();
            int profIndex;

            for (profIndex = 0; profIndex < profs.Count; profIndex++)
            {
                if (profs[profIndex].FullName == _class.Prof.FullName)
                {
                    break;
                }
            }
            Prof_Text.SelectedIndex = profIndex;
            if (_class.Online)
            {
                Online_Box.IsChecked = true;
            }
            else if (_class.isAppointment)
            {
                if (_class.Classroom.Location == "APPT")
                {
                    Appointment_Box.IsChecked = true;
                }
                else
                {
                    Appointment2_Box.IsChecked = true;
                }
            }
            else
            {
                InClass_Box.IsChecked = true;
            }
            //MessageBox.Show("excludeCredits: " + _class.excludeCredits);
        }
Beispiel #13
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="SubjectAbbrev">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)
        {
            Users last = db.Users.LastOrDefault();
            //System.Diagnostics.Debug.WriteLine(last.UId);
            string newUID = "";

            if (last == null)
            {
                newUID = "u2000010";
            }
            else
            {
                string lastUID  = last.UId.Replace("u", string.Empty);
                int    newValue = Int32.Parse(lastUID) + 1;
                newUID = "u" + newValue.ToString();
            }

            Users u = new Users();

            u.UId   = newUID;
            u.FName = fName;
            u.LName = lName;
            u.Dob   = DOB;
            db.Users.Add(u);
            db.SaveChanges();

            if (role == "Administrator")
            {
                System.Diagnostics.Debug.WriteLine("ad");
                Administrators a = new Administrators();
                a.UId = newUID;
                db.Administrators.Add(a);
                db.SaveChanges();
            }
            else if (role == "Professor")
            {
                System.Diagnostics.Debug.WriteLine("pro");
                Professors p = new Professors();
                p.UId        = newUID;
                p.Department = SubjectAbbrev;
                db.Professors.Add(p);
                db.SaveChanges();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("stu");
                Students s = new Students();
                s.UId        = newUID;
                s.Department = SubjectAbbrev;     //SHOULD THIS BE CHANGED??
                db.Students.Add(s);
                db.SaveChanges();
            }

            return(u.UId);
        }
Beispiel #14
0
        public IHttpActionResult CreateProfessors(Professors professors)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _context.Professors.Add(professors);
            _context.SaveChanges();
            return(Created(new Uri(Request.RequestUri + "/" + professors.id), professors));
        }
Beispiel #15
0
        public ActionResult Create([Bind(Include = "ProfessorID,FirstName,LastName")] Professors professors)
        {
            if (ModelState.IsValid)
            {
                db.Professors.Add(professors);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(professors));
        }
Beispiel #16
0
        public ProfessorController(DataContext context, UserManager <IdentityUser> userManager, IHttpContextAccessor httpContextAccessor)
        {
            _context             = context;
            _httpContextAccessor = httpContextAccessor;
            _userManager         = userManager;
            ClaimsPrincipal currentuser = this.User;
            //.Identity.IsAuthenticated
            var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            //var userId = _userManager.GetUserId(currentuser);
            professor = _context.Professors.Include(std => std.IdUserNavigation).Where(std => std.IdUser == userId).FirstOrDefault();
        }
        public async Task OnSearchProfessor()
        {
            if (String.IsNullOrEmpty(ProfessorSearch) || String.IsNullOrWhiteSpace(ProfessorSearch))
            {
                await _confirmationDialogHelper.ErrorWindowShow("Veuillez remplir le champ de recherche.");
            }
            else
            {
                var profdep = _departmentRepository.GetDepartments();
                Professors.Clear();
                if (firstNameOrLastName.IsMatch(ProfessorSearch))
                {
                    for (int i = 0; i < GetProfessors.Count; i++)
                    {
                        if (GetProfessors[i].FirstName.ToLower().Contains(ProfessorSearch.ToLower()) || GetProfessors[i].LastName.ToLower().Contains(ProfessorSearch.ToLower()))
                        {
                            Professors.Add(GetProfessors[i]);
                        }
                        else if (GetProfessors[i].Diplome.ToString() == ProfessorSearch)
                        {
                            Professors.Add(GetProfessors[i]);
                        }
                    }
                }
                else if (fullNameRx.IsMatch(ProfessorSearch))
                {
                    var word      = ProfessorSearch.Split(' ');
                    var countWord = word.Length;

                    foreach (var prof in GetProfessors)
                    {
                        int i        = 0;
                        var fullname = prof.FirstName + " " + prof.LastName;
                        do
                        {
                            if (fullname.ToLower().Contains((word[i]).ToLower()))
                            {
                                if (i == countWord - 1)
                                {
                                    Professors.Add(prof);
                                }
                                i++;
                            }
                            else
                            {
                                break;
                            }
                        } while (i < countWord);
                    }
                }
            }
        }
        protected override Task OnInitializeAsync(CancellationToken cancellationToken)
        {
            var professor           = _professorRepository.GetProfessors();
            var professorDepartment = _professorRepository.GetProfessorDepartments();

            Task.Run(() =>
            {
                Professors.AddRange(professor);
                GetProfessors.AddRange(professor);
                GetProfessorDepartments.AddRange(professorDepartment);
            });
            return(base.OnInitializeAsync(cancellationToken));
        }
Beispiel #19
0
        // GET: Professors/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Professors professors = db.Professors.Find(id);

            if (professors == null)
            {
                return(HttpNotFound());
            }
            return(View(professors));
        }
Beispiel #20
0
        public static string AddOneProfessor(Team41LMSContext db)
        {
            var departments = new List <Departments>(db.Departments);
            var newUser     = new Professors {
                FirstName         = "Brian",
                LastName          = "Landes",
                UId               = "u000006",
                WorksIn           = departments[0].Name,
                WorksInNavigation = departments[0]
            };

            db.Professors.Add(newUser);
            db.SaveChanges();
            return("u000006");
        }
        /*******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="SubjectAbbrev">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)
        {
            using (Team31LMSContext dab = new Team31LMSContext())
            {
                Users u = new Users();

                u.FirstName = fName;
                u.LastName  = lName;
                u.Dob       = DOB;
                u.UId       = getNewUid();
                dab.Users.Add(u);
                switch (role)
                {
                case "Student":
                    Students s = new Students();
                    s.Dob = u.Dob;
                    s.DeptAbbreviation = SubjectAbbrev;
                    s.UId      = u.UId;
                    s.U        = u;
                    u.Students = s;
                    dab.Students.Add(s);
                    dab.SaveChanges();
                    break;

                case "Professor":
                    Professors p = new Professors();
                    p.Dob = u.Dob;
                    p.DeptAbbreviation = SubjectAbbrev;
                    p.UId        = u.UId;
                    p.U          = u;
                    u.Professors = p;
                    dab.Professors.Add(p);
                    dab.SaveChanges();
                    break;

                default:
                    Admins a = new Admins();
                    a.Dob    = u.Dob;
                    a.UId    = u.UId;
                    a.U      = u;
                    u.Admins = a;
                    dab.Admins.Add(a);
                    dab.SaveChanges();
                    break;
                }
                return(u.UId);
            }
        }
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            pfDetail.Name = stepContext.Result.ToString();
            Professors pf   = new Professors();
            var        list = pf.ProfessorsDB(pfDetail.Name);

            if (list.Count > 0)
            {
                CardGenerator cardGenerator = new CardGenerator();
                await cardGenerator.AttachProfessorsCard(stepContext.Context, list, pfDetail.Name, cancellationToken);
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"{pfDetail.Name} 으로 검색한 결과가 없습니다."));
            }
            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
Beispiel #23
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="SubjectAbbrev">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)
        {
            string uniqueID = uIDGen();

            // Determine what type of user and store appropriate parameters.
            if (role.Equals("Administrator"))
            {
                Administrators a = new Administrators();

                a.FName = fName;
                a.LName = lName;
                a.Dob   = DOB;
                a.UId   = uniqueID;

                db.Administrators.Add(a);
                db.SaveChanges();
            }
            else if (role.Equals("Professor"))
            {
                Professors p = new Professors();

                p.FName   = fName;
                p.LName   = lName;
                p.Dob     = DOB;
                p.UId     = uniqueID;
                p.WorksIn = SubjectAbbrev;

                db.Professors.Add(p);
                db.SaveChanges();
            }
            else if (role.Equals("Student"))
            {
                Students s = new Students();

                s.FName = fName;
                s.LName = lName;
                s.Dob   = DOB;
                s.UId   = uniqueID;
                s.Major = SubjectAbbrev;

                db.Students.Add(s);
                db.SaveChanges();
            }

            return(uniqueID);
        }
Beispiel #24
0
        protected Team63LMSContext AddProfessor()
        {
            Team63LMSContext db = mockDB();

            Professors p = new Professors();

            p.FName   = "John";
            p.LName   = "Doe";
            p.UId     = uIDGen(db);
            p.WorksIn = "CS";
            p.Dob     = new DateTime(1997, 10, 23);

            db.Professors.Add(p);
            db.SaveChanges();

            return(db);
        }
        private void ExecuteRemove(object p)
        {
            if (p != null && p is Professor)
            {
                try
                {
                    var professor = p as Professor;

                    ServiceDataProvider.DeleteProfessor(professor.ProfessorId);
                    Professors.Remove(professor);
                }
                catch (FaultException <DeleteFault> fe)
                {
                    MessageBox.Show(string.Format("{0} {1}", fe.Detail.Message, fe.Detail.Description));
                }
            }
        }
        /*******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="SubjectAbbrev">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)
        {
            int id    = 0;
            var query = from u in db.Users
                        select u.UId;
            string newID = "u" + id.ToString().PadLeft(7, '0');

            while (query.Contains(newID))
            {
                id++;
                newID = "u" + id.ToString().PadLeft(7, '0');
            }
            Users user = new Users();

            user.UId       = newID;
            user.FirstName = fName;
            user.LastName  = lName;
            user.Dob       = DOB;
            db.Users.Add(user);

            if (role.ToLower() == "professor")
            {
                Professors p = new Professors();
                p.UId     = newID;
                p.Subject = SubjectAbbrev;
                db.Professors.Add(p);
            }
            else if (role.ToLower() == "student")
            {
                Students s = new Students();
                s.UId     = newID;
                s.Subject = SubjectAbbrev;
                db.Students.Add(s);
            }
            else if (role.ToLower() == "administrator")
            {
                Administrators a = new Administrators();
                a.UId = newID;
                db.Administrators.Add(a);
            }
            db.SaveChanges();
            return(newID);

            //return "";
        }
Beispiel #27
0
        protected Team63LMSContext AddClasses()
        {
            Team63LMSContext db = mockDB();

            AdministratorController controller = new AdministratorController();

            controller.UseLMSContext(db);

            // Create Professor to teach class
            Professors p = new Professors();

            p.FName   = "Danny";
            p.LName   = "Kopta";
            p.UId     = uIDGen(db);
            p.WorksIn = "CS";
            p.Dob     = new DateTime(1992, 10, 23);


            db.Professors.Add(p);
            db.SaveChanges();

            controller.CreateCourse("CS", 5530, "Database Systems");

            var query = from pr in db.Professors
                        select pr.UId;

            var query2 = from cr in db.Courses
                         select cr.CatalogId;

            // Create class associated with a CS course
            Classes c = new Classes();

            c.Loc        = "WEB 1250";
            c.Start      = new TimeSpan(7, 9, 16);
            c.End        = new TimeSpan(9, 16, 25);
            c.Semester   = "Spring 2019";
            c.TaughtBy   = query.SingleOrDefault();
            c.CategoryId = query2.SingleOrDefault();

            db.Classes.Add(c);

            db.SaveChanges();

            return(db);
        }
        private bool TryInsertUser(string uid, string fName, string lName, DateTime dob, string subjectAbbr, string role)
        {
            try
            {
                // Register as Student
                if (role == "Student")
                {
                    Students student = new Students();
                    student.FName = fName;
                    student.LName = lName;
                    student.Dob   = dob;
                    student.Major = subjectAbbr;
                    student.UId   = uid;
                    db.Students.Add(student);
                }
                // Register as Professor
                else if (role == "Professor")
                {
                    Professors prof = new Professors();
                    prof.FName      = fName;
                    prof.LName      = lName;
                    prof.Dob        = dob;
                    prof.Department = subjectAbbr;
                    prof.UId        = uid;
                    db.Professors.Add(prof);
                }
                // Register as Administrator
                else if (role == "Administrator")
                {
                    Administrators admin = new Administrators();
                    admin.FName = fName;
                    admin.LName = lName;
                    admin.Dob   = dob;
                    admin.UId   = uid;
                    db.Administrators.Add(admin);
                }

                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public Task HandleAsync(DepartmentProfessor message, CancellationToken cancellationToken)
        {
            DepartmentProfessor = message;
            Department.Id       = message.DepartmentId;
            Department.Name     = message.Name;
            Department.Code     = message.Code;
            Name = message.Name;
            Code = message.Code;
            var prof = _professorRepository.GetProfessors();

            Professors.AddRange(prof);
            Id = message.ProfessorId;
            if (Professors.Count != 0)
            {
                Professor = Professors.Where(p => p.Id == message.ProfessorId).First();
            }
            return(Task.CompletedTask);
        }
Beispiel #30
0
        /// <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)
        {
            string uId = GenerateUId();

            if (role.Equals("Administrator"))
            {
                Administrators user = new Administrators
                {
                    UId   = uId,
                    FName = fName,
                    LName = lName,
                    Dob   = DOB
                };
                db.Administrators.Add(user);
            }
            else if (role.Equals("Professor"))
            {
                Professors user = new Professors
                {
                    UId     = uId,
                    FName   = fName,
                    LName   = lName,
                    Dob     = DOB,
                    Subject = SubjectAbbrev
                };
                db.Professors.Add(user);
            }
            else
            {
                Students user = new Students
                {
                    UId     = uId,
                    FName   = fName,
                    LName   = lName,
                    Dob     = DOB,
                    Subject = SubjectAbbrev
                };
                db.Students.Add(user);
            }
            db.SaveChanges();
            return(uId);
        }