コード例 #1
0
ファイル: User.cs プロジェクト: weedkiller/Spitball
        public virtual void SetUserType(UserType userType)
        {
            switch (userType)
            {
            case UserType.UniversityStudent:
                Extend = new CollegeStudent(this);
                break;

            case UserType.HighSchoolStudent:
                Extend = new HighSchoolStudent(this);

                break;

            case UserType.Parent:
                Extend = new Parent(this);

                break;

            case UserType.Teacher:
                Extend = new Teacher(this);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(userType), userType, null);
            }

            UserType2 = userType;
        }
コード例 #2
0
        // GET: HighSchoolStudents/Delete
        public ActionResult HighSchoolDelete(int?id)
        {
            HighSchoolStudent highSchoolStudent = db.HighSchoolStudents.Find(id);

            db.HighSchoolStudents.Remove(highSchoolStudent);
            db.SaveChanges();
            return(RedirectToAction("HighSchoolIndex"));
        }
コード例 #3
0
 public ActionResult HighSchoolEdit([Bind(Include = "HighSchoolStudent_ID,Grade_ID,Student_ID")] HighSchoolStudent highSchoolStudent)
 {
     if (ModelState.IsValid)
     {
         db.Entry(highSchoolStudent).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("HighSchoolIndex"));
     }
     ViewBag.Grade_ID   = new SelectList(db.Grades, "Grade_ID", "GradeName", highSchoolStudent.Grade_ID);
     ViewBag.Student_ID = new SelectList(db.Students, "Student_ID", "Student_ID", highSchoolStudent.Student_ID);
     return(View(highSchoolStudent));
 }
コード例 #4
0
        // GET: HighSchoolStudents/Edit
        public ActionResult HighSchoolEdit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HighSchoolStudent highSchoolStudent = db.HighSchoolStudents.Find(id);

            if (highSchoolStudent == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Grade_ID   = new SelectList(db.Grades, "Grade_ID", "GradeName", highSchoolStudent.Grade_ID);
            ViewBag.Student_ID = new SelectList(db.Students, "Student_ID", "Student_ID", highSchoolStudent.Student_ID);
            return(View(highSchoolStudent));
        }
コード例 #5
0
        public dynamic RegisterUser(string name, string surname, string email, string username, string password, string confirmpassword, string phonenumber, int grade, int degree, int studentType)
        {
            string test = "PLEASE Workkk";

            try
            {
                //add user
                User user = new User();
                user.UserType_ID = 3;
                user.Name        = name;
                user.Surname     = surname;
                user.Email       = email;
                user.Username    = username;

                //hashing of password
                string pass = password;
                var    hash = GenerateHash(ApplySomeSalt(pass));
                user.Password = hash;

                user.PhoneNo = phonenumber;
                db.Users.Add(user);

                //add student
                Student newStudent = new Student();
                newStudent.User_ID        = user.User_ID;
                newStudent.StudentType_ID = studentType;
                db.Students.Add(newStudent);

                //highschool student
                if (studentType == 1)
                {
                    HighSchoolStudent hstudent = new HighSchoolStudent();
                    hstudent.Student_ID = newStudent.Student_ID;
                    hstudent.Grade_ID   = Convert.ToInt32(grade);
                    db.HighSchoolStudents.Add(hstudent);
                }
                //university student
                else if (studentType == 2)
                {
                    UniversityStudent ustudent = new UniversityStudent();
                    ustudent.Student_ID = newStudent.Student_ID;
                    ustudent.Degree_ID  = Convert.ToInt32(degree);
                    db.UniversityStudents.Add(ustudent);
                }
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }

            return(test);
        }