Пример #1
0
        // POST - /api/instructors/
        public void SetPreference(InstructorPreference preference)
        {
            var userId         = User.Identity.GetUserId();
            var instructorInDb = _context.Instructors.SingleOrDefault(s => s.AccountId == userId);

            instructorInDb.InstructorPreference = preference;
            _context.SaveChanges();
            instructorInDb.InstructorPreferenceId = preference.Id;
            _context.SaveChanges();
        }
        public ActionResult Create([Bind(Include = "EmployeeId,Firstname,Lastname")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
        public ActionResult Create([Bind(Include = "ScheduleId,Start,Stop,Comment")] Schedule schedule)
        {
            if (ModelState.IsValid)
            {
                db.Schedules.Add(schedule);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(schedule));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "JobSopId,Title")] JobSop jobSop)
        {
            if (ModelState.IsValid)
            {
                db.JobSops.Add(jobSop);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(jobSop));
        }
Пример #5
0
        public ActionResult Create(Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
Пример #6
0
        public ActionResult Create([Bind(Include = "DepartmentId,Title")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
        public void DeleteLabAssistants(int id)
        {
            var labAssistantInDb = _context.LabAssistances.SingleOrDefault(x => x.Id == id);

            if (labAssistantInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            _context.LabAssistances.Remove(labAssistantInDb);
            _context.SaveChanges();
        }
Пример #8
0
        public void DeleteSection(int id)
        {
            var sectionInDb = _context.Sections.SingleOrDefault(x => x.Id == id);

            if (sectionInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            _context.Sections.Remove(sectionInDb);
            _context.SaveChanges();
        }
        public ActionResult Create(TimeSlot timeslot)
        {
            if (ModelState.IsValid)
            {
                timeslot.Event = db.Events.Find(eventID);
                db.TimeSlots.Add(timeslot);
                db.SaveChanges();
                return(PartialView("GridData", new TimeSlot[] { timeslot }));
            }

            return(PartialView("Edit", timeslot));
        }
Пример #10
0
        public ActionResult Create([Bind(Include = "JobId,Title,DepartmentId,JobSopId")] Job job)
        {
            if (ModelState.IsValid)
            {
                db.Jobs.Add(job);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Title", job.DepartmentId);
            ViewBag.JobSopId     = new SelectList(db.JobSops, "JobSopId", "Title", job.JobSopId);
            return(View(job));
        }
Пример #11
0
        public async Task <ActionResult> Create()
        {
            var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = await userManager.FindByNameAsync(User.Identity.Name);

            var deptHead = user == null ? null : _context.Instructors.Include(i => i.Department).Single(i => i.AccountId == user.Id);

            var sections = _context
                           .Sections
                           .Where(s => s.DepartmentId == deptHead.DepartmentId)
                           .ToList();

            var currentSemester = _context
                                  .AcademicSemesters
                                  .Include(s => s.AcademicYear)
                                  .Single(s => s.CurrentSemester);

            var previousCourseOfferings = _context.CourseOfferings.Where(c => c.AcademicSemesterId == currentSemester.Id);

            foreach (var previousCourseOffering in previousCourseOfferings)
            {
                _context.CourseOfferings.Remove(previousCourseOffering);
            }
            _context.SaveChanges();

            foreach (var section in sections)
            {
                //section.CurrentYear = (byte)((int.Parse(currentSemester.AcademicYear.EtYear) - section.EntranceYear) + 1);
                var courses = _context
                              .Courses
                              .Where(c => c.DeliveryYear == section.CurrentYear && c.DeliverySemester == currentSemester.Semester);

                foreach (var course in courses)
                {
                    _context.CourseOfferings.Add(
                        new CourseOffering
                    {
                        Name               = course.Title,
                        SectionId          = section.Id,
                        CourseId           = course.Id,
                        AcademicSemesterId = currentSemester.Id
                    }
                        );
                }
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "CourseOfferings"));
        }
        public ActionResult Create(SchedulingConstraint schedulingconstraint)
        {
            if (ModelState.IsValid)
            {
                schedulingconstraint.Event     = db.Events.Find(eventID);
                schedulingconstraint.Group     = db.Groups.Find(schedulingconstraint.Group != null ? schedulingconstraint.Group.ID : -1);
                schedulingconstraint.GroupType = db.GroupTypes.Find(schedulingconstraint.GroupType != null ? schedulingconstraint.GroupType.ID : -1);
                schedulingconstraint.Station   = db.Stations.Find(schedulingconstraint.Station != null ? schedulingconstraint.Station.ID : -1);
                db.SchedulingConstraints.Add(schedulingconstraint);
                db.SaveChanges();
                return(PartialView("GridData", new SchedulingConstraint[] { schedulingconstraint }));
            }

            return(PartialEditView(schedulingconstraint));
        }
Пример #13
0
        public ActionResult Create([Bind(Include = "ScheduleDetailId,Comment,Formation,ScheduleId,DepartmentId,JobId,EmployeeId")] ScheduleDetail scheduleDetail)
        {
            if (ModelState.IsValid)
            {
                db.ScheduleDetails.Add(scheduleDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Title", scheduleDetail.DepartmentId);
            ViewBag.EmployeeId   = new SelectList(db.Employees, "EmployeeId", "Firstname", scheduleDetail.EmployeeId);
            ViewBag.JobId        = new SelectList(db.Jobs, "JobId", "Title", scheduleDetail.JobId);
            ViewBag.ScheduleId   = new SelectList(db.Schedules, "ScheduleId", "Comment", scheduleDetail.ScheduleId);
            return(View(scheduleDetail));
        }
        public ActionResult Save(Course course)
        {
            if (course.Id == 0)
            {
                _context.Courses.Add(course);
            }
            else
            {
                var courseInDb = _context.Courses.Single(c => c.Id == course.Id);

                courseInDb.Id               = course.Id;
                courseInDb.CourseCode       = course.CourseCode;
                courseInDb.Credit           = course.Credit;
                courseInDb.CurriculumId     = course.CurriculumId;
                courseInDb.DeliverySemester = course.DeliverySemester;
                courseInDb.DeliveryYear     = course.DeliveryYear;
                courseInDb.Laboratory       = course.Laboratory;
                courseInDb.Lecture          = course.Lecture;
                courseInDb.Title            = course.Title;
                courseInDb.Tutor            = course.Tutor;
                courseInDb.Color            = course.Color;
                courseInDb.Acronym          = course.Acronym;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Courses"));
        }
Пример #15
0
        public void DeleteBuildings(int id)
        {
            var buildingInDb = _context
                               .Buildings
                               .Include(b => b.Rooms.Select(r => r.AssignedLectureSections))
                               .Include(b => b.Rooms.Select(r => r.AssignedLabGroups))
                               .SingleOrDefault(x => x.Id == id);

            if (buildingInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }


            var rooms = buildingInDb.Rooms;

            buildingInDb.Rooms = null;
            foreach (var room in rooms)
            {
                room.AssignedLabGroups       = null;
                room.AssignedLectureSections = null;
                _context.Rooms.Remove(room);
            }
            _context.Buildings.Remove(buildingInDb);
            _context.SaveChanges();
        }
Пример #16
0
        public async Task <ActionResult> Save(Curriculum curriculum)
        {
            var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = await userManager.FindByNameAsync(User.Identity.Name);

            var deptHead = user == null ? null : _context.Instructors.Include(i => i.Department).Single(i => i.AccountId == user.Id);

            if (curriculum.Id == 0)
            {
                curriculum.DepartmentId = deptHead.DepartmentId;
                _context.Curriculums.Add(curriculum);
            }
            else
            {
                var curriculumInDb = _context.Curriculums.SingleOrDefault(c => c.Id == curriculum.Id);

                curriculumInDb.AdmissionClassification = curriculum.AdmissionClassification;
                curriculumInDb.DepartmentId            = curriculum.DepartmentId;
                curriculumInDb.FieldOfStudy            = curriculum.FieldOfStudy;
                curriculumInDb.MinimumCredit           = curriculum.MinimumCredit;
                curriculumInDb.Program      = curriculum.Program;
                curriculumInDb.StaySemester = curriculum.StaySemester;
                curriculumInDb.StayYear     = curriculum.StayYear;
                curriculumInDb.Nomenclature = curriculum.Nomenclature;
                curriculumInDb.DepartmentId = deptHead.DepartmentId;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Curriculums"));
        }
Пример #17
0
        public JsonResult Create(Event e)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(e);
                db.SaveChanges();

                Response.AppendCookie(new HttpCookie("event", e.ID.ToString()));

                return(Json(e));
            }
            else
            {
                throw new Exception("Could not model bind event.");
            }
        }
 public ActionResult Create(Group group)
 {
     if (ModelState.IsValid)
     {
         group.Event       = db.Events.Find(eventID);
         group.Type        = db.GroupTypes.Find(group.TypeID);
         group.Preference1 = db.Stations.Find(group.Preference1.ID);
         group.Preference2 = db.Stations.Find(group.Preference2.ID);
         group.Preference3 = db.Stations.Find(group.Preference3.ID);
         group.Preference4 = db.Stations.Find(group.Preference4.ID);
         group.Preference5 = db.Stations.Find(group.Preference5.ID);
         db.Groups.Add(group);
         db.SaveChanges();
         return(PartialView("GridData", new Group[] { group }));
     }
     return(PartialEditView(group));
 }
        public ActionResult Save(LabAssistant model)
        {
            if (model.Id == 0)
            {
                _context.LabAssistances.Add(model);
            }
            else
            {
                var labAssistanceInDb = _context.LabAssistances.Single(l => l.Id == model.Id);

                labAssistanceInDb.FirstName       = model.FirstName;
                labAssistanceInDb.FatherName      = model.FatherName;
                labAssistanceInDb.GrandFatherName = model.GrandFatherName;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public IHttpActionResult Save(ScheduleDto model)
 {
     try
     {
         var currentSemester = _context.AcademicSemesters.SingleOrDefault(s => s.CurrentSemester);
         var schedule        = Mapper.Map <ScheduleDto, Schedule>(model);
         foreach (var day in schedule.Days)
         {
             foreach (var period in day.Periods)
             {
                 if (period.Course.Title == null)
                 {
                     day.Periods[period.Period].Course     = null;
                     day.Periods[period.Period].Instructor = null;
                     day.Periods[period.Period].Room       = null;
                     day.Periods[period.Period].LabGroupId = null;
                     day.Periods[period.Period].LabGroup   = null;
                 }
                 else
                 {
                     if (day.Periods[period.Period].IsLab)
                     {
                         day.Periods[period.Period].CourseId     = day.Periods[period.Period].Course.Id;
                         day.Periods[period.Period].Course       = null;
                         day.Periods[period.Period].InstructorId = day.Periods[period.Period].Instructor.Id;
                         day.Periods[period.Period].Instructor   = null;
                         day.Periods[period.Period].RoomId       = day.Periods[period.Period].Room.Id;
                         day.Periods[period.Period].Room         = null;
                         day.Periods[period.Period].LabGroupId   = day.Periods[period.Period].LabGroup.Id;
                         day.Periods[period.Period].LabGroup     = null;
                     }
                     else
                     {
                         day.Periods[period.Period].CourseId     = day.Periods[period.Period].Course.Id;
                         day.Periods[period.Period].Course       = null;
                         day.Periods[period.Period].InstructorId = day.Periods[period.Period].Instructor.Id;
                         day.Periods[period.Period].Instructor   = null;
                         day.Periods[period.Period].RoomId       = day.Periods[period.Period].Room.Id;
                         day.Periods[period.Period].Room         = null;
                         day.Periods[period.Period].LabGroup     = null;
                         day.Periods[period.Period].LabGroupId   = null;
                     }
                 }
             }
         }
         schedule.SectionId          = schedule.Section.Id;
         schedule.Section            = null;
         schedule.AcademicSemesterId = currentSemester.Id;
         _context.Schedules.Add(schedule);
         _context.SaveChanges();
         return(Ok());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #21
0
        public void DeleteSection(int id)
        {
            var labGroupInDb = _context.LabGroups.SingleOrDefault(g => g.Id == id);

            if (labGroupInDb != null)
            {
                _context.LabGroups.Remove(labGroupInDb);
                _context.SaveChanges();
            }
        }
Пример #22
0
        // TODO: set dispatch status to callback & generate interrupt
        // Only start time & callback info are allowed for updates
        public static void SetCallback(Dispatch ThisDispatch)
        {
            Dispatch      dispatch;
            DbEntityEntry entry;
            IrqHandle     irq;
            DateTime      currentdatetimeutc = DateTime.UtcNow;

            using (SchedulingContext se = new SchedulingContext())
            {
                dispatch = se.Dispatches.Find(ThisDispatch.Id);
                entry    = se.Entry <Dispatch>(dispatch);
                entry.CurrentValues.SetValues(ThisDispatch);

                if (entry.State == System.Data.EntityState.Modified)
                {
                    entry.Property("CreatedDateTimeUtc").CurrentValue = entry.Property("CreatedDateTimeUtc").OriginalValue;
                    dispatch.LastModifiedDateTimeUtc = currentdatetimeutc;

                    irq = new IrqHandle()
                    {
                        ScheduleID = ThisDispatch.ScheduleID,
                        DispatchID = ThisDispatch.Id,
                        Level      = IRQL.Dispatch,
                        TimeStamp  = currentdatetimeutc
                    };
                    se.IrqQueue.Add(irq);

                    // simple strategy to retry only once on concurrency update failure
                    try
                    {
                        se.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // Update original values from the database
                        entry = ex.Entries.Single();
                        entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                        se.SaveChanges();
                    }
                }
            }
        }
        private void assignSectionToRoomButton_Click(object sender, EventArgs e)
        {
            int sectionId = int.Parse(sectionDropdown.SelectedValue.ToString());
            int roomId    = int.Parse(roomDropdown.SelectedValue.ToString());

            var section = _context.Sections.SingleOrDefault(s => s.Id == sectionId);
            var room    = _context.Rooms.SingleOrDefault(r => r.Id == roomId);

            section.AssignedRooms.Add(room);
            _context.SaveChanges();
        }
Пример #24
0
 public ActionResult Create(Station station, int[] TimeSlotIDs)
 {
     if (ModelState.IsValid)
     {
         station.Event = db.Events.Find(eventID);
         station.AvailableTimeSlots = new List <TimeSlot>();
         if (TimeSlotIDs != null)
         {
             foreach (var timeSlotID in TimeSlotIDs)
             {
                 station.AvailableTimeSlots.Add(db.TimeSlots.Find(timeSlotID));
             }
         }
         db.Stations.Add(station);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     PrepareTimeSlotCheckBoxes();
     return(View("Edit", station));
 }
Пример #25
0
        private void registerSectionButton_Click(object sender, EventArgs e)
        {
            var room = new Room
            {
                Name = nameValue.Text,
                //Building = buildingValue.Text,
                Size = int.Parse(sizeValue.Text)
            };

            _context.Rooms.Add(room);
            _context.SaveChanges();
        }
Пример #26
0
        public void DeleteCurriculum(int id)
        {
            var curriculumInDb = _context.Curriculums.SingleOrDefault(x => x.Id == id);

            if (curriculumInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            _context.Curriculums.Remove(curriculumInDb);
            _context.SaveChanges();
        }
        private void saveButton_Click(object sender, EventArgs e)
        {
            Instructor instructor = new Instructor
            {
                FirstName       = firstNameValue.Text,
                FatherName      = fatherNameValue.Text,
                GrandFatherName = grandFatherNameValue.Text,
                DepartmentId    = int.Parse(departmentDropdown.SelectedValue.ToString())
            };

            _context.Instructors.Add(instructor);
            _context.SaveChanges();
        }
Пример #28
0
        public async Task <IHttpActionResult> ChangeDepartmentHead(DepartmentHeadChangeDto dto)
        {
            if (ModelState.IsValid)
            {
                // Find the department in the database with the given id
                var departmentInDb = _context
                                     .Departments
                                     .Include(d => d.DepartmentHead)
                                     .Single(d => d.Id == dto.DepartmentId);


                // to use the user manager
                var userStore   = new UserStore <ApplicationUser>(new ApplicationDbContext());
                var userManager = new ApplicationUserManager(userStore);

                // make sure the department has a head assigned to it already
                if (departmentInDb.DepartmentHead != null)
                {
                    // the old department head who is about to be replaced
                    var oldDepartmentHead = departmentInDb.DepartmentHead;

                    // remove the old department head from the department head role
                    var result = await userManager.RemoveFromRoleAsync(oldDepartmentHead.AccountId, RoleName.IsADepartmentHead);
                }

                // update department head to the new instructor
                departmentInDb.DepartmentHeadId = dto.InstructorId;

                // find the instructor from the db with the id
                var instructor = _context.Instructors.Single(i => i.Id == dto.InstructorId);

                // add the new department head to the department head role
                await userManager.AddToRoleAsync(instructor.AccountId, RoleName.IsADepartmentHead);

                _context.SaveChanges();
            }
            return(Ok());
        }
        public IHttpActionResult Save(AcademicEvent model)
        {
            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    model = _context.AcademicEvents.Add(model);
                }
                else
                {
                    var eventInDb = _context.AcademicEvents.SingleOrDefault(e => e.Id == model.Id);
                    eventInDb.Subject     = model.Subject;
                    eventInDb.Description = model.Description;
                    eventInDb.Start       = model.Start;
                    eventInDb.End         = model.End;
                    eventInDb.Color       = model.Color;
                }

                _context.SaveChanges();
            }

            return(Ok(model));
        }
        public ActionResult SaveYear(AcademicYearsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var academicYear = new AcademicYear
                {
                    StartDate = model.StartDate,
                    EndDate   = model.EndDate,
                    EtYear    = model.EtYear,
                    GcYear    = model.GcYear
                };

                var academicYearStartEvent = new AcademicEvent
                {
                    Subject     = "Academic Year Start Date",
                    Description = $"{academicYear.EtYear} EC Academic Year Start Date",
                    Start       = model.StartDate
                };

                var academicYearEndEvent = new AcademicEvent
                {
                    Subject     = "Academic Year End Date",
                    Description = $"{academicYear.EtYear} EC Academic Year End Date",
                    Start       = model.EndDate
                };

                _context.AcademicYears.Add(academicYear);
                _context.AcademicEvents.Add(academicYearStartEvent);
                _context.AcademicEvents.Add(academicYearEndEvent);

                _context.SaveChanges();

                return(RedirectToAction("Index", "Semesters"));
            }

            return(View("NewAcademicYear"));
        }