Exemplo n.º 1
0
        public string InsertInstructor(string name, string email, string title, string pwd, int d_id,
                                       string country, double size)
        {
            lecturer l = new lecturer
            {
                name_surname  = name,
                email         = email,
                title         = title,
                password      = pwd,
                department_id = d_id,
            };

            db.lecturers.InsertOnSubmit(l);


            try
            {
                db.SubmitChanges();
                return("sucess");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 2
0
        // Creates a new course from user input
        public void CreateCourse()
        {
            try {
                // at first check if all inputs filled
                if (InputLecturerFirstName == null || InputLecturerLastName == null || InputLecturerEmail == null || InputLecturerSalutation == null ||
                    InputCourseName == null || InputCourseSemester == null)
                {
                    throw new FormatException();
                }
                // create a lecturer for the new course
                lecturer newLecturer = new lecturer();

                // add a new course to the db
                course newCourse = new course {
                    semester = InputCourseSemester,
                    name     = InputCourseName,
                };
                access.addCourse(newCourse);

                // check if lecturer already exist
                List <lecturer> listOfLecturers = new List <lecturer>();
                listOfLecturers = access.LecturerContext.GetAll().Where(s => s.firstName == InputLecturerFirstName && s.lastName == InputLecturerLastName).ToList();

                if (listOfLecturers != null)
                {
                    // if no lecturer exist create a new one
                    newLecturer = new lecturer {
                        email      = InputLecturerEmail,
                        firstName  = InputLecturerFirstName,
                        lastName   = InputLecturerLastName,
                        salutation = InputLecturerSalutation
                    };
                    access.LecturerContext.AddOne(newLecturer);
                    access.LecturerContext.AddLecToCourse(newLecturer, newCourse);
                }
                else
                {
                    // if lecturer exist fill the fields without add a new lecturer to the db
                    foreach (lecturer existingLecturer in listOfLecturers)
                    {
                        newLecturer.firstName  = existingLecturer.firstName;
                        newLecturer.lastName   = existingLecturer.lastName;
                        newLecturer.email      = existingLecturer.email;
                        newLecturer.salutation = existingLecturer.salutation;
                    }
                    access.LecturerContext.AddOne(newLecturer);
                    access.LecturerContext.AddLecToCourse(newLecturer, newCourse);
                }

                // update courseOverview
                Courses = access.GetAllCourses();

                // close popup
                CreateCourseViewVisible = false;
            } catch (FormatException e) {
                InputFeedback = "Der Kurs konnte nicht erstellt werden. Bitte überprüfen Sie die Eingaben.";
                InputFeedbackPopup();
                Console.WriteLine(e);
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            lecturer lecturer = db.lecturers.Find(id);

            db.lecturers.Remove(lecturer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 public List <course> GetCoursesOfLectruer(int id)
 {
     using (se02team06 context = new se02team06()) {
         DbSet <lecturer> dbsetLectruer = context.Set <lecturer>();
         lecturer         lecturerTmp   = dbsetLectruer.Find(id);
         context.Entry(lecturerTmp).Collection(s => s.courses).Load(); // loads Courses collection
         context.SaveChanges();
         return(lecturerTmp.courses.ToList());
     }
 }
Exemplo n.º 5
0
        public ActionResult Index(string txtStudent, string lecId)
        {
            lecturer _lect = db.lecturers.Find((string)Session["lecturerId"]);

            if (txtStudent == "")
            {
                return(RedirectToAction("Index", "SRVLogin", new { notFound = false }));
            }
            return(RedirectToAction("Index", "SRVLogin", new { value = txtStudent + "/" }));
        }
Exemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "lecturer_Id,lecturer_Name,univercity_Id,College_Institute_Center")] lecturer lecturer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lecturer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.univercity_Id = new SelectList(db.univercities, "univercity_Id", "univercity_name", lecturer.univercity_Id);
     return(View(lecturer));
 }
Exemplo n.º 7
0
 public void AddLecToCourse(lecturer lecturer, course course)
 {
     using (se02team06 context = new se02team06()) {
         DbSet <lecturer> dbsetLecturer = context.Set <lecturer>();
         DbSet <course>   dbsetCourse   = context.Set <course>();
         var tmpLec    = dbsetLecturer.Find(lecturer.lecturerID);
         var tmpCourse = dbsetCourse.Find(course.courseID);
         tmpLec.courses.Add(tmpCourse);
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 private void FillLecturer()
 {
     firstNameLecturer.ForEach(firstname => {
         lecturer tmplec = new lecturer {
             salutation = salutationLecturer[firstNameLecturer.IndexOf(firstname)],
             firstName  = firstname,
             lastName   = lastNameLecturer[firstNameLecturer.IndexOf(firstname)],
             email      = emailLecturer[firstNameLecturer.IndexOf(firstname)]
         };
         lecDbSet.AddLecToCourse(lecDbSet.AddOne(tmplec), courseDbSet.GetById(firstNameLecturer.IndexOf(firstname) + 1));
     });
 }
Exemplo n.º 9
0
        public Lecturer ConvertLecturer(lecturer l)
        {
            Lecturer lecturer = new Lecturer {
                LecturerID = l.lecturerID,
                FirstName  = l.firstName,
                LastName   = l.lastName,
                Salutation = l.salutation,
                Email      = l.email,
                Courses    = new List <Course>()
            };

            return(lecturer);
        }
Exemplo n.º 10
0
        // GET: lecturers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            lecturer lecturer = db.lecturers.Find(id);

            if (lecturer == null)
            {
                return(HttpNotFound());
            }
            return(View(lecturer));
        }
Exemplo n.º 11
0
 private void FillLecturer()
 {
     firstNameLecturer.ForEach(firstname => {
         lecturer tmplec = new lecturer {
             salutation = salutationLecturer[firstNameLecturer.IndexOf(firstname)],
             firstName  = firstname,
             lastName   = lastNameLecturer[firstNameLecturer.IndexOf(firstname)],
             email      = emailLecturer[firstNameLecturer.IndexOf(firstname)]
         };
         lecDbSet.AddLecToCourse(lecDbSet.AddOne(tmplec), courseDbSet.GetById(firstNameLecturer.IndexOf(firstname) + 1));
         Console.WriteLine($"fill lecturer {tmplec.firstName}{tmplec.lastName} and add to course");
     });
     Console.WriteLine("- - - - - - - Finished - - - - -");
 }
Exemplo n.º 12
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            lecturer lecturer = db.lecturers.Find(id);

            if (lecturer == null)
            {
                return(HttpNotFound());
            }
            ViewBag.univercity_Id = new SelectList(db.univercities, "univercity_Id", "univercity_name", lecturer.univercity_Id);
            return(View(lecturer));
        }
Exemplo n.º 13
0
        public List <User> GetListUser <T> (List <T> list)
        {
            List <User> users = new List <User>();

            // list type is student
            if (list.GetType().GetGenericArguments()[0].Name.Equals("student"))
            {
                list.ForEach(a =>
                {
                    student _s = a as student;
                    users.Add(new User()
                    {
                        LecturerID   = _s.StudentID,
                        EmailAddress = _s.EmailAddress,
                        GivenName    = _s.GivenName,
                        LastName     = _s.LastName,
                        UserType     = "student"
                    });
                });
            }
            // list type is lecturer
            else if (list.GetType().GetGenericArguments()[0].Name.Equals("lecturer"))
            {
                list.ForEach(a =>
                {
                    lecturer _s = a as lecturer;
                    users.Add(new User()
                    {
                        LecturerID   = _s.LecturerID,
                        EmailAddress = _s.EmailAddress,
                        GivenName    = _s.GivenName,
                        LastName     = _s.LastName,
                        UserType     = "lecturer"
                    });
                });
            }
            return(users);
        }
Exemplo n.º 14
0
        public ActionResult Index(string value, int?year, int?term)
        {
            lecturer _lect     = new lecturer();
            bool     isStudent = true;

            var _listStudent = db.students.ToList();

            // convert list of student to list of User
            List <User> _listUser = findUser.GetListUser(_listStudent);

            // find if input value existing in the list of user
            User _user = findUser.FindUserByInputValue(_listUser, value);

            // if user is null then try to find out if the input value is the lecturer
            if (_user == null)
            {
                var _listLecturer = db.lecturers.ToList();

                // convert the list of lectuer to list of user
                _listUser = findUser.GetListUser(_listLecturer);

                // find out if the input value existing in the list of user
                _lect = findUser.FindUserByInputValue(_listUser, value);

                // if can't find lecturer, then redirect to Home controller
                if (_lect == null)
                {
                    return(RedirectToAction("Index", "Home", new { notFound = false }));
                }
                else
                {
                    Session["user"] = _lect;
                    //Session["lecturer"] = _lect;
                    //Session["lecturerId"] = _lect.LecturerID;
                    isStudent = false;
                }
            }
            else
            {
                if (Session["user"] == null)
                {
                    Session["user"] = _user;
                }

                isStudent = true;
            }

            if (isStudent)
            {
                if (Session["lecturerId"] != null)
                {
                    _lect            = db.lecturers.Find((string)Session["lecturerId"]);
                    ViewBag.lecturer = _lect;
                }

                student _student = db.students.Find(_user.LecturerID);

                List <student_studyplan> studyPlans    = _student.student_studyplan.ToList();
                List <SelectListItem>    quals         = new List <SelectListItem>();
                List <SelectListItem>    studyPlanYear = new List <SelectListItem>();
                List <SelectListItem>    terms         = new List <SelectListItem>();

                foreach (var item in studyPlans)
                {
                    quals.Add(new SelectListItem
                    {
                        Text  = item.qualification.QualName,
                        Value = item.QualCode
                    });
                }

                foreach (var item in studyPlans)
                {
                    studyPlanYear.Add(new SelectListItem
                    {
                        Text  = item.TermYearStart.ToString(),
                        Value = item.TermYearStart.ToString()
                    });
                }
                for (int i = 1; i < 5; i++)
                {
                    terms.Add(new SelectListItem
                    {
                        Text  = i.ToString(),
                        Value = i.ToString()
                    });
                }

                ViewBag.quals         = quals;
                ViewBag.studyPlanYear = studyPlanYear;
                ViewBag.terms         = terms;
                ViewBag.year          = year;
                ViewBag.term          = term;
                return(View("Student", _student));
            }
            else
            {
                List <SelectListItem> listDept = new List <SelectListItem>();

                List <crn_detail> listCrn = new List <crn_detail>();
                listCrn = db.lecturers.Find(_lect.LecturerID).crn_detail.ToList(); //_lect.crn_detail.ToList();
                HashSet <string> dept = new HashSet <string>();
                foreach (var item in listCrn)
                {
                    dept.Add(item.department.Department1);
                }
                foreach (var item in dept)
                {
                    listDept.Add(new SelectListItem
                    {
                        Text  = item,
                        Value = item
                    });
                }
                ViewBag.dept = listDept;
                return(View("Lecturer", _lect));
            }
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            using (var ctx = new tect_CodeFirstContext())
            {
                try
                {
                    try
                    {
                        ctx.lecturers.Remove(ctx.lecturers.ToList <lecturer>().ElementAt(0));
                        // ctx.lecturers.Remove(ctx.lecturers.ToList<lecturer>().ElementAt(1));
                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    var lectureList = ctx.lecturers.ToList <lecturer>();
                    //Perform create operation
                    Console.WriteLine("Perform create operation");
                    ctx.lecturers.Add(new lecturer()
                    {
                        lc_id = "L_1", lc_fname = "New lecturer"
                    });
                    //Execute Insert, Update & Delete queries in the database
                    ctx.SaveChanges();
                    var lects1 = ctx.lecturers.ToList <lecturer>();
                    Lecturers_print(lects1);

                    //Perform Update operation
                    Console.WriteLine("Perform Update operation");
                    var      lecturerList1    = ctx.lecturers.ToList <lecturer>();
                    lecturer lecturerToUpdate = lecturerList1.Where(s => s.lc_fname == "New lecturer").FirstOrDefault <lecturer>();
                    lecturerToUpdate.lc_fname = "Edited lecturer";
                    //Execute Insert, Update & Delete queries in the database
                    ctx.SaveChanges();
                    lects1 = ctx.lecturers.ToList <lecturer>();
                    Lecturers_print(lects1);

                    Console.WriteLine();
                    SQL_qry(ctx);
                    Console.WriteLine();

                    Console.WriteLine("Transaction example");
                    Transaction_test tr = new Transaction_test();
                    tr.StartOwnTransactionWithinContext();

                    lects1 = ctx.lecturers.ToList <lecturer>();
                    Lecturers_print(lects1);
                    //Perform delete operation, re-read lecturers list
                    Console.WriteLine("Perform delete operation");
                    lecturerList1 = ctx.lecturers.ToList <lecturer>();
                    ctx.lecturers.Remove(lecturerList1.ElementAt <lecturer>(0));
                    ctx.lecturers.Remove(lecturerList1.Where(s => s.lc_fname == "Edited second lecturer").FirstOrDefault <lecturer>());
                    //Execute Insert, Update & Delete queries in the database
                    ctx.SaveChanges();
                    lects1 = ctx.lecturers.ToList <lecturer>();
                    Lecturers_print(lects1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.ReadKey();
            }
        }