public bool ChangePassword(string indexNumber, ChangePasswordRequests request) { _context = new APBDContext(); Student student; try { student = GetStudent(indexNumber, _context); if (!student.Password.Equals(request.OldPassword)) { return(false); } } catch { return(false); } student.Password = request.NewPassword; _context.SaveChanges(); /*var updatedStudent = new Student * { * IndexNumber = indexNumber, * Password = request.NewPassword * }; * * _context.Attach(updatedStudent); * _context.Entry(updatedStudent).Property("Password").IsModified = true; * _context.SaveChanges();*/ return(true); }
public void DeleteStudent(string indexNumber) { _context = new APBDContext(); var student = new Student { IndexNumber = indexNumber }; _context.Remove(student); _context.SaveChanges(); }
/*public Enrollment GetEnrollment(string indexNumber) * { * _context = new APBDContext(); * var student = _context.Student * .First(x => x.IndexNumber == indexNumber); * var enrollment = _context.Enrollment * .First(x => x.IdEnrollment == student.IdEnrollment); * return enrollment; * }*/ public Enrollment EnrollStudent(EnrollStudentRequests request) { _context = new APBDContext(); Studies study; try { study = _context.Studies .First(x => x.Name.Equals(request.Studies)); } catch { return(null); } Enrollment enrollment; try { enrollment = _context.Enrollment .Where(x => x.IdStudy.Equals(study.IdStudy)) .First(x => x.Semester == 1); } catch { var newEnrollment = new Enrollment { IdEnrollment = _context.Enrollment .Max(x => x.IdEnrollment) + 1, Semester = 1, IdStudy = study.IdStudy, StartDate = DateTime.Today }; _context.Enrollment.Add(newEnrollment); enrollment = newEnrollment; } var idEnrollment = enrollment.IdEnrollment; var student = new Student { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, BirthDate = DateTime.ParseExact(request.BirthDate, "dd.MM.yyyy", CultureInfo.InvariantCulture), IdEnrollment = idEnrollment, Password = "******" }; _context.Student.Add(student); _context.SaveChanges(); return(enrollment); }
public Enrollment PromoteStudents(PromoteStudentsRequest request) { _context = new APBDContext(); Studies study; Enrollment oldEnrollment; // Upewniam się, że w tabeli Enrollment istnieje wpis o podanej wartości Studies i Semester try { study = _context.Studies .First(x => x.Name.Equals(request.Studies)); oldEnrollment = _context.Enrollment .Where(x => x.IdStudy.Equals(study.IdStudy)) .First(x => x.Semester == Convert.ToInt32(request.Semester)); } catch { return(null); } Enrollment enrollment; try { enrollment = _context.Enrollment .Where(x => x.IdStudy.Equals(study.IdStudy)) .First(x => x.Semester == Convert.ToInt32(request.Semester) + 1); } catch { var newEnrollment = new Enrollment { IdEnrollment = _context.Enrollment .Max(x => x.IdEnrollment) + 1, Semester = Convert.ToInt32(request.Semester) + 1, IdStudy = study.IdStudy, StartDate = DateTime.Today }; _context.Enrollment.Add(newEnrollment); enrollment = newEnrollment; } var students = _context.Student .Where(x => x.IdEnrollment == oldEnrollment.IdEnrollment) .ToList(); foreach (var s in students) { s.IdEnrollment = enrollment.IdEnrollment; } _context.SaveChanges(); return(enrollment); }
public bool deleteStudent(string indexNumber) { APBDContext context = new APBDContext(); var student = GetStudentByIndex(indexNumber, context); if (student == null) { return(false); } context.Student.Remove(student); context.SaveChanges(); return(true); }
public EnrollmentResponse PromoteStudents(PromoteStudentsRequest request) { APBDContext context = new APBDContext(); //istnienie wpisów Enrollment enr = context.Enrollment .Where(x => x.Semester == request.Semester) .Where(x => x.IdStudy == context.Studies.Where(y => y.Name == request.Studies).FirstOrDefault().IdStudy) .FirstOrDefault(); if (enr == null) { return(null); } //istnienie wpisu +1 Enrollment enr2 = context.Enrollment .Where(x => x.Semester == request.Semester + 1) .Where(x => x.IdStudy == enr.IdStudy) .FirstOrDefault(); if (enr2 == null) { context.Enrollment.Add(enr2 = new Enrollment { Semester = request.Semester + 1, StartDate = DateTime.Today, IdEnrollment = context.Enrollment.Select(x => x.IdEnrollment).Max() + 1, IdStudy = enr.IdStudy }); } //promocja studentów var students = context.Student .Where(x => x.IdEnrollment == enr.IdEnrollment).ToList(); foreach (Student s in students) { s.IdEnrollment = enr2.IdEnrollment; } context.SaveChanges(); // stworzenie Enrollmentu EnrollmentResponse enrResp = new EnrollmentResponse(); enrResp.Semester = enr2.Semester; enrResp.StudyName = request.Studies; enrResp.StartDate = enr2.StartDate.ToString(); return(enrResp); }
public Student ModifyStudent(ModifyRequest request) { APBDContext context = new APBDContext(); var student = GetStudentByIndex(request.IndexNumber); if (student != null) { if (request.FirstName != null) { student.FirstName = request.FirstName; } if (request.LastName != null) { student.LastName = request.LastName; } if (request.BirthDate != null) { student.BirthDate = request.BirthDate; } context.SaveChanges(); return(student); } return(null); }
public EnrollmentResponse EnrollStudent(EnrollStudentRequest request) { var enr = new EnrollmentResponse(); // request APBDContext context = new APBDContext(); //istnienie studiow Studies studies = context.Studies.Where(x => x.Name == request.Studies).FirstOrDefault(); if (studies == null) { return(null); } //wpis do tabeli enrollment //czy wpis istnieje Enrollment enrollment = context.Enrollment .Where(x => x.IdStudy == studies.IdStudy) .Where(x => x.Semester == 1) .FirstOrDefault(); // jesli nie to dodaj wpis if (enrollment == null) { enrollment = new Enrollment { Semester = 1, StartDate = DateTime.Today, IdEnrollment = context.Enrollment.Select(x => x.IdEnrollment).Max() + 1, IdStudy = studies.IdStudy }; context.Enrollment.Add(enrollment); } //sprawdzenie unikalnosci indeksu if (context.Student.Select(x => x.IndexNumber).Any(x => x == request.IndexNumber)) { return(null); } //dodanie studenta Student student = new Student { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, BirthDate = DateTime.ParseExact(request.BirthDate, "yyyy-mm-dd", System.Globalization.CultureInfo.InvariantCulture), IdEnrollment = enrollment.IdEnrollment }; context.Student.Add(student); context.SaveChanges(); // stworzenie Enrollmentu enr.Semester = enrollment.Semester; enr.StudyName = studies.Name; enr.StartDate = enrollment.StartDate.ToString(); return(enr); }