Пример #1
0
        static void Main()
        {
            Studentmodel studentFirst = new Studentmodel(1, "John");

            studentFirst.Introduce();

            Subjectmodel subject1 = new Subjectmodel();

            subject1.Id   = 1;
            subject1.Name = "Computer Science";
            studentFirst.subjects.Add(subject1);

            Subjectmodel subject2 = new Subjectmodel();

            subject2.Id   = 2;
            subject2.Name = " Science";
            studentFirst.subjects.Add(subject2);

            Subjectmodel subject3 = new Subjectmodel();

            subject3.Id   = 3;
            subject3.Name = "Computer";
            studentFirst.subjects.Add(subject3);

            foreach (Subjectmodel subject in studentFirst.subjects)
            {
                Console.WriteLine(subject.Name);
            }

            Console.ReadKey();
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            using (DBmodel dBModels = new DBmodel())
            {
                StudentTB    temp  = dBModels.StudentTBs.Where(x => x.sid == id).FirstOrDefault();
                Studentmodel model = new Studentmodel();

                model.fullname    = temp.fullname;
                model.gender      = temp.gender;
                model.address     = temp.address;
                model.email       = temp.email;
                model.grade       = temp.grade;
                model.parentname  = temp.parentname;
                model.parenttpnum = temp.parenttpnum;
                model.password    = temp.password;
                model.school      = temp.school;
                model.sid         = temp.sid;
                model.subject     = temp.subject;
                model.tpnum       = temp.tpnum;
                model.username    = temp.username;

                List <GradeList> grades   = dBModels.GradeLists.ToList();
                List <subject>   subjects = dBModels.subjects.ToList();

                ViewBag.Grades   = new SelectList(grades, "Grade", "Grade");
                ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1");

                return(View(model));
            }
        }
Пример #3
0
        public ActionResult Edit(int id, Studentmodel temp)
        {
            try
            {
                StudentTB model = new StudentTB();
                using (DBmodel dBModels = new DBmodel())
                {
                    model.fullname    = temp.fullname;
                    model.gender      = temp.gender;
                    model.address     = temp.address;
                    model.email       = temp.email;
                    model.grade       = temp.grade;
                    model.parentname  = temp.parentname;
                    model.parenttpnum = temp.parenttpnum;
                    model.password    = temp.password;
                    model.school      = temp.school;
                    model.sid         = id;
                    model.subject     = temp.subject;
                    model.tpnum       = temp.tpnum;
                    model.username    = temp.username;

                    dBModels.Entry(model).State = System.Data.Entity.EntityState.Modified;
                    dBModels.SaveChanges();
                }
                if (Session["Role"].ToString().Contains("Admin"))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Details", new { id = model.sid }));
                }
            }
            catch
            {
                DBmodel          dBModels = new DBmodel();
                List <GradeList> grades   = dBModels.GradeLists.ToList();
                List <subject>   subjects = dBModels.subjects.ToList();

                ViewBag.Grades   = new SelectList(grades, "Grade", "Grade");
                ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1");
                return(View());
            }
        }
Пример #4
0
        public ActionResult Details(int id)
        {
            using (DBmodel dBModels = new DBmodel())
            {
                StudentTB    temp  = dBModels.StudentTBs.Where(x => x.sid == id).FirstOrDefault();
                Studentmodel model = new Studentmodel();

                model.fullname    = temp.fullname;
                model.gender      = temp.gender;
                model.address     = temp.address;
                model.email       = temp.email;
                model.grade       = temp.grade;
                model.parentname  = temp.parentname;
                model.parenttpnum = temp.parenttpnum;
                model.password    = temp.password;
                model.school      = temp.school;
                model.sid         = temp.sid;
                model.subject     = temp.subject;
                model.tpnum       = temp.tpnum;
                model.username    = temp.username;

                return(View(model));
            }
        }
Пример #5
0
        public ActionResult Create(Studentmodel temp)
        {
            try
            {
                using (DBmodel dBModels = new DBmodel())
                {
                    if (dBModels.StudentTBs.Any(m => m.username == temp.username) ||
                        dBModels.Teachers.Any(m => m.Username == temp.username) ||
                        dBModels.Cleaners.Any(m => m.Username == temp.username) ||
                        dBModels.Offices.Any(m => m.Username == temp.username))
                    {
                        ViewBag.Error = "User name already exist! please use another one";

                        List <GradeList> grades   = dBModels.GradeLists.ToList();
                        List <subject>   subjects = dBModels.subjects.ToList();

                        ViewBag.Grades   = new SelectList(grades, "Grade", "Grade");
                        ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1");
                        return(View(temp));
                    }
                    else
                    {
                        StudentTB model = new StudentTB();

                        model.fullname    = temp.fullname;
                        model.gender      = temp.gender;
                        model.address     = temp.address;
                        model.email       = temp.email;
                        model.grade       = temp.grade;
                        model.parentname  = temp.parentname;
                        model.parenttpnum = temp.parenttpnum;
                        model.password    = temp.password;
                        model.school      = temp.school;
                        model.sid         = temp.sid;
                        model.subject     = temp.subject;
                        model.tpnum       = temp.tpnum;
                        model.username    = temp.username;

                        dBModels.StudentTBs.Add(model);

                        if (ModelState.IsValid)
                        {
                            dBModels.SaveChanges();
                            return(RedirectToAction("Index", "Student"));
                        }
                        else
                        {
                            List <GradeList> grades   = dBModels.GradeLists.ToList();
                            List <subject>   subjects = dBModels.subjects.ToList();

                            ViewBag.Grades   = new SelectList(grades, "Grade", "Grade");
                            ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1");
                            return(View(temp));
                        }
                    }
                }

                //return RedirectToAction("Loginpage", "Student");
            }
            catch
            {
                return(View());
            }
        }