private void removeinstructor_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                decimal x = decimal.Parse(salaryName.Text.ToString());

                int query =
                    (from c in context3.branches
                     where c.Name == branchName.SelectedItem.ToString()
                     select c.BranchId).FirstOrDefault();

                instructor deleteinstructor =
                    (from ins in context3.instructors
                     where ins.FirstName == instructorname.Text.ToString() && ins.Salary == x &&
                     ins.Branchid == query
                     select ins).FirstOrDefault();

                context3.instructors.Remove(deleteinstructor);
                context3.SaveChanges();
                showInstrctor removeFromList = new showInstrctor();
                removeFromList.FirstName  = instructorname.Text.ToString();
                removeFromList.Branchname = branchName.SelectedItem.ToString();
                removeFromList.Salary     = x;


                instructorss.Items.Remove(removeFromList);
            }
            catch (Exception d)

            {
                MessageBox.Show("invalid inputs");
            }
        }
        private void editcourse_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                corseadd selectedcrs = coursess.SelectedItem as corseadd;
                selectedcrs.Name           = coursename.Text.ToString();
                selectedcrs.MaxDegree      = short.Parse(degreee.Text.ToString());
                selectedcrs.instructorName = instructorcourse.SelectedItem.ToString();

                instructor newins = context3.instructors.Where(em => em.FirstName == selectedcrs.instructorName).FirstOrDefault();

                course updatecourse =
                    (from cr in context3.courses
                     where cr.Name == selectedcrs.Name && cr.MaxDegree == selectedcrs.MaxDegree
                     select cr).FirstOrDefault();
                updatecourse.Name        = coursename.Text.ToString();
                updatecourse.MaxDegree   = short.Parse(degreee.Text.ToString());
                updatecourse.MinDegree   = 50;
                updatecourse.Description = updatecourse.Name + " is important";

                context3.SaveChanges();

                rel_instructor_cource updatecourseandinstructor = context3.rel_instructor_cource.Where(em => em.CourseId == updatecourse.CourseId).FirstOrDefault();
                updatecourseandinstructor.InsId = newins.InsId;
                context3.SaveChanges();
            }
            catch (Exception k)
            {
            }
        }
Пример #3
0
        private void updateinstructor_Click(object sender, RoutedEventArgs e)
        {
            showInstrctor updated = new showInstrctor();

            updated = instructorss.SelectedItem as showInstrctor;

            int query =
                (from c in context3.branches
                 where c.Name == branchName.SelectedItem.ToString()
                 select c.BranchId).FirstOrDefault();

            int query2 =
                (from c in context3.branches
                 where c.Name == updated.Branchname
                 select c.BranchId).FirstOrDefault();

            instructor deleteinstructor =
                (from ins in context3.instructors
                 where ins.FirstName == updated.FirstName && ins.Salary == updated.Salary &&
                 ins.Branchid == query2
                 select ins).FirstOrDefault();

            decimal x = decimal.Parse(salaryName.Text.ToString());

            deleteinstructor.FirstName = instructorname.Text.ToString();
            deleteinstructor.Salary    = x;
            deleteinstructor.Branchid  = query;

            context3.SaveChanges();
        }
        private void addinstructor_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                showInstrctor newinst = new showInstrctor();
                newinst.FirstName  = instructorname.Text.ToString();
                newinst.Branchname = branchName.SelectedItem.ToString();
                newinst.Salary     = decimal.Parse(salaryName.Text.ToString());

                instructor NewInstructorWasAdded = new instructor();
                user       NewUserWasAdded       = new user();

                NewUserWasAdded.Password = newinst.FirstName;
                NewUserWasAdded.Type     = "instructor";
                NewUserWasAdded.Email    = newinst.FirstName + "@gmail.com";
                context3.users.Add(NewUserWasAdded);
                context3.SaveChanges();

                int query =
                    (from c in context3.branches
                     where c.Name == newinst.Branchname
                     select c.BranchId).FirstOrDefault();
                instructor newInstructorIsAdded = new instructor();
                newInstructorIsAdded.InsEmail = NewUserWasAdded.Email;

                newInstructorIsAdded.ManagerId     = 1;
                newInstructorIsAdded.FirstName     = newinst.FirstName;
                newInstructorIsAdded.LastName      = newinst.FirstName;
                newInstructorIsAdded.MaritalStatus = "married";
                newInstructorIsAdded.BirthDate     = DateTime.Now;
                newInstructorIsAdded.HireDate      = DateTime.Now;
                newInstructorIsAdded.Job           = "instructor";
                newInstructorIsAdded.Salary        = newinst.Salary;
                newInstructorIsAdded.Branchid      = query;
                context3.instructors.Add(newInstructorIsAdded);
                context3.SaveChanges();
                instructorss.Items.Add(newinst);
            }
            catch (Exception u)
            {
                MessageBox.Show("inavlid inputs");
            }
        }
        private void addcourse_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                corseadd newcourse = new corseadd();

                newcourse.Name = coursename.Text.ToString();

                newcourse.MaxDegree = 100;

                newcourse.instructorName = instructorcourse.SelectedItem.ToString();

                instructor newins = context3.instructors.Where(em => em.FirstName == newcourse.instructorName).FirstOrDefault();

                rel_instructor_cource newcourseinstructor = new rel_instructor_cource();


                course newCourseAdd = new course();
                newCourseAdd.Name        = coursename.Text.ToString();
                newCourseAdd.MinDegree   = 50;
                newCourseAdd.MaxDegree   = 100;
                newCourseAdd.Description = coursename.Text.ToString() + "is important";
                context3.courses.Add(newCourseAdd);
                context3.SaveChanges();
                newcourseinstructor.CourseId = newCourseAdd.CourseId;
                newcourseinstructor.InsId    = newins.InsId;
                newcourseinstructor.Year     = DateTime.Now;

                context3.rel_instructor_cource.Add(newcourseinstructor);
                context3.SaveChanges();
                coursess.Items.Add(newcourse);
            }
            catch (Exception f)
            {
                MessageBox.Show("Invalid Inputs");
            }
        }