public void SpecializingIn_WithImageType_UpdatesFileType() { var sut = new Enrollment(); sut.SpecializingIn(FileType.Image); Assert.Equal(FileType.Image, sut.FileType); }
public async Task<IHttpActionResult> PutEnrollment(int id, Enrollment enrollment) { if (!ModelState.IsValid) { return BadRequest(ModelState); } enrollment.EnrollmentID = id; db.Entry(enrollment).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnrollmentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public static Boolean registerStudent(int cCode, int semester_id, int student_id, double year_work, double project_marks, double final_exam, double total_marks) { GradingSys_DataClassesDataContext db = new GradingSys_DataClassesDataContext(); Enrollment enroll = new Enrollment { Course_code = cCode, Semester_id = semester_id, Student_id = student_id, Year_work = (Decimal) year_work, Project_marks = (Decimal) project_marks, Final_exam = (Decimal) final_exam, Total_marks = (Decimal) total_marks }; db.Enrollments.InsertOnSubmit(enroll); // Submit the change to the database. try { db.SubmitChanges(); return true; } catch (Exception e) { Console.WriteLine(e); return false; } }
partial void Enrollments_Validate(Enrollment entity, EntitySetValidationResultsBuilder results) { // If the section has reached the max enrollment limit, show an error if (entity.Section.SpaceRemaining < 0) { results.AddEntityError("This section is full."); } }
private Secretary GetGraduate(Enrollment enrollment) { var enrollments = new List<Enrollment> { enrollment }; var ceremony = new GraduationCeremony(enrollments); var grads = ceremony.GetGraduates(); return grads[0]; }
public ActionResult Create(Enrollment enrollment) { if (ModelState.IsValid) { db.Enrollments.Add(enrollment); db.SaveChanges(); return RedirectToAction("Index"); } return View(enrollment); }
public void AddEnrollment(EnrollmentData enrollmentData) { using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) { var enrollment = new Enrollment { CourseId = enrollmentData.CourseId, StudentId = enrollmentData.StudentId }; con.Enrollments.Add(enrollment); con.SaveChanges(); } }
/// <summary> /// Creates a secretary and enrolls them in the school /// </summary> /// <returns>An entry into the enrollment fluent API</returns> public IEnrollment Enroll() { var enrollment = new Enrollment { FileType = FileType.Default, Secretary = new Secretary(), School = this }; Enrollments.Add(enrollment); return enrollment; }
public void Graduates_GivenEnrollments_ShouldKnowWhatToDo() { var enrollment = new Enrollment { FileType = FileType.File, School = new LocalSchool("TestSchool", @"C:\temp"), Secretary = new Secretary() }; var grad = GetGraduate(enrollment); Assert.Equal("TestSchool", grad.AlmaMater); }
public void SettingEnrollmentFor_WithAnEntity_ShouldChangeToSepcializedSecretary() { var school = new LocalSchool("Test", @"C:\Test"); school.Specializations.Add<TestEntity>(FileType.File, null); var sut = new Enrollment { Secretary = new Secretary(), FileType = FileType.File, School = school }; sut.For<TestEntity>(); var secretary = sut.Secretary as Secretary<TestEntity>; Assert.NotNull(secretary); Assert.Equal(FileType.File, sut.FileType); }
public Enrollment CreateEnrollment() { // <InitializeEnrollment> var classList = new Enrollment() { new Student("Lessie", "Crosby"), new Student("Vicki", "Petty"), new Student("Ofelia", "Hobbs"), new Student("Leah", "Kinney"), new Student("Alton", "Stoker"), new Student("Luella", "Ferrell"), new Student("Marcy", "Riggs"), new Student("Ida", "Bean"), new Student("Ollie", "Cottle"), new Student("Tommy", "Broadnax"), new Student("Jody", "Yates"), new Student("Marguerite", "Dawson"), new Student("Francisca", "Barnett"), new Student("Arlene", "Velasquez"), new Student("Jodi", "Green"), new Student("Fran", "Mosley"), new Student("Taylor", "Nesmith"), new Student("Ernesto", "Greathouse"), new Student("Margret", "Albert"), new Student("Pansy", "House"), new Student("Sharon", "Byrd"), new Student("Keith", "Roldan"), new Student("Martha", "Miranda"), new Student("Kari", "Campos"), new Student("Muriel", "Middleton"), new Student("Georgette", "Jarvis"), new Student("Pam", "Boyle"), new Student("Deena", "Travis"), new Student("Cary", "Totten"), new Student("Althea", "Goodwin") }; // </InitializeEnrollment> return classList; }
/** * Enroll course * * * */ public IList<Enrollment> enrollCourse(long studentId, IList<long> courseIds) { if (session == null || !session.IsOpen) { session = hibernate.getSession(); } //get student and check his/her enrollment first for existing enrollment Student student = session.CreateCriteria<Student>() .Add(Restrictions.Eq("USER_ID", studentId)) .UniqueResult<Student>(); if (student == null) throw new CourseEnrollmentException("Invalid student ID: " + studentId); if(courseIds.Count <= 0) throw new CourseEnrollmentException("No course selected."); IList<Enrollment> enrolledCourses = student.COURSE_ENROLLED; foreach (Enrollment enrolledCourse in enrolledCourses) { if (courseIds.Contains(enrolledCourse.COURSE.COURSE_ID)) throw new CourseEnrollmentException("Student " + studentId + " is already enrolled in course " + enrolledCourse.COURSE.COURSE_NAME); } //get course objects long[] courseIdsArray = courseIds.ToArray(); IList<Course> courses = session.CreateCriteria<Course>() .Add(Restrictions.In("COURSE_ID",courseIdsArray)) .List<Course>(); IList<Enrollment> newEnrollments = new List<Enrollment>(); session.BeginTransaction(); foreach (Course course in courses) { Enrollment newEnrollment = new Enrollment(); newEnrollment.COURSE = course; newEnrollment.STUDENT = student; course.ENROLLMENTS.Add(newEnrollment); student.COURSE_ENROLLED.Add(newEnrollment); session.Save(newEnrollment); session.Save(course); session.Save(student); newEnrollments.Add(newEnrollment); } session.Transaction.Commit(); return newEnrollments; }
public void Setup() { enrollment = new Enrollment(); restClient = new Mock<IRequestExecute>(); param = new Hashtable(); paramValues = new EnrollmentParams(); }
public static void Initialize(ApplicationDbContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Clients.Any()) { return; // DB has been seeded } var clients = new Client[] { new Client { Name = "Carson", surname = "Alexander", Adrress = "Kaunas, Studentu g. 69", Phone = "865265411" }, new Client { Name = "Peter", surname = "Alexander", Adrress = "Kaunas, Petraburgo g. 9", Phone = "865296451" }, new Client { Name = "Sandra", surname = "Bu", Adrress = "Kaunas, Gedimino g. 60", Phone = "865265623" } }; foreach (Client s in clients) { context.Clients.Add(s); } context.SaveChanges(); var teachers = new Teacher[] { new Teacher { Name = "Sandi", Surname = "Leteta", Phone = "8641532" }, new Teacher { Name = "Laura", Surname = "Favelo", Phone = "5120532" }, new Teacher { Name = "Linda", Surname = "Masiozo", Phone = "5631206" }, new Teacher { Name = "Fera", Surname = "Fernendento", Phone = "461532" } }; foreach (Teacher s in teachers) { context.Teachers.Add(s); } context.SaveChanges(); var dances = new Dance[] { new Dance { DanceId = 1050, Title = "Salsa", Price = 30 }, new Dance { DanceId = 4022, Title = "Lombada", Price = 30 }, new Dance { DanceId = 4041, Title = "Valsas", Price = 30 }, new Dance { DanceId = 1045, Title = "Tango", Price = 40 } }; foreach (Dance c in dances) { context.Dances.Add(c); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { ClientId = 1, DanceId = 1050, TeacherId = 1 }, new Enrollment { ClientId = 1, DanceId = 4022, TeacherId = 2 }, new Enrollment { ClientId = 1, DanceId = 4041, TeacherId = 3 }, new Enrollment { ClientId = 2, DanceId = 1050, TeacherId = 1 }, new Enrollment { ClientId = 2, DanceId = 4041, TeacherId = 3 }, new Enrollment { ClientId = 2, DanceId = 1045, TeacherId = 4 }, new Enrollment { ClientId = 3, DanceId = 1050, TeacherId = 1 } }; foreach (Enrollment e in enrollments) { context.Enrollments.Add(e); } context.SaveChanges(); }
public async Task <PromoteStudentResponse> PromoteStudentsAsync(PromoteStudentRequest promoteStudentRequest) { var listStudiesWithName = _studentContext.Studies.Where(s => s.Name == promoteStudentRequest.Studies).ToList(); if (listStudiesWithName.Count() == 0) { return(null); } var idStudy = listStudiesWithName[0].IdStudy; var existsStudiesSemester = _studentContext.Enrollment.Any(e => e.IdStudy == idStudy && e.Semester == promoteStudentRequest.Semester); if (!existsStudiesSemester) { return(null); } var listStudents = (from s in _studentContext.Student join e in _studentContext.Enrollment on s.IdEnrollment equals e.IdEnrollment where e.IdStudy == idStudy && e.Semester == promoteStudentRequest.Semester select s.IndexNumber).ToList(); if (listStudents.Count() == 0) { return(null); } int enrollmentId; var existsStudiesSemesterAdd1 = _studentContext.Enrollment.Any(e => e.IdStudy == idStudy && e.Semester == promoteStudentRequest.Semester + 1); DateTime startDateMade = DateTime.Now; if (!existsStudiesSemesterAdd1) { var e = new Enrollment { Semester = promoteStudentRequest.Semester + 1, IdStudy = idStudy, StartDate = startDateMade, }; _studentContext.Enrollment.Add(e); _studentContext.SaveChanges(); enrollmentId = e.IdEnrollment; } else { var enrollments = _studentContext.Enrollment.Where(e => e.IdStudy == idStudy && e.Semester == promoteStudentRequest.Semester + 1).ToList(); enrollmentId = enrollments[0].IdEnrollment; startDateMade = enrollments[0].StartDate; } foreach (var stu in listStudents) { var updatedStudent = new Student { IndexNumber = stu, IdEnrollment = enrollmentId }; _studentContext.Attach(updatedStudent); _studentContext.Entry(updatedStudent).Property("IdEnrollment").IsModified = true; await _studentContext.SaveChangesAsync(); } var psr = new PromoteStudentResponse { IdEnrollment = enrollmentId, IdStudy = idStudy, Semester = promoteStudentRequest.Semester, StartDate = startDateMade }; return(psr); }
public void AddToEnrollments(Enrollment enrollment) { base.AddObject("Enrollments", enrollment); }
public string EnrollClaims([FromBody] Enrollment enrollment) { return($"TODO: This is where you will receive an enrollment request processing id for example: {Guid.NewGuid()}"); }
public async Task <IActionResult> PutEnrollment([FromRoute] int studentId, [FromRoute] int enrollmentId, [FromBody] Enrollment enrollment) { if (!StudentExists(studentId)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (enrollmentId != enrollment.Id) { return(BadRequest()); } _context.Entry(enrollment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnrollmentExists(enrollmentId)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult Enrolled(Enrollment model) { return(View(model)); }
public static void Initialize(SchoolContext context) { context.Database.EnsureCreated(); if (context.Students.Any()) { return; } var students = new Student[] { new Student { Forenames = "Ntuthuko", Surname = "Nene", Email = "*****@*****.**", DOB = DateTime.Parse("1998-03-22") }, new Student { Forenames = "John", Surname = "Wick", Email = "*****@*****.**", DOB = DateTime.Parse("2001-05-18") }, new Student { Forenames = "Mike", Surname = "Roberts", Email = "*****@*****.**", DOB = DateTime.Parse("1999-11-12") }, new Student { Forenames = "Lango", Surname = "Lubede", Email = "*****@*****.**", DOB = DateTime.Parse("1997-05-12") }, new Student { Forenames = "Rico", Surname = "Mnikathi", Email = "*****@*****.**", DOB = DateTime.Parse("2000-03-18") }, new Student { Forenames = "Mzamo", Surname = "Khanyile", Email = "*****@*****.**", DOB = DateTime.Parse("1999-08-29") }, new Student { Forenames = "Mfundo", Surname = "Sithole", Email = "*****@*****.**", DOB = DateTime.Parse("1996-07-24") }, new Student { Forenames = "Buhle", Surname = "Mbambo", Email = "*****@*****.**", DOB = DateTime.Parse("1998-04-27") }, new Student { Forenames = "Pretty", Surname = "Mkhize", Email = "*****@*****.**", DOB = DateTime.Parse("1999-01-02") }, }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var lectures = new Lecture[] { new Lecture { Forenames = "Ashveer", Surname = "Govender", Email = "*****@*****.**", DOB = DateTime.Parse("1990-07-22"), HireDate = DateTime.Parse("2014-01-05") }, new Lecture { Forenames = "Lindokuhle", Surname = "Nene", Email = "*****@*****.**", DOB = DateTime.Parse("1994-07-09"), HireDate = DateTime.Parse("2006-01-05") }, new Lecture { Forenames = "Asiphe", Surname = "Khumalo", Email = "*****@*****.**", DOB = DateTime.Parse("1989-09-22"), HireDate = DateTime.Parse("2011-01-05") }, new Lecture { Forenames = "Nelly", Surname = "Bhengu", Email = "*****@*****.**", DOB = DateTime.Parse("1984-08-22"), HireDate = DateTime.Parse("2012-01-05") }, new Lecture { Forenames = "Andile", Surname = "Dazela", Email = "*****@*****.**", DOB = DateTime.Parse("1970-02-03"), HireDate = DateTime.Parse("2002-01-05") }, }; foreach (Lecture lecture in lectures) { context.Lectures.Add(lecture); } context.SaveChanges(); var degree = new Degree[] { new Degree { DegreeName = "Computer Science", Duration = "4 years", LectureId = lectures.Single(i => i.Surname == "Govender").Id, Lecture = "Ashveer Govender" }, new Degree { DegreeName = "Information Technology", Duration = "3 years", LectureId = lectures.Single(i => i.Surname == "Nene").Id, Lecture = "Lindokuhle Nene" }, new Degree { DegreeName = "Plant Manager", Duration = "3 years", LectureId = lectures.Single(i => i.Surname == "Khumalo").Id, Lecture = "Asiphe Khumalo" }, new Degree { DegreeName = "Civil Engineer", Duration = "6 years", LectureId = lectures.Single(i => i.Surname == "Bhengu").Id, Lecture = "Nelly Bhengu" }, new Degree { DegreeName = "IT Management", Duration = "5 years", LectureId = lectures.Single(i => i.Surname == "Dazela").Id, Lecture = "Andile Dazela" }, }; foreach (Degree Degree in degree) { context.Degree.Add(Degree); } context.SaveChanges(); var courses = new Course[] { new Course { CourseId = 101, Title = "Web Page Design", Credits = 10, DegreeId = degree.Single(s => s.DegreeName == "Information Technology").DegreeId }, new Course { CourseId = 102, Title = "Development Software", Credits = 10, DegreeId = degree.Single(s => s.DegreeName == "Computer Science").DegreeId }, new Course { CourseId = 103, Title = "Projects", Credits = 5, DegreeId = degree.Single(s => s.DegreeName == "Plant Manager").DegreeId }, new Course { CourseId = 104, Title = "Hydrology", Credits = 10, DegreeId = degree.Single(s => s.DegreeName == "Civil Engineer").DegreeId }, new Course { CourseId = 105, Title = "Security Manaager", Credits = 10, DegreeId = degree.Single(s => s.DegreeName == "IT Management").DegreeId }, }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var officeAssignments = new OfficeAssignment[] { new OfficeAssignment { LectureId = lectures.Single(i => i.Surname == "Govender").Id, Location = "Durban" }, new OfficeAssignment { LectureId = lectures.Single(i => i.Surname == "Nene").Id, Location = "Cape Town" }, new OfficeAssignment { LectureId = lectures.Single(i => i.Surname == "Khumalo").Id, Location = "Pretora" }, }; foreach (OfficeAssignment oa in officeAssignments) { context.OfficeAssignments.Add(oa); } context.SaveChanges(); var courseLectures = new CourseAsssignment[] { new CourseAsssignment { CourseId = courses.Single(c => c.Title == "Web Page Design").CourseId, LectureId = lectures.Single(i => i.Surname == "Govender").Id }, new CourseAsssignment { CourseId = courses.Single(c => c.Title == "Development Software").CourseId, LectureId = lectures.Single(i => i.Surname == "Nene").Id }, new CourseAsssignment { CourseId = courses.Single(c => c.Title == "Projects").CourseId, LectureId = lectures.Single(i => i.Surname == "Khumalo").Id }, new CourseAsssignment { CourseId = courses.Single(c => c.Title == "Hydrology").CourseId, LectureId = lectures.Single(i => i.Surname == "Dazela").Id }, new CourseAsssignment { CourseId = courses.Single(c => c.Title == "Security Manaager").CourseId, LectureId = lectures.Single(i => i.Surname == "Bhengu").Id }, }; foreach (CourseAsssignment ci in courseLectures) { context.CourseAsssignments.Add(ci); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentId = students.Single(s => s.Surname == "Nene").Id, CourseId = courses.Single(c => c.Title == "Web Page Design").CourseId, Grade = Grade.A }, new Enrollment { StudentId = students.Single(s => s.Surname == "Wick").Id, CourseId = courses.Single(c => c.Title == "Projects").CourseId, Grade = Grade.B }, new Enrollment { StudentId = students.Single(s => s.Surname == "Roberts").Id, CourseId = courses.Single(c => c.Title == "Hydrology").CourseId, Grade = Grade.A }, new Enrollment { StudentId = students.Single(s => s.Surname == "Lubede").Id, CourseId = courses.Single(c => c.Title == "Security Manaager").CourseId, Grade = Grade.C }, new Enrollment { StudentId = students.Single(s => s.Surname == "Mnikathi").Id, CourseId = courses.Single(c => c.Title == "Projects").CourseId, Grade = Grade.A }, new Enrollment { StudentId = students.Single(s => s.Surname == "Khanyile").Id, CourseId = courses.Single(c => c.Title == "Development Software").CourseId, Grade = Grade.B }, }; foreach (Enrollment e in enrollments) { var enrollmentInDatabase = context.Enrollments.Where( s => s.StudentId == e.StudentId && s.Course.CourseId == e.CourseId).SingleOrDefault(); if (enrollmentInDatabase == null) { context.Enrollments.Add(e); } context.Enrollments.Add(e); } context.SaveChanges(); }
public async Task <ViewResult> DatabaseOperations() { // CREATE operation /*Company MyCompany = new Company(); * MyCompany.symbol = "MCOB"; * MyCompany.name = "ISM"; * MyCompany.date = "ISM"; * MyCompany.isEnabled = true; * MyCompany.type = "ISM"; * MyCompany.iexId = "ISM"; * * Quote MyCompanyQuote1 = new Quote(); * //MyCompanyQuote1.EquityId = 123; * MyCompanyQuote1.date = "11-23-2018"; * MyCompanyQuote1.open = 46.13F; * MyCompanyQuote1.high = 47.18F; * MyCompanyQuote1.low = 44.67F; * MyCompanyQuote1.close = 47.01F; * MyCompanyQuote1.volume = 37654000; * MyCompanyQuote1.unadjustedVolume = 37654000; * MyCompanyQuote1.change = 1.43F; * MyCompanyQuote1.changePercent = 0.03F; * MyCompanyQuote1.vwap = 9.76F; * MyCompanyQuote1.label = "Nov 23"; * MyCompanyQuote1.changeOverTime = 0.56F; * MyCompanyQuote1.symbol = "MCOB"; * MyCompanyQuote1.company = MyCompany; * * * Quote MyCompanyQuote2 = new Quote(); * //MyCompanyQuote1.EquityId = 123; * MyCompanyQuote2.date = "11-23-2018"; * MyCompanyQuote2.open = 46.13F; * MyCompanyQuote2.high = 47.18F; * MyCompanyQuote2.low = 44.67F; * MyCompanyQuote2.close = 47.01F; * MyCompanyQuote2.volume = 37654000; * MyCompanyQuote2.unadjustedVolume = 37654000; * MyCompanyQuote2.change = 1.43F; * MyCompanyQuote2.changePercent = 0.03F; * MyCompanyQuote2.vwap = 9.76F; * MyCompanyQuote2.label = "Nov 23"; * MyCompanyQuote2.changeOverTime = 0.56F; * MyCompanyQuote2.symbol = "MCOB"; * MyCompanyQuote2.company = MyCompany; * * dbContext.Companies.Add(MyCompany); * dbContext.Quotes.Add(MyCompanyQuote1); * dbContext.Quotes.Add(MyCompanyQuote2); */ Student student = new Student(); // student.studentID = 1; student.studentName = "Shiva"; Course course = new Course(); // course.courseID = 1; course.courseName = "Distributed systems"; Enrollment enrollment = new Enrollment(); enrollment.course = course; enrollment.student = student; //enrollment.enrollmentID = 1; //enrollment.course.courseID = 1; //enrollment.student.studentID = 1; enrollment.grade = "A"; dbContext.Students.Add(student); dbContext.Courses.Add(course); dbContext.Enrollments.Add(enrollment); dbContext.SaveChanges(); /* // READ operation * Company CompanyRead1 = dbContext.Companies * .Where(c => c.symbol == "MCOB") * .First(); * * Company CompanyRead2 = dbContext.Companies * .Include(c => c.Quotes) * .Where(c => c.symbol == "MCOB") * .First(); * * // UPDATE operation * CompanyRead1.iexId = "MCOB"; * dbContext.Companies.Update(CompanyRead1); * //dbContext.SaveChanges(); * await dbContext.SaveChangesAsync();*/ // DELETE operation //dbContext.Companies.Remove(CompanyRead1); //await dbContext.SaveChangesAsync(); return(View(student)); }
public static void Initialize(SchoolContext context) { context.Database.EnsureCreated(); //=========STUDENTS==========// if (context.Students.Any()) { return; } var students = new Student[] { new Student { FirstName = "Carson", LastName = "Alexander", Email = "*****@*****.**", EnrollmentDate = DateTime.Parse("2017-09-01"), Address = "4 Flanders Court", City = "Moncton", Province = "NB", PostalCode = "E1C 8H1" }, new Student { FirstName = "Carson2", LastName = "Alexander2", Email = "*****@*****.**", EnrollmentDate = DateTime.Parse("2017-09-01"), Address = "4 Flanders Court", City = "Moncton", Province = "NB", PostalCode = "E1C 8H1" } }; foreach (Student i in students) { context.Students.Add(i); } context.SaveChanges(); //=====instruct var instructors = new Instructor[] { new Instructor { FirstName = "bob", LastName = "bob", Email = "*****@*****.**", HireDate = DateTime.Parse("2017-09-01"), Address = "4 Flanders Court", City = "Moncton", Province = "NB", PostalCode = "E1C 8H1" }, new Instructor { FirstName = "bobob", LastName = "bobob", Email = "*****@*****.**", HireDate = DateTime.Parse("2017-09-01"), Address = "4 Flanders Court", City = "Moncton", Province = "NB", PostalCode = "E1C 8H1" }, }; foreach (Instructor i in instructors) { context.Istructors.Add(i); } context.SaveChanges(); //==========COURSES===========// var courses = new Course[] { new Course { CourseID = 1050, Title = "Chemestry", Credits = 3 }, new Course { CourseID = 1040, Title = "Chemestry2", Credits = 3 }, }; foreach (Course c in courses) { context.Add(c); } context.SaveChanges(); //===================================Enrollment===============================// var enrollments = new Enrollment[] { new Enrollment { CourseID = 1050, StudentID = students.Single(s => s.LastName == "Alexander").ID, Grade = Grade.A }, new Enrollment { CourseID = 4022, StudentID = students.Single(s => s.LastName == "Alexander2").ID, Grade = Grade.B } }; foreach (Enrollment e in enrollments) { context.Enrollments.Add(e); } //save context context.SaveChanges(); }
public IActionResult PromoteStudent(Enrollment enrollment) { Enrollment en = service.PromoteStudent(enrollment); return(Ok(en)); }
public IActionResult Save(EnrollmentFormViewModel efvm) { if (!ModelState.IsValid) { var message = string.Join(" | ", ModelState.Values .SelectMany(v => v.Errors) .Select(e => e.ErrorMessage)); TempData["ErrorMessage"] = "Κάτι πήγε στραβά: " + message + " . Παρακαλώ δοκιμάστε ξανά αργότερα."; return(RedirectToAction("Index", "Enrollment")); } if (efvm.Id == 0) { Enrollment enrollmentInDb = new Enrollment { StudentId = efvm.Student.Id, AcademicPeriodId = efvm.AcademicPeriod.Id, DateAdded = DateTime.Today }; try { context.Enrollments.Add(enrollmentInDb); context.SaveChanges(); } catch (Exception ex) { TempData["ErrorMessage"] = ex.Message; } var selectedCourses = efvm.Courses.Where(ef => ef.Checked).Select(ef => ef.Course.Id).ToList(); var enrollment = context .Enrollments .Where(e => e.StudentId == enrollmentInDb.StudentId) .Where(e => e.AcademicPeriodId == enrollmentInDb.AcademicPeriodId) .Single(); foreach (var course in selectedCourses) { Grade grade = new Grade { CourseId = course, EnrollmentId = enrollment.Id }; context.Grades.Add(grade); } } else { var enrollment = context.Enrollments.FirstOrDefault(e => e.Id == efvm.Id); if (enrollment == null) { TempData["ErrorMessage"] = "Η Δήλωση δε βρέθηκε!"; return(RedirectToAction("Index", "Enrollment")); } context.Grades.RemoveRange(context.Grades.Where(g => g.EnrollmentId == efvm.Id)); context.SaveChanges(); var selectedCourses = efvm.Courses.Where(ef => ef.Checked).Select(ef => ef.Course.Id).ToList(); foreach (var course in selectedCourses) { Grade grade = new Grade { CourseId = course, EnrollmentId = enrollment.Id }; context.Grades.Add(grade); } } try { context.SaveChanges(); TempData["SuccessMessage"] = "Η Δήλωση στάλθηκε στη Γραμματεία."; } catch (Exception ex) { TempData["ErrorMessage"] = "Κάτι πήγε στραβά: " + ex.Message + " " + ex.InnerException + " . Παρακαλώ δοκιμάστε ξανά αργότερα."; } return(RedirectToAction("Index", "Enrollment")); }
public async Task <EnrollStudentResponse> EnrollStudentAsync(EnrollStudentRequest request) { var studiesExists = _studentContext.Studies.Any(s => s.Name == request.Studies); if (!studiesExists) { return(null); } var studiesList = _studentContext.Studies.Where(s => s.Name == request.Studies).ToList(); int idStudy = studiesList[0].IdStudy; int enrollmentID = 1; var enrollmentExists = _studentContext.Enrollment.Any(e => e.IdStudy == idStudy && e.Semester == 1); if (enrollmentExists) { var enrollmentsList = _studentContext.Enrollment.Where(e => e.IdStudy == idStudy && e.Semester == 1).ToList(); enrollmentID = enrollmentsList[0].IdEnrollment; } else { var e = new Enrollment { Semester = 1, IdStudy = idStudy, StartDate = DateTime.Now }; _studentContext.Enrollment.Add(e); _studentContext.SaveChanges(); enrollmentID = e.IdEnrollment; } var studentExists = _studentContext.Student.Any(s => s.IndexNumber == request.IndexNumber); if (studentExists) { return(null); } var isq = new InsertStudentRequest { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, BirthDate = request.BirthDate, IdEnrollment = enrollmentID }; await AddStudentAsync(isq); var enrollStudentList = _studentContext.Enrollment.Where(e => e.IdEnrollment == enrollmentID).ToList(); var esr = new EnrollStudentResponse { IdEnrollment = enrollStudentList[0].IdEnrollment, IdStudy = enrollStudentList[0].IdStudy, Semester = enrollStudentList[0].Semester, StartDate = enrollStudentList[0].StartDate }; return(esr); }
public static void Initialize(SchoolContext context) { // context.Database.EnsureCreated(); // Look for any students. if (context.StudentSQL.Any()) { return; // DB has been seeded } var students = new Student[] { new Student { FirstName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2005-09-01"), StudentID = new Guid("b53bccee-43ff-4901-8885-7037cee0596f") }, new Student { FirstName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2002-09-01"), StudentID = new Guid("41e90dca-e540-48fa-b4d7-056bbd05d97a") }, new Student { FirstName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2003-09-01"), StudentID = new Guid("d5234f6b-6448-4477-8c87-4cf93a0251ca") }, new Student { FirstName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2002-09-01"), StudentID = new Guid("9dadea32-071a-4eae-9fde-668f24cc29e3") }, new Student { FirstName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2002-09-01"), StudentID = new Guid("062a7700-f165-4418-ae1f-ecf2f061a7e1") }, new Student { FirstName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2001-09-01"), StudentID = new Guid("5c6e5715-7c1b-4629-a421-fcc3ac0567fb") }, new Student { FirstName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2003-09-01"), StudentID = new Guid("090f4511-a07c-42ab-8c54-225d0ab7942c") }, new Student { FirstName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01"), StudentID = new Guid("182609f6-6f65-404c-830c-bf803c774f93") } }; foreach (Student s in students) { context.StudentSQL.Add(s); } context.SaveChanges(); var courses = new Course[] { new Course { CourseID = new Guid("16c80884-8564-4f2b-9a56-e37a857cd8f4"), Title = "Chemistry", Credits = 3 }, new Course { CourseID = new Guid("912574b1-2a7c-48b6-95c7-bc192c9ff74b"), Title = "Microeconomics", Credits = 3 }, new Course { CourseID = new Guid("412d459e-5184-45df-a761-6e6ad7c4f6a0"), Title = "Macroeconomics", Credits = 3 }, new Course { CourseID = new Guid("7d8268cb-2040-4d24-8db6-db3acae802da"), Title = "Calculus", Credits = 4 }, new Course { CourseID = new Guid("1e05b2af-c122-4d8d-8414-c346f25d5e4d"), Title = "Trigonometry", Credits = 4 }, new Course { CourseID = new Guid("fe5642a6-43a2-47bb-b7e0-f2798dd49b31"), Title = "Composition", Credits = 3 }, new Course { CourseID = new Guid("43ea5305-eb70-483e-9a35-a0f655cfc8b1"), Title = "Literature", Credits = 4 } }; foreach (Course c in courses) { context.CourseSQL.Add(c); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentID = new Guid("b53bccee-43ff-4901-8885-7037cee0596f"), CourseID = new Guid("16c80884-8564-4f2b-9a56-e37a857cd8f4"), Grade = Grade.A }, new Enrollment { StudentID = new Guid("b53bccee-43ff-4901-8885-7037cee0596f"), CourseID = new Guid("912574b1-2a7c-48b6-95c7-bc192c9ff74b"), Grade = Grade.C }, new Enrollment { StudentID = new Guid("b53bccee-43ff-4901-8885-7037cee0596f"), CourseID = new Guid("412d459e-5184-45df-a761-6e6ad7c4f6a0"), Grade = Grade.B }, new Enrollment { StudentID = new Guid("41e90dca-e540-48fa-b4d7-056bbd05d97a"), CourseID = new Guid("7d8268cb-2040-4d24-8db6-db3acae802da"), Grade = Grade.B }, new Enrollment { StudentID = new Guid("41e90dca-e540-48fa-b4d7-056bbd05d97a"), CourseID = new Guid("1e05b2af-c122-4d8d-8414-c346f25d5e4d"), Grade = Grade.F }, new Enrollment { StudentID = new Guid("182609f6-6f65-404c-830c-bf803c774f93"), CourseID = new Guid("fe5642a6-43a2-47bb-b7e0-f2798dd49b31"), Grade = Grade.F }, new Enrollment { StudentID = new Guid("d5234f6b-6448-4477-8c87-4cf93a0251ca"), CourseID = new Guid("16c80884-8564-4f2b-9a56-e37a857cd8f4"), Grade = Grade.B }, new Enrollment { StudentID = new Guid("9dadea32-071a-4eae-9fde-668f24cc29e3"), CourseID = new Guid("16c80884-8564-4f2b-9a56-e37a857cd8f4"), Grade = Grade.B }, new Enrollment { StudentID = new Guid("9dadea32-071a-4eae-9fde-668f24cc29e3"), CourseID = new Guid("43ea5305-eb70-483e-9a35-a0f655cfc8b1"), Grade = Grade.F }, new Enrollment { StudentID = new Guid("062a7700-f165-4418-ae1f-ecf2f061a7e1"), CourseID = new Guid("412d459e-5184-45df-a761-6e6ad7c4f6a0"), Grade = Grade.C }, new Enrollment { StudentID = new Guid("5c6e5715-7c1b-4629-a421-fcc3ac0567fb"), CourseID = new Guid("7d8268cb-2040-4d24-8db6-db3acae802da"), Grade = Grade.B }, new Enrollment { StudentID = new Guid("090f4511-a07c-42ab-8c54-225d0ab7942c"), CourseID = new Guid("1e05b2af-c122-4d8d-8414-c346f25d5e4d"), Grade = Grade.A }, }; foreach (Enrollment e in enrollments) { context.EnrollmentSQL.Add(e); } context.SaveChanges(); var user = new User[] { new User { Id = new Guid(), Password = "******", Username = "******" } }; foreach (var item in user) { context.UserSQL.Add(item); } context.SaveChanges(); }
// [Authorize(Roles = "Admin")] public ActionResult Create(Enrollment enrollment) { _context.Enrollments.Add(enrollment); _context.SaveChanges(); return(RedirectToAction("Index")); }
public void GetUsersNotBelongingToGroupTestPositive() { // Arrange // The group, not belonging to it users must be returned by test method var group = new Group { Id = 111, Course = new Course { Id = 222 }, OwnerId = 333, CourseId = 222 }; var role1 = new Role { Name = "Student" }; var role2 = new Role { Name = "AnotherRole" }; // On the exit must be this user with this enrollment // Enrollment to return var enrollment = new Enrollment { GroupId = 100, Group = new Group { Course = new Course { Id = 100 } } }; // User to return var user = new User { Id = 100, Roles = new List <Role> { role1 }, Enrollments = new List <Enrollment> { enrollment } }; enrollment.User = user; // User to test "u.Id != group.OwnerId" condition in Service var user1 = new User { Id = 333, Roles = new List <Role> { role1 }, Enrollments = new List <Enrollment> { enrollment } }; // User to test "u.Enrollments.Select(e => e.Group.Course).FirstOrDefault(c => c.Id == course.Id) == null" // condition in Service var enrollment2 = new Enrollment { GroupId = 100, Group = new Group { Course = new Course { Id = 222 } } }; var user2 = new User { Id = 333, Roles = new List <Role> { role1 }, Enrollments = new List <Enrollment> { enrollment2 } }; // User to test "!usersCurrentlyInGroup.Any(u2 => u2.Id == u.Id)" condition var user3 = new User { Id = 333, Roles = new List <Role> { role1 }, Enrollments = new List <Enrollment> { enrollment2 } }; // User to test "u.Roles.Select(r => r.Name).Contains("Student")" condition var user4 = new User { Id = 333, Roles = new List <Role> { role2 }, Enrollments = new List <Enrollment> { enrollment2 } }; // For enrollmentRepository to return var enrollments = new List <Enrollment>(new Enrollment[] { enrollment, new Enrollment { GroupId = 111, User = user1 } }).AsQueryable(); var users = (new List <User> { user, user1, user2, user3, user4 }).AsQueryable(); var groupRepository = new Mock <IRepository <Group> >(); unitOfWork.Setup(x => x.GroupRepository).Returns(groupRepository.Object); groupRepository.Setup(x => x.GetById(group.Id)).Returns(group); enrollmentRepository.Setup(x => x.GetAll()).Returns(enrollments); var userRepository = new Mock <IUserRepository>(); unitOfWork.Setup(x => x.UserRepository).Returns(userRepository.Object); userRepository.Setup(x => x.GetAll()).Returns(users); // Act var result = enrollmentService.GetUsersNotBelongingToGroup(group.Id); // Assert Assert.IsTrue(result.TrueForAll(u => u.Roles.Select(r => r.Name).Contains("Student")), "User should have the Student role"); Assert.IsTrue(result.TrueForAll(u => !u.Enrollments.Any(e => e.GroupId == group.Id)), "User shouldn't be in that group"); Assert.IsTrue(result.TrueForAll(u => !u.Enrollments.Any(e => e.Group.CourseId == group.CourseId)), "User shouldn't be in the course that contains given group"); Assert.IsTrue(result.TrueForAll(u => u.Id != group.OwnerId)); }
public void CreateEnrollment(Enrollment enrollment) { Database.Enrollments.Add(enrollment); }
public ActionResult AddEvent(Event model) { List <string> ListaTypow = new List <string>(); ListaTypow.Add("platne"); ListaTypow.Add("bezplatne"); ViewBag.TypyWydarzen = new SelectList(ListaTypow); List <string> ListaMiast = new List <string>(); ListaMiast.Add("Augustów"); ListaMiast.Add("Bialystok"); ListaMiast.Add("Choroszcz"); ListaMiast.Add("Chrzanowo"); ListaMiast.Add("Dotnetowo"); ListaMiast.Add("Katowice"); ListaMiast.Add("Kieliszkowo"); ListaMiast.Add("Kraków"); ListaMiast.Add("Lublin"); ListaMiast.Add("Łódz"); ListaMiast.Add("Opole"); ListaMiast.Add("Siedlce"); ListaMiast.Add("Suwalki"); ListaMiast.Add("Warszawa"); ListaMiast.Add("Wroclaw"); ListaMiast.Add("Zakopane"); ViewBag.Miasta = new SelectList(ListaMiast); bool Status = false; string message = ""; if (ModelState.IsValid) { var isExist = IsEventExists(model.Name); if (isExist) { ModelState.AddModelError("NameExist", "Taka nazwa już istnieje!"); return(View(model)); } if (DateTime.Compare(model.Date, DateTime.Now) < 0) { ModelState.AddModelError("ToErly", "Nie wiedziałem, że potrafisz się cofać w czasie"); return(View(model)); } using (MyDatabaseEntities db = new MyDatabaseEntities()) { model.OrganiserEmail = HttpContext.User.Identity.Name; db.Events.Add(model); db.SaveChanges(); } using (MyDatabaseEntities db = new MyDatabaseEntities()) { int eveID = db.Events.Max(a => a.EventId); var eve = db.Events.Where(a => a.EventId == eveID).FirstOrDefault(); var user = db.Users.Where(a => a.EmailID == HttpContext.User.Identity.Name).FirstOrDefault(); Enrollment env = new Enrollment(); env.User = user; env.Event = eve; db.Enrollments.Add(env); db.SaveChanges(); message = "Dodanie nowego Eventu powiodło się!"; Status = true; } } else { message = "Invalid Request"; } ViewBag.Status = Status; ViewBag.Message = message; return(View(model)); }
public void UpdateEnrollment(Enrollment enrollment) { Database.Entry(enrollment).State = Microsoft.EntityFrameworkCore.EntityState.Modified; }
private void DetachEnrollments(Enrollment entity) { this.OnPropertyChanging(); entity.Course = null; }
public IActionResult Delete(int?Id) { Enrollment model = _Enrollment.GetEnrollment(Id); return(View(model)); }
public static Enrollment CreateEnrollment(int ID, byte[] rowVersion, int enrollment_Section, int enrollment_Student) { Enrollment enrollment = new Enrollment(); enrollment.Id = ID; enrollment.RowVersion = rowVersion; enrollment.Enrollment_Section = enrollment_Section; enrollment.Enrollment_Student = enrollment_Student; return enrollment; }
protected override void Seed(UniversityContext context) { var courses = new Course[] { new Course { CourseId = 1050, Name = ".NET", Credits = 30 }, new Course { CourseId = 1051, Name = "Java", Credits = 25 }, new Course { CourseId = 901, Name = "Office 365", Credits = 35 } }; context.Courses.AddRange(courses); context.SaveChanges(); var students = new Student[] { new Student { FirstName = "Adam", LastName = "Bertilsson" }, new Student { FirstName = "Berit", LastName = "Andersson" }, new Student { FirstName = "Cecilia", LastName = "Bengtsson" }, new Student { FirstName = "David", LastName = "Carlsson" } }; context.Students.AddRange(students); context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentId = students[0].Id, CourseId = 1050, EnrollmentDate = DateTime.Parse("2017-01-12"), Grade = Grade.A }, new Enrollment { StudentId = students[1].Id, CourseId = 1050, EnrollmentDate = DateTime.Parse("2017-02-10"), Grade = Grade.A }, new Enrollment { StudentId = students[2].Id, CourseId = 1051, EnrollmentDate = DateTime.Parse("2017-02-11"), Grade = Grade.B }, new Enrollment { StudentId = students[2].Id, CourseId = 901, EnrollmentDate = DateTime.Parse("2017-02-12"), Grade = Grade.C }, new Enrollment { StudentId = students[3].Id, CourseId = 901, EnrollmentDate = DateTime.Today, Grade = Grade.A }, new Enrollment { StudentId = students[1].Id, CourseId = 1051, EnrollmentDate = DateTime.Today, Grade = Grade.F } }; context.Enrollments.AddRange(enrollments); context.SaveChanges(); }
public ViewResult DisplayFirstName() { Enrollment m = new Enrollment { FirstName = "Umais", LastName = "Siddiqui" }; var result = m.DisplayFirstName(); return View("TestExtension", (object)String.Format("Your First Name is : {0}", result)); }
public ActionResult Create([Bind(Include = "Id,grade,group,streamId")] bool another, Enrollment10to12ViewModel enrollment10to12ViewModel) { string userId = User.Identity.GetUserId(); var user = db.Managers.Find(userId); if (!ModelState.IsValid) { var streamList = new List <SelectListItem>(); var streamQuery = from e in user.school.Streams where e.name != "Grade 8 & 9" select e; foreach (var m in streamQuery) { streamList.Add(new SelectListItem { Value = (m.Id).ToString(), Text = m.name }); } ViewBag.streamlist = streamList; return(View(enrollment10to12ViewModel)); } if (ModelState.IsValid) { var StrId = Convert.ToInt64(enrollment10to12ViewModel.streamId); var stream = user.school.Streams.ToList().Find(p => p.Id == StrId); enrollment10to12ViewModel.group = enrollment10to12ViewModel.group.ToUpper(); var exist = stream.enrollments.ToList().Find(p => p.grade == enrollment10to12ViewModel.grade && p.group == enrollment10to12ViewModel.group); if (exist != null) { ModelState.AddModelError("", "Grade " + enrollment10to12ViewModel.grade + enrollment10to12ViewModel.group + " already exists."); var streamList = new List <SelectListItem>(); var streamQuery = from e in user.school.Streams where e.name != "Grade 8 & 9" select e; foreach (var m in streamQuery) { streamList.Add(new SelectListItem { Value = (m.Id).ToString(), Text = m.name }); } ViewBag.streamlist = streamList; return(View(enrollment10to12ViewModel)); } var enrollment = new Enrollment { grade = enrollment10to12ViewModel.grade, group = enrollment10to12ViewModel.group, stream = stream }; foreach (var i in stream.subjects) { var subject = new EnrollmentSubject { name = i.name, Enrollment = enrollment }; db.EnrollmentSubjects.Add(subject); } db.Enrollments.Add(enrollment); db.SaveChanges(); if (another == true) { return(RedirectToAction("Create")); } return(RedirectToAction("Index", "Home")); } return(View(enrollment10to12ViewModel)); }
public ActionResult NewEnrollment(CohortEnrollmentViewModel form) { if (!ModelState.IsValid) { return View(form); } var user = _context.Users.Single(u => u.Id == form.UserId); var passedDate = form.PassedDate ?? DateTime.Parse("1900-1-1"); var cohortId = Convert.ToInt32(form.CohortId); var cohort = _context.Courses.Single(c => c.Id == cohortId); var newEnrollment = new Enrollment(user, passedDate, cohort); _context.Enrollments.Add(newEnrollment); _context.SaveChanges(); var enrollmentId = newEnrollment.Id; var enr = _context.Enrollments.Find(enrollmentId); _context.Courses.Find(enr.Course.Id); EnrollmentServices.CreateScoRecordsForCourse(enr, _context); _context.SaveChanges(); var id = cohortId; return RedirectToAction("Enrollments", "Courses", new { id }); }
public static void Initialize(MainContext context) { // Look for any enrollments if (context.Enrollments.Any()) { return; // DB has been seeded } var enrollments = new Enrollment[] { new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Alexander").ID, CourseID = context.Courses.Single(c => c.Title == "Chemistry").CourseID, Grade = Grade.A }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Alexander").ID, CourseID = context.Courses.Single(c => c.Title == "Microeconomics").CourseID, Grade = Grade.C }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Alexander").ID, CourseID = context.Courses.Single(c => c.Title == "Macroeconomics").CourseID, Grade = Grade.B }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Alonso").ID, CourseID = context.Courses.Single(c => c.Title == "Calculus").CourseID, Grade = Grade.B }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Alonso").ID, CourseID = context.Courses.Single(c => c.Title == "Trigonometry").CourseID, Grade = Grade.B }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Alonso").ID, CourseID = context.Courses.Single(c => c.Title == "Composition").CourseID, Grade = Grade.B }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Anand").ID, CourseID = context.Courses.Single(c => c.Title == "Chemistry").CourseID }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Anand").ID, CourseID = context.Courses.Single(c => c.Title == "Microeconomics").CourseID, Grade = Grade.B }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Barzdukas").ID, CourseID = context.Courses.Single(c => c.Title == "Chemistry").CourseID, Grade = Grade.B }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Li").ID, CourseID = context.Courses.Single(c => c.Title == "Composition").CourseID, Grade = Grade.B }, new Enrollment { StudentID = context.Students.Single(s => s.LastName == "Justice").ID, CourseID = context.Courses.Single(c => c.Title == "Literature").CourseID, Grade = Grade.B } }; foreach (Enrollment e in enrollments) { var enrollmentInDataBase = context.Enrollments.Where( s => s.Student.ID == e.StudentID && s.Course.CourseID == e.CourseID).SingleOrDefault(); if (enrollmentInDataBase == null) { context.Enrollments.Add(e); } } context.SaveChanges(); }
public void Setup() { enrollment = new Enrollment(); BaseTestClass.SetConfiguration(); EnrollmentInput = "{'enrollment_npi': { 'payer_id': '00074', 'endpoint': 'coverage', 'effective_date': '2012-12-24', 'facility_name': 'Quality', 'provider_name': 'Jane Austen', 'tax_id': '12345678', 'address': '125 Snow Shoe Road', 'city': 'Sacramento', 'state': 'CA', 'zip': '94107', 'ptan': '54321', 'medicaid_id': '22222', 'npi': '1234567890', 'authorized_signer': { 'title': 'title', 'first_name': 'Lorem', 'last_name': 'Ipsum', 'contact_number': '1478963250', 'email': '*****@*****.**', 'signature': { 'coordinates': [{ 'lx': 47, 'ly': 9, 'mx': 47, 'my': 8 }, { 'lx': 46, 'ly': 8, 'mx': 47, 'my': 9 }] } } } }"; }
protected void EnrollButton_Click(object sender, EventArgs e) { for (int i = 0; i < ClassInfo.Rows.Count; i++) { int classID = Convert.ToInt32(ClassInfo.Rows[i].Cells[0].Text); CheckBox checkbox = (CheckBox)ClassInfo.Rows[i].FindControl("enrollBox"); if (checkbox.Checked) { IQueryable<WebApplication1.HalonModels.Firefighter> ffquery = _db.Firefighters; string firefighter_UName = Page.User.Identity.Name; ffquery = ffquery.Where(f => f.Firefighter_Account_Username.Equals(firefighter_UName)); Enrollment enroll = new Enrollment(); enroll.Class_ID = classID; enroll.Firefighter_ID = ffquery.FirstOrDefault().Firefighter_ID; _db.Enrollments.Add(enroll); _db.SaveChanges(); Response.Redirect("~/User/Class/ClassestoDate.aspx"); } } }
public static EnrollmentService GenerateModel() { var random = new Random(5757); var typeFactors = new Dictionary<Type, int>() { { typeof(EnrollmentService), 5 }, { typeof(Service), 1 }, { typeof(Provider), 1 }, { typeof(Client), 50000 }, { typeof(Program), 20 }, { typeof(Note), 1000 }, { typeof(Doc), 1000 }, { typeof(Contact), 500 }, { typeof(User), 1200 }, { typeof(ClientCareSetting), 1000 } }; var entities = new Dictionary<Type, List<object>>() { { typeof(EnrollmentService), new List<object>() }, { typeof(Enrollment), new List<object>() }, { typeof(Service), new List<object>() }, { typeof(Provider), new List<object>() }, { typeof(Client), new List<object>() }, { typeof(Program), new List<object>() }, { typeof(Note), new List<object>() }, { typeof(Doc), new List<object>() }, { typeof(Contact), new List<object>() }, { typeof(User), new List<object>() }, { typeof(ClientCareSetting), new List<object>() } }; foreach (var kvp in typeFactors) { var properties = kvp.Key.GetRuntimeProperties(); for (var i = 0; i < kvp.Value; i++) { var entity = Activator.CreateInstance(kvp.Key); entities[kvp.Key].Add(entity); } } foreach (var kvp in entities) { var properties = kvp.Key.GetRuntimeProperties(); foreach (var entity in kvp.Value) { foreach (var property in properties) { if (typeFactors.ContainsKey(property.PropertyType)) { var relatedEntities = entities[property.PropertyType]; property.SetValue(entity, relatedEntities[random.Next(0, relatedEntities.Count)]); } else if (property.PropertyType == typeof(ICollection<EnrollmentService>)) { property.SetValue(entity, Select(property.PropertyType, random, 5, entities)); } else if (property.PropertyType == typeof(ICollection<Doc>)) { property.SetValue(entity, Select(property.PropertyType, random, 5, entities)); } else if (property.PropertyType == typeof(ICollection<Note>)) { property.SetValue(entity, Select(property.PropertyType, random, 5, entities)); } else if (property.PropertyType == typeof(ICollection<Provider>)) { property.SetValue(entity, Select(property.PropertyType, random, 5, entities)); } else if (property.PropertyType == typeof(ICollection<Service>)) { property.SetValue(entity, Select(property.PropertyType, random, 5, entities)); } else if (property.PropertyType == typeof(ICollection<Contact>)) { property.SetValue(entity, Select(property.PropertyType, random, 5, entities)); } else if (property.PropertyType == typeof(ICollection<ClientCareSetting>)) { property.SetValue(entity, Select(property.PropertyType, random, 5, entities)); } else if (property.PropertyType == typeof(Address)) { var address = new Address() { City = "Seattle", State = "WA", Street1 = Guid.NewGuid().ToString(), Zip = 98004, }; property.SetValue(entity, address); } else if (property.PropertyType == typeof(int)) { // Do nothing } else if (property.PropertyType == typeof(int?)) { property.SetValue(entity, 0); } else if (property.PropertyType == typeof(string)) { property.SetValue(entity, Guid.NewGuid().ToString()); } else if (property.PropertyType == typeof(DateTime)) { // Do nothing } } } } foreach (Client client in entities[typeof(Client)]) { client.Enrollments = new List<Enrollment>(); var enrollmentCount = random.Next(0, 5); for (var i = 0; i < enrollmentCount; i++) { var program = (Program)entities[typeof(Program)][random.Next(0, typeFactors[typeof(Program)])]; if (program.Enrollments == null) { program.Enrollments = new List<Enrollment>(); } var enrollment = new Enrollment() { Client = client, Documents = (List<Doc>)Select(typeof(ICollection<Doc>), random, 5, entities), EnrollmentServices = (List<EnrollmentService>)Select(typeof(ICollection<EnrollmentService>), random, 5, entities), Notes = (List<Note>)Select(typeof(ICollection<Note>), random, 5, entities), PrimaryCaseManager = (User)entities[typeof(User)][random.Next(0, typeFactors[typeof(User)])], SecondaryCaseManager = (User)entities[typeof(User)][random.Next(0, typeFactors[typeof(User)])], Program = program, }; client.Enrollments.Add(enrollment); program.Enrollments.Add(enrollment); entities[typeof(Enrollment)].Add(enrollment); } } return (EnrollmentService)entities[typeof(EnrollmentService)][random.Next(0, typeFactors[typeof(EnrollmentService)])]; }
public static void Initialize(SchoolContext context) { //context.Database.EnsureCreated(); // Look for any students. if (context.Students.Any()) { return; // DB has been seeded } var students = new Student[] { new Student { FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2010-09-01") }, new Student { FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2012-09-01") }, new Student { FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2013-09-01") }, new Student { FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2012-09-01") }, new Student { FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2012-09-01") }, new Student { FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2011-09-01") }, new Student { FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2013-09-01") }, new Student { FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01") } }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var instructors = new Instructor[] { new Instructor { FirstMidName = "Kim", LastName = "Abercrombie", HireDate = DateTime.Parse("1995-03-11") }, new Instructor { FirstMidName = "Fadi", LastName = "Fakhouri", HireDate = DateTime.Parse("2002-07-06") }, new Instructor { FirstMidName = "Roger", LastName = "Harui", HireDate = DateTime.Parse("1998-07-01") }, new Instructor { FirstMidName = "Candace", LastName = "Kapoor", HireDate = DateTime.Parse("2001-01-15") }, new Instructor { FirstMidName = "Roger", LastName = "Zheng", HireDate = DateTime.Parse("2004-02-12") } }; foreach (Instructor i in instructors) { context.Instructors.Add(i); } context.SaveChanges(); var departments = new Department[] { new Department { Name = "English", Budget = 350000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID }, new Department { Name = "Mathematics", Budget = 100000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID }, new Department { Name = "Engineering", Budget = 350000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single(i => i.LastName == "Harui").ID }, new Department { Name = "Economics", Budget = 100000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID } }; foreach (Department d in departments) { context.Departments.Add(d); } context.SaveChanges(); var courses = new Course[] { new Course { CourseID = 1050, Title = "Chemistry", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID }, new Course { CourseID = 4022, Title = "Microeconomics", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID }, new Course { CourseID = 4041, Title = "Macroeconomics", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID }, new Course { CourseID = 1045, Title = "Calculus", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID }, new Course { CourseID = 3141, Title = "Trigonometry", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID }, new Course { CourseID = 2021, Title = "Composition", Credits = 3, DepartmentID = departments.Single(s => s.Name == "English").DepartmentID }, new Course { CourseID = 2042, Title = "Literature", Credits = 4, DepartmentID = departments.Single(s => s.Name == "English").DepartmentID }, }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var officeAssignments = new OfficeAssignment[] { new OfficeAssignment { InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID, Location = "Smith 17" }, new OfficeAssignment { InstructorID = instructors.Single(i => i.LastName == "Harui").ID, Location = "Gowan 27" }, new OfficeAssignment { InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID, Location = "Thompson 304" }, }; foreach (OfficeAssignment o in officeAssignments) { context.OfficeAssignments.Add(o); } context.SaveChanges(); var courseInstructors = new CourseAssignment[] { new CourseAssignment { CourseID = courses.Single(c => c.Title == "Chemistry").CourseID, InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Chemistry").CourseID, InstructorID = instructors.Single(i => i.LastName == "Harui").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Microeconomics").CourseID, InstructorID = instructors.Single(i => i.LastName == "Zheng").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Macroeconomics").CourseID, InstructorID = instructors.Single(i => i.LastName == "Zheng").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Calculus").CourseID, InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Trigonometry").CourseID, InstructorID = instructors.Single(i => i.LastName == "Harui").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Composition").CourseID, InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Literature").CourseID, InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID }, }; foreach (CourseAssignment ci in courseInstructors) { context.CourseAssignments.Add(ci); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentID = students.Single(s => s.LastName == "Alexander").ID, CourseID = courses.Single(c => c.Title == "Chemistry").CourseID, Grade = Grade.A }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alexander").ID, CourseID = courses.Single(c => c.Title == "Microeconomics").CourseID, Grade = Grade.C }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alexander").ID, CourseID = courses.Single(c => c.Title == "Macroeconomics").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alonso").ID, CourseID = courses.Single(c => c.Title == "Calculus").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alonso").ID, CourseID = courses.Single(c => c.Title == "Trigonometry").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alonso").ID, CourseID = courses.Single(c => c.Title == "Composition").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Anand").ID, CourseID = courses.Single(c => c.Title == "Chemistry").CourseID }, new Enrollment { StudentID = students.Single(s => s.LastName == "Anand").ID, CourseID = courses.Single(c => c.Title == "Microeconomics").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Barzdukas").ID, CourseID = courses.Single(c => c.Title == "Chemistry").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Li").ID, CourseID = courses.Single(c => c.Title == "Composition").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Justice").ID, CourseID = courses.Single(c => c.Title == "Literature").CourseID, Grade = Grade.B } }; foreach (Enrollment e in enrollments) { var enrollmentInDataBase = context.Enrollments.Where( s => s.Student.ID == e.StudentID && s.Course.CourseID == e.CourseID).SingleOrDefault(); if (enrollmentInDataBase == null) { context.Enrollments.Add(e); } } context.SaveChanges(); }
// GET: Enrollments/Details/5 public ActionResult Details(int id) { Enrollment e = Eobj.FindbyID(id); return(View(e)); }
public async Task <Enrollment> PromoteStudent(PromoteStudentRequest request) { var existedStudy = await _studentContext.Studies .Where(opt => opt.Name == request.Study) .FirstOrDefaultAsync(); if (existedStudy == null) { throw new DbServiceExceptionHandler(ExceptionHandlerEnumType.NotFound, "Study does not exist"); } /*return null;*/ var existedEnrollment = await _studentContext.Enrollment .Include(opt => opt.IdStudyNavigation) .Where(opt => opt.Semester == request.Semester && opt.IdStudyNavigation.Name == request.Study) .AnyAsync(); if (existedEnrollment == false) { throw new DbServiceExceptionHandler(ExceptionHandlerEnumType.NotFound, "Enrollment does not exist"); } /* return null;*/ var promotedEnrollment = await _studentContext.Enrollment .Include(opt => opt.IdStudyNavigation) .Where(opt => (opt.Semester == request.Semester + 1) && opt.IdStudyNavigation.Name == request.Study) .FirstOrDefaultAsync(); if (promotedEnrollment == null) { promotedEnrollment = new Enrollment { IdEnrollment = _studentContext.Enrollment.Count() + 1, Semester = request.Semester + 1, IdStudy = existedStudy.IdStudy, StartDate = DateTime.Today } } ; _studentContext.Add(promotedEnrollment); var studens = await _studentContext.Student .Include(opt => opt.IdEnrollmentNavigation) .ThenInclude(opt => opt.IdStudyNavigation) .Where(opt => opt.IdEnrollmentNavigation.Semester == request.Semester && opt.IdEnrollmentNavigation.IdStudyNavigation.Name == request.Study) .ToListAsync(); foreach (var student in studens) { student.IdEnrollment = promotedEnrollment.IdEnrollment; _studentContext.Entry(student).Property("IdEnrollment").IsModified = true; } return(promotedEnrollment); } }
protected void DeleteEnrollmentButton_Click(object sender, EventArgs e) { Enrollment enrollment = new Enrollment(); ClassroomController.DeleteUserEnrollmentByCourse(UserId, CourseId); if(!string.IsNullOrEmpty(Request.QueryString["retto"])) { /* Return back to CourseStudent.aspx */ Response.Redirect("~/Admin/Classroom/CourseStudents.aspx?CourseID=" + CourseId); } else { /* Return back to UserDetails.aspx */ Response.Redirect("~/Admin/UserDetails.aspx?user="******"user"]) && !string.IsNullOrEmpty(Request.QueryString["sku"])) //{ // enrollment.DeleteEnrollment(Request.QueryString["user"].ToString(), Request.QueryString["sku"].ToString()); // Response.Redirect("~/Admin/UserDetails.aspx?Tab=4&user="******"user"].ToString()); //} }
public static void Initialize(SchoolContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Students.Any()) { return; // DB has been seeded } var students = new Student[] { new Student { FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2005-09-01") }, new Student { FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2001-09-01") }, new Student { FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01") } }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var courses = new Course[] { new Course { CourseID = 1050, Title = "Chemistry", Credits = 3 }, new Course { CourseID = 4022, Title = "Microeconomics", Credits = 3 }, new Course { CourseID = 4041, Title = "Macroeconomics", Credits = 3 }, new Course { CourseID = 1045, Title = "Calculus", Credits = 4 }, new Course { CourseID = 3141, Title = "Trigonometry", Credits = 4 }, new Course { CourseID = 2021, Title = "Composition", Credits = 3 }, new Course { CourseID = 2042, Title = "Literature", Credits = 4 } }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentID = 1, CourseID = 1050, Grade = Grade.A }, new Enrollment { StudentID = 1, CourseID = 4022, Grade = Grade.C }, new Enrollment { StudentID = 1, CourseID = 4041, Grade = Grade.B }, new Enrollment { StudentID = 2, CourseID = 1045, Grade = Grade.B }, new Enrollment { StudentID = 2, CourseID = 3141, Grade = Grade.F }, new Enrollment { StudentID = 2, CourseID = 2021, Grade = Grade.F }, new Enrollment { StudentID = 3, CourseID = 1050 }, new Enrollment { StudentID = 4, CourseID = 1050 }, new Enrollment { StudentID = 4, CourseID = 4022, Grade = Grade.F }, new Enrollment { StudentID = 5, CourseID = 4041, Grade = Grade.C }, new Enrollment { StudentID = 6, CourseID = 1045 }, new Enrollment { StudentID = 7, CourseID = 3141, Grade = Grade.A }, }; foreach (Enrollment e in enrollments) { context.Enrollments.Add(e); } context.SaveChanges(); }
public ActionResult Edit(Enrollment enrollment) { if (ModelState.IsValid) { db.Entry(enrollment).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("List"); } return View(enrollment); }
public static void Initialize(SchoolContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Students.Any()) { return; // DB has been seeded } var students = new Student[] { new Student { StudentFullName = "David Jackson", Age = 18, GPA = 3.4 }, new Student { StudentFullName = "Peter Parker", Age = 18, GPA = 3.4 }, new Student { StudentFullName = "Robert Smith", Age = 17, GPA = 3.4 }, new Student { StudentFullName = "Olivia Dale", Age = 19, GPA = 3.4 }, new Student { StudentFullName = "Barak Trump", Age = 19, GPA = 3.4 }, new Student { StudentFullName = "Donalad SpilBurg", Age = 18, GPA = 3.4 }, new Student { StudentFullName = "Sarah Borneroth", Age = 18, GPA = 3.4 }, new Student { StudentFullName = "Abel moouche", Age = 18, GPA = 3.4 } }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var Classes = new Class[] { new Class { Id = 1050, Title = "Chemistry", Location = "Building A, Room 102", TeacherName = "Mr. Branson" }, new Class { Id = 4022, Title = "Microeconomics", Location = "Building A, Room 105", TeacherName = "Mr. Pateriani" }, new Class { Id = 4041, Title = "Macroeconomics", Location = "Building A, Room 102", TeacherName = "Mr. Jackson" }, new Class { Id = 1045, Title = "Calculus", Location = "Building A, Room 103", TeacherName = "Mr. Bale" }, new Class { Id = 3141, Title = "Trigonometry", Location = "Building A, Room 88", TeacherName = "Mr. Atkinson" }, new Class { Id = 2021, Title = "Composition", Location = "Building A, Room 95", TeacherName = "Ms. Pacino" }, new Class { Id = 2042, Title = "Literature", Location = "Building A, Room 212", TeacherName = "Mr. Deniro" } }; foreach (Class c in Classes) { context.Classes.Add(c); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentID = 1, ClassID = 1050 }, new Enrollment { StudentID = 1, ClassID = 4022 }, new Enrollment { StudentID = 1, ClassID = 4041 }, new Enrollment { StudentID = 2, ClassID = 1045 }, new Enrollment { StudentID = 2, ClassID = 3141 }, new Enrollment { StudentID = 2, ClassID = 2021 }, new Enrollment { StudentID = 3, ClassID = 1050 }, new Enrollment { StudentID = 4, ClassID = 1050 }, new Enrollment { StudentID = 4, ClassID = 4022 }, new Enrollment { StudentID = 5, ClassID = 4041 }, new Enrollment { StudentID = 6, ClassID = 1045 }, new Enrollment { StudentID = 7, ClassID = 3141 } }; foreach (Enrollment e in enrollments) { context.Enrollments.Add(e); } context.SaveChanges(); }
public int EnrollStudentInCourse(int studentId, int courseId, Enrollment enrollment) { throw new NotImplementedException(); }
public static void Initialize(SchoolDbcontext context) { context.Database.EnsureCreated(); // 检查是否有学生信息 if (context.Students.Any()) { return; //返回,不执行。 } var students = new Student[] { new Student { RealName = "龙傲天", EnrollmentDate = DateTime.Parse("2005-09-01") }, new Student { RealName = "王尼玛", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { RealName = "张全蛋", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { RealName = "叶良辰", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { RealName = "和珅", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { RealName = "纪晓岚", EnrollmentDate = DateTime.Parse("2001-09-01") }, new Student { RealName = "李逍遥", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { RealName = "王小虎", EnrollmentDate = DateTime.Parse("2005-09-01") } }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var courses = new Course[] { new Course { CourseId = 1050, Title = "数学", Credits = 3 }, new Course { CourseId = 4022, Title = "政治", Credits = 3 }, new Course { CourseId = 4041, Title = "物理", Credits = 3 }, new Course { CourseId = 1045, Title = "化学", Credits = 4 }, new Course { CourseId = 3141, Title = "生物", Credits = 4 }, new Course { CourseId = 2021, Title = "英语", Credits = 3 }, new Course { CourseId = 2042, Title = "历史", Credits = 4 } }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentId = 1, CourseId = 1050, Grade = Grade.A }, new Enrollment { StudentId = 1, CourseId = 4022, Grade = Grade.C }, new Enrollment { StudentId = 1, CourseId = 4041, Grade = Grade.B }, new Enrollment { StudentId = 2, CourseId = 1045, Grade = Grade.B }, new Enrollment { StudentId = 2, CourseId = 3141, Grade = Grade.F }, new Enrollment { StudentId = 2, CourseId = 2021, Grade = Grade.F }, new Enrollment { StudentId = 3, CourseId = 1050 }, new Enrollment { StudentId = 4, CourseId = 1050 }, new Enrollment { StudentId = 4, CourseId = 4022, Grade = Grade.F }, new Enrollment { StudentId = 5, CourseId = 4041, Grade = Grade.C }, new Enrollment { StudentId = 6, CourseId = 1045 }, new Enrollment { StudentId = 7, CourseId = 3141, Grade = Grade.A }, }; foreach (Enrollment e in enrollments) { context.Enrollments.Add(e); } context.SaveChanges(); }
private void AttachEnrollments(Enrollment entity) { this.OnPropertyChanging(); entity.Course = this; }
public ActionResult Details(int Cid, int sectionNum, int LectureNum) { string fromEnroll = (string)TempData["messageEnrollSucess"]; if (fromEnroll == null) { ViewBag.message = ""; } else if (fromEnroll.CompareTo("Sucess") == 0) { ViewBag.message = "Sucessfully Enrolled"; } else if (fromEnroll.CompareTo("failure") == 0) { ViewBag.message = "You have already Enrolled"; } var userId = User.Identity.GetUserId(); /*Enrollment enroll = (Enrollment) (from e in db.Enrollments * where e.CourseID == id && e.StudentID == userId * select new Enrollment { EnrollmentID=e.EnrollmentID, * CourseID=e.CourseID, * StudentID=e.StudentID, * EnrollmentDate=e.EnrollmentDate, * Progress=e.Progress, * pointsEarned=e.pointsEarned});*/ Enrollment enroll = db.Enrollments .Where(i => i.StudentID == userId) .Where(i => i.CourseID == Cid).Single(); var reminders = (from r in db.Reminders where r.EnrollmentID == enroll.EnrollmentID select r).ToList(); Course course = db.Course.Find(Cid); Instructor instructor = db.Instructors.Find(course.InstructorID); string userName = instructor.Email; //get number of lectures in each section and section names ArrayList LecCount = new ArrayList(); ArrayList sectionNames = new ArrayList(); for (int i = 1; i <= course.TotalSections; i++) { string sPath = course.CoursePath + "/section" + i; DirectoryInfo dInfo = new DirectoryInfo(Server.MapPath(sPath)); var str = dInfo.GetDirectories(); int totLectures = str.Count(); //get count of lectures in each section LecCount.Add(totLectures); var secName = System.IO.File.ReadAllText(Server.MapPath(sPath) + @"/SectionName.txt"); sectionNames.Add((string)secName); } string path = course.CoursePath; string secPath = path + "/section" + sectionNum; //get section Name from "secPath"+/SectionName.txt string LecPath = secPath + "/Lecture" + LectureNum; var notes = (from n in db.Notes where n.EnrollmentID == enroll.EnrollmentID && n.LecturePath == LecPath select n).ToList(); //get list of filenames in the LecturePath //check for video file withname "Lecture"+LectureNum string LecVideo = ""; DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(LecPath)); foreach (FileInfo l in dirInfo.GetFiles("Lecture" + LectureNum + ".*")) { LecVideo = LecPath + "/" + l.Name; } //check for additional document with name "AddDoc"+LectureNum //temp string AddDoc = ""; try { foreach (FileInfo l in dirInfo.GetFiles("AddDoc" + LectureNum + ".*")) { ViewBag.AddDoc = "true"; AddDoc = LecPath + "/" + l.Name; } } catch (DirectoryNotFoundException e) { ViewBag.AddDoc = "false"; } //get lecture description from file "LectureDesc"+ LectureNum+".txt" var lecDesc = System.IO.File.ReadAllText(Server.MapPath(LecPath) + @"/LectureDesc" + LectureNum + ".txt"); ArrayList quizSecs = new ArrayList((from q in db.Quiz where q.CourseID == Cid orderby q.sectionNum select q.sectionNum).Distinct().ToList()); EnrolledCourseView courseView = new EnrolledCourseView { enrollment = enroll, course = course, QuizSecNums = quizSecs, notes = notes, reminders = reminders, LectureVideoPath = LecVideo, AddDocPath = AddDoc, LectureDesc = (string)lecDesc, LecturesInSection = LecCount, sectionNames = sectionNames, sectionNum = sectionNum, lecNum = LectureNum }; return(View(courseView)); }
public void Seed() { if (_ctx.Courses.Count() > 0) { return; } try { foreach (var subjectName in subjects) { var subject = new Subject { Name = subjectName }; _ctx.Subjects.Add(subject); _ctx.SaveChanges(); } for (int i = 0; i < tutorNames.Length; i++) { var nameGenderMail = SplitValue(tutorNames[i]); var tutor = new Tutor { Email = String.Format("{0}.{1}@{2}", nameGenderMail[0], nameGenderMail[1], nameGenderMail[3]), UserName = String.Format("{0}{1}", nameGenderMail[0], nameGenderMail[1]), Password = RandomString(8), FirstName = nameGenderMail[0], LastName = nameGenderMail[1], Gender = ((Entity.Enums.Gender)Enum.Parse(typeof(Entity.Enums.Gender), nameGenderMail[2])) }; _ctx.Tutors.Add(tutor); var courseSubject = _ctx.Subjects.Where(s => s.Id == i + 1).Single(); foreach (var CourseDataItem in CoursesSeedData.Where(c => c.SubjectID == courseSubject.Id)) { var course = new Course { Name = CourseDataItem.CourseName, CourseSubject = courseSubject, CourseTutor = tutor, Duration = new Random().Next(3, 6), Description = String.Format("The course will talk in depth about: {0}", CourseDataItem.CourseName) }; _ctx.Courses.Add(course); } } _ctx.SaveChanges(); for (int i = 0; i < studentNames.Length; i++) { var nameGenderMail = SplitValue(studentNames[i]); var student = new Student() { Email = String.Format("{0}.{1}@{2}", nameGenderMail[0], nameGenderMail[1], nameGenderMail[3]), UserName = String.Format("{0}{1}", nameGenderMail[0], nameGenderMail[1]), Password = RandomString(8), FirstName = nameGenderMail[0], LastName = nameGenderMail[1], Gender = ((Entity.Enums.Gender)Enum.Parse(typeof(Entity.Enums.Gender), nameGenderMail[2])), DateOfBirth = DateTime.UtcNow.AddDays(-new Random().Next(7000, 8000)), RegistrationDate = DateTime.UtcNow.AddDays(-new Random().Next(365, 730)) }; _ctx.Students.Add(student); int maxCoursesId = _ctx.Courses.Max(c => c.Id); //To enroll in 4 courses randomly for (int z = 0; z < 4; z++) { int randomCourseId = new Random().Next(1, maxCoursesId); var enrollment = new Enrollment { Student = student, Course = _ctx.Courses.Where(c => c.Id == randomCourseId).Single(), EnrollmentDate = DateTime.UtcNow.AddDays(-new Random().Next(10, 30)) }; _ctx.Enrollments.Add(enrollment); } } _ctx.SaveChanges(); } catch (Exception ex) { string message = ex.ToString(); throw ex; } }
public Enrollment NewStudent(Student student) { /*if (!ModelState.IsValid) * { * var d = ModelState; * return BadRequest("!!!"); * }*/ var result = new List <Enrollment>(); if (student.FirstName == null || student.IndexNumber == null || student.LastName == null || student.BirthDate == null || student.Studies == null) { return(null);// BadRequest("Nie podano wszystkich danych studenta"); } var st = new Enrollment(); using (SqlConnection con = new SqlConnection(ConnString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; con.Open(); //SqlTransaction tran = con.BeginTransaction(); //var tran = con.BeginTransaction(); st.IdStudy = 0; com.CommandText = "select * from studies where name = '" + student.Studies + "'"; com.Parameters.AddWithValue("name", student.Studies); var dr = com.ExecuteReader(); if (dr.Read()) { st.IdStudy = (int)dr["idStudy"]; } else if (st.IdStudy == 0) { //tran.Rollback(); return(null);// BadRequest("Nie ma tego na liscie Studies"); } dr.Close(); st.IdEnrollment = 0; com.CommandText = "select idEnrollment from enrollment where semester=1 and idstudy = (select idstudy from Studies where name ='" + student.Studies + "') and StartDate = (select max(StartDate) from enrollment where Semester = 1 and Idstudy = (select idStudy from studies where Name ='" + student.Studies + "'))"; //com.Parameters.AddWithValue("name", student.Studies); var dr2 = com.ExecuteReader(); if (dr2.Read()) { st.IdEnrollment = (int)dr2["IdEnrollment"]; } else if (st.IdEnrollment == 0) { dr2.Close(); var sprawdzenieEski = new List <string>(); com.CommandText = "select indexNumber from students"; var dr3 = com.ExecuteReader(); while (dr3.Read()) { string eska = dr3["indexNumber"].ToString(); sprawdzenieEski.Add(eska); } int eskaUnik = 1; foreach (string es in sprawdzenieEski) { if (student.IndexNumber.Equals(es)) { eskaUnik++; } } /*SqlTransaction trans = con.BeginTransaction(); * com.Transaction = trans;*/ if (eskaUnik == 1) { SqlTransaction trans = con.BeginTransaction(); com.Transaction = trans; try { st.StartDate = DateTime.Now; com.CommandText = "insert into Enrollment(idEnrollment,Semester,IdStudy,StartDate)" + "values(" + @st.IdEnrollment + "," + 1 + "," + st.IdStudy + "," + st.StartDate + ")"; com.ExecuteNonQuery(); com.CommandText = "insert into student (IndexNumber, FirstName, LastName, BirthDate, IdEnrollment) values ('" + student.IndexNumber + "', '" + student.FirstName + "', '" + student.LastName + "', '" + student.BirthDate.Split(".")[2] + "-" + student.BirthDate.Split(".")[1] + "-" + student.BirthDate.Split(".")[0] + "', (select max(IdEnrollment) from Enrollment));"; com.ExecuteNonQuery(); trans.Commit(); } catch { trans.Rollback(); return(null);// BadRequest("Blad podczas transakcji"); } } else { SqlTransaction trans = con.BeginTransaction(); com.Transaction = trans; try { st.StartDate = DateTime.Now; com.CommandText = "insert into Enrollment(idEnrollment,Semester,IdStudy,StartDate)" + "values(" + @st.IdEnrollment + "," + 1 + "," + st.IdStudy + "," + st.StartDate + ")"; trans.Commit(); } catch { trans.Rollback(); return(null);// BadRequest("Blad podczas transakcji"); } } } } //st.StartDate = DateTime.Now; st.Semester = 1; result.Add(st); return(st); }