public int PutExcuse(int AbsenceId, int ByUserId, string Excuse, DateTime EnterDate) { using (ISchoolData Data = new ISchoolData()) { try { DateTime Now = DateTime.Now; Data.isch_Excuses.Add(new isch_Excuses() { e_EnterDate = Now, e_Text = Excuse, e_User = ByUserId, }); Data.SaveChanges(); var SelectedExcuse = Data.isch_Excuses.Where(Excu => (Excu.e_EnterDate == Now && Excu.e_Text == Excuse && Excu.e_User == ByUserId)); if (SelectedExcuse.Count() != 1) { return(0); } var Absence = Data.isch_Absences.Where(abs => abs.a_id == AbsenceId); if (Absence.Count() != 1) { return(0); } Absence.First().a_Excuse = SelectedExcuse.First().e_id; Data.SaveChanges(); return(1); } catch (Exception) { return(-1); } } }
public int PutNotification(int SenderId, string Title, string NotificationBody, int ToUser) { using (ISchoolData Data = new ISchoolData()) { if (Data.isch_Users.Where(Tech => Tech.u_id == SenderId).Count() != 1 || Data.isch_Users.Where(Tech => Tech.u_id == ToUser).Count() != 1) { return(0); } try { Data.isch_NotiFication.Add(new isch_NotiFication() { n_EnterByUser = SenderId, n_title = Title, n_text = NotificationBody, n_ToUser = ToUser, n_EnterDate = DateTime.Now }); Data.SaveChanges(); return(1); } catch (Exception) { return(-1); } } }
/// <summary> /// Creates the test department. /// </summary> /// <param name="_repository">The database.</param> /// <returns></returns> public static DepartmentDTO CreateTestDepartment(ISchoolData _repository) { var departmentName = Guid.NewGuid().ToString(); decimal budget = 1000000; var startDate = DateTime.Today; var obj = new DepartmentDTO(); obj.Name = departmentName; obj.Budget = budget; obj.CreatedDate = startDate; var departments = _repository.GetAllDepartments(); obj.DepartmentID = 1; if (departments != null && departments.Count() > 0) { obj.DepartmentID += departments.Max(x => x.DepartmentID); } obj = _repository.CreateDepartment(obj); return(obj); }
/// <summary> /// Deletes the test object. /// </summary> /// <param name="toDelete">The object to delete.</param> /// <param name="_repository">The repository.</param> public static void DeleteTestObject(CourseDTO toDelete, ISchoolData _repository) { _repository.DeleteCourse(toDelete.CourseID); var originalDepartment = _repository.GetDepartment(toDelete.DepartmentID); if (originalDepartment != null) { DepartmentTest.DeleteTestObject(originalDepartment, _repository); } }
/// <summary> /// Creates the test course. /// </summary> /// <param name="_repository">The repository.</param> /// <returns></returns> public static CourseDTO CreateTestCourse(ISchoolData _repository) { var randomName = Guid.NewGuid().ToString(); var random = new Random(); var credits = random.Next(1, 4); var departmentID = DepartmentTest.CreateTestDepartment(_repository).DepartmentID; var obj = new CourseDTO(); obj.CourseID = 0; obj.Name = randomName; obj.Credits = credits; obj.DepartmentID = departmentID; obj = _repository.CreateCourse(obj); return(obj); }
/// <summary> /// Creates the test Instructor. /// </summary> /// <param name="Repository">The repository.</param> /// <returns></returns> public static InstructorDTO CreateTestInstructor(ISchoolData Repository) { var firstName = "Test"; var lastName = "Subject"; DateTime?hireDate = null; DateTime?HireDate = null; var Instructor = new InstructorDTO(); Instructor.FirstName = firstName; Instructor.LastName = lastName; Instructor.HireDate = hireDate; Instructor.HireDate = HireDate; Instructor.Terminated = false; Instructor = Repository.CreateInstructor(Instructor); return(Instructor); }
public int ChangeStudentPhoneNumber(int StudentId, string PhoneNumber) { using (ISchoolData Data = new ISchoolData()) { try { var Student = Data.isch_Students.Where(stu => stu.st_id == StudentId); if (Student.Count() != 1) { return(0); } Student.First().st_PhoneNumber = PhoneNumber; Data.SaveChanges(); return(1); } catch (Exception) { return(-1); } } }
public int PutAbsence(int StudentId, int AbsenceType, DateTime Date, int Subject) { using (ISchoolData Data = new ISchoolData()) { try { Data.isch_Absences.Add(new isch_Absences() { a_Date = DateTime.Now, a_Student = StudentId, a_Type = AbsenceType, a_Subject = Subject }); Data.SaveChanges(); return(1); } catch (Exception) { return(-1); } } }
public static int GetUnusedCourse(ISchoolData repository) { var courses = repository.GetAllCourses(); for (int ii = 1; ii < Int32.MaxValue; ii++) { bool isUsed = false; foreach (var thing in courses) { if (thing.CourseID.Equals(ii)) { isUsed = true; break; } } if (!isUsed) { return(ii); } } return(0); }
/// <summary> /// Finds an Instructor ID that is not in the system. /// </summary> /// <param name="_repository">The repository.</param> /// <returns></returns> public static int GetUnusedInstructorID(ISchoolData _repository) { var assignments = _repository.GetAllInstructors(); for (int ii = 1; ii < Int32.MaxValue; ii++) { bool isUsed = false; foreach (var assignment in assignments) { if (assignment.InstructorID.Equals(ii)) { isUsed = true; break; } } if (!isUsed) { return(ii); } } return(0); }
public SchoolBusiness(ISchoolData schoolData) { this.schoolData = schoolData; }
public DepartmentController(ISchoolData repository) { Repository = repository; }
public CourseController(ISchoolData repository) { Repository = repository; }
public InstructorController(ISchoolData repository) { Repository = repository; }
/// <summary> /// Deletes the test object. /// </summary> /// <param name="toDelete">The object to delete.</param> /// <param name="_repository">The repository.</param> public static void DeleteTestObject(DepartmentDTO toDelete, ISchoolData _repository) { _repository.DeleteDepartment(toDelete.DepartmentID); }
public StudentController(ISchoolData repository) { Repository = repository; }
/// <summary> /// Deletes the test object. /// </summary> /// <param name="toDelete">The object to delete.</param> public static void DeleteTestInstructor(InstructorDTO toDelete, ISchoolData Repository) { Repository.DeleteInstructor(toDelete.InstructorID); }
public int PutSchedualForStudent(int StudentId, int Sub1, int Sub2, int Sub3, int Sub4, int Sub5, int Sub6, int Sub7, int Sub8) { using (ISchoolData Data = new ISchoolData()) { try { var Student = Data.isch_Students.Where(stu => stu.st_id == StudentId); if (Student.Count() != 1) { return(0); } isch_Schedules Sch = new isch_Schedules(); var Q = Data.isch_Schedules.Where(subj => subj.s_Subject1 == Sub1 && subj.s_Subject2 == Sub2 && subj.s_Subject3 == Sub3 && subj.s_Subject4 == Sub4 && subj.s_Subject5 == Sub5 && subj.s_Subject6 == Sub6 && subj.s_Subject7 == Sub7 && subj.s_Subject8 == Sub8); if (Q.Count() > 0) { Sch = Q.First(); goto Go; } Data.isch_Schedules.Add(new isch_Schedules() { s_Subject1 = Sub1, s_Subject2 = Sub2, s_Subject3 = Sub3, s_Subject4 = Sub4, s_Subject5 = Sub5, s_Subject6 = Sub6, s_Subject7 = Sub7, s_Subject8 = Sub8, }); Data.SaveChanges(); var Q = Data.isch_Schedules.Where(subj => subj.s_Subject1 == Sub1 && subj.s_Subject2 == Sub2 && subj.s_Subject3 == Sub3 && subj.s_Subject4 == Sub4 && subj.s_Subject5 == Sub5 && subj.s_Subject6 == Sub6 && subj.s_Subject7 == Sub7 && subj.s_Subject8 == Sub8); if (Q.Count() > 0) { Sch = Q.First(); } else { return(0); } Go :; Student.First().st_Schedule = Sch.s_id; Data.SaveChanges(); return(1); } catch (Exception) { return(-1); } } }