public IActionResult updateStudent(Models2.Student student) { var db = new Models2.s19278Context(); var st = db.Student.Where(e => e.IndexNumber == student.IndexNumber); if (!st.Any()) { return(NotFound()); } if (student.LastName != null) { st.FirstOrDefault().LastName = student.LastName; } if (student.FirstName != null) { st.FirstOrDefault().FirstName = student.FirstName; } if (student.BirthDate != null) { st.FirstOrDefault().BirthDate = student.BirthDate; } if (student.IdEnrollment != 0) { st.FirstOrDefault().IdEnrollment = student.IdEnrollment; } db.SaveChanges(); return(Ok()); }
public IActionResult AddStudent(EnrollStudClass enroll) { var db = new Models2.s19278Context(); var st = db.Studies.Where(e => e.Name == enroll.Studies); if (!st.Any()) { return(NotFound("W bazie nie ma takich studiów")); } var en = db.Enrollment.Join(db.Studies, k => k.IdStudy, e => e.IdStudy, (k, e) => new { Enrollment = k, Studies = e }) .Where(e => e.Enrollment.Semester == 1 && e.Studies.Name == enroll.Studies); if (!en.Any()) { var enrolst = db.Studies.Where(e => e.Name == enroll.Studies).Select(e => e.IdStudy); db.Enrollment.Add(new Models2.Enrollment { IdEnrollment = db.Enrollment.Max(e => e.IdEnrollment) + 1, Semester = 1, IdStudy = enrolst.FirstOrDefault(), StartDate = DateTime.Now }); } var std = db.Student.Where(e => e.IndexNumber == enroll.IndexNumber); if (!std.Any()) { db.Student.Add(new Models2.Student { IndexNumber = enroll.IndexNumber, FirstName = enroll.FirstName, LastName = enroll.LastName, BirthDate = DateTime.Parse(enroll.BirthDate), IdEnrollment = db.Enrollment.Join(db.Studies, k => k.IdStudy, e => e.IdStudy, (k, e) => new { Enrollment = k, Studies = e }) .Where(e => e.Enrollment.Semester == 1 && e.Studies.Name == enroll.Studies).Select(e => e.Enrollment.IdEnrollment).FirstOrDefault() }); } else { return(NotFound("Id studenta nie jest unikalne")); } var enrollment = db.Enrollment.Join(db.Studies, k => k.IdStudy, e => e.IdStudy, (k, e) => new { Enrollment = k, Studies = e }) .Where(e => e.Enrollment.Semester == 1 && e.Studies.Name == enroll.Studies).FirstOrDefault(); db.SaveChanges(); return(StatusCode(201, enrollment)); }
public IActionResult GetStudents() { var db = new Models2.s19278Context(); var st = db.Student.ToList(); if (!st.Any()) { return(NotFound("W bazie nie ma studentów")); } db.Student.Remove(st.FirstOrDefault()); db.SaveChanges(); return(Ok(st)); }
public IActionResult deleteStudent(String id) { var db = new Models2.s19278Context(); var st = db.Student.Where(e => e.IndexNumber == id); if (!st.Any()) { return(NotFound()); } db.Student.Remove(st.FirstOrDefault()); db.SaveChanges(); return(Ok()); }