public Model.Entities.Course AddCourseByStaff(Model.Entities.Course course, int staffId) { // Before we add an association to the StaffCourse table let's add the course to the database to generate course Id which // then be used to populate the StaffCourse entity Model.Entities.Course newCourse = Add(course); // This doesn't seem to be the best solution to deal with many-to-many relationships but as of limited knowledge at the time of this writing // This deemed to be the perfect solution. Model.Entities.StaffCourse staffCourse = new Model.Entities.StaffCourse(); staffCourse.Course_Id = newCourse.Id; staffCourse.Staff_Id = staffId; // As we don't know the use of these fields so we are setting a dummy datetime value for now staffCourse.EffectiveFrom = DateTime.Now; staffCourse.EffectiveTo = DateTime.Now; StaffCourse newStaffCourse = ObjectMapper.Map <Model.Entities.StaffCourse, StaffCourse>(staffCourse); DbEntityEntry entry = Context.Entry <StaffCourse>(newStaffCourse); if (entry.State == System.Data.Entity.EntityState.Detached) { Context.Entry <StaffCourse>(newStaffCourse).State = System.Data.Entity.EntityState.Added; Context.SaveChanges(); } return(newCourse); }
public StaffCourse UpdateStaffCourse(string id, StaffCourse staffcourse) { for (var index = _staffcourses.Count - 1; index >= 0; index--) { if (_staffcourses[index].ID == id) { _staffcourses[index] = staffcourse; } } return(staffcourse); }
public ActionResult GetDetails(string selectedSemester, string selectedStaff, string selectedDepartment, string selectedSubject) { if (string.IsNullOrEmpty(selectedSemester) || string.IsNullOrEmpty(selectedStaff) || string.IsNullOrEmpty(selectedDepartment) || selectedSubject.Contains("---Select---")) { TempData["AllocatedErrorMessage"] = "Please fill all of the fields"; return(RedirectToAction("Index")); } var staffId = 0; // Get a selected Semester Id var semesterId = DatabaseData.GetSemesterInfo(selectedSemester).Id; // Get a selected staff Id var staff = _context.Staffs.FirstOrDefault(u => u.Name == selectedStaff); if (staff != null) { staffId = staff.Id; } // Get a selected department Id var departmentId = DatabaseData.GetDepartmentInfo(selectedDepartment).Id; // Get a selected subject id var subjectId = DatabaseData.GetCourseInfo(selectedSubject).Courseid; var newAllocatedCourse = new StaffCourse { CourseId = subjectId, SemesterId = semesterId, StaffId = staffId, DepartmentId = departmentId }; _context.StaffCourses.Add(newAllocatedCourse); _context.SaveChanges(); TempData["AllocatedSuccessMessage"] = "Subject allocated to staff successfully"; return(RedirectToAction("Index")); }
public string AssignCourse(StaffCourse model) { try { if (_context.StaffCourses.Any(a => a.StaffId == model.StaffId && a.CourseId == model.CourseId)) { return("Course already assigned to staff"); } model.Id = Guid.NewGuid().ToString(); model.DateAssigned = DateTime.Now; _context.StaffCourses.Add(model); return(_context.SaveChanges() > 0 ? "" : "Course could not be assigned to staff"); } catch (Exception ex) { throw ex; } }
public StaffCourse AddStaffCourse(StaffCourse staffcourse) { _staffcourses.Add(staffcourse); return(staffcourse); }
public ActionResult <StaffCourse> UpdateStaffCourse(string id, StaffCourse staffcourse) { _service.UpdateStaffCourse(id, staffcourse); return(staffcourse); }
public ActionResult <StaffCourse> AddStaffCourse(StaffCourse staffcourse) { _service.AddStaffCourse(staffcourse); return(staffcourse); }
public void DeleteStaffCourseRelationship(StaffCourse staffCourse) { _context.StaffCourse.Remove(staffCourse); }