public Users GetAdmin(string UserName, string Password) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { return(studentSystemEntities.Users.FirstOrDefault(x => x.UserName == UserName && x.Password == Password)); } }
// GET api/GetCourseByID/5 public Courses Get(int id) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Console.WriteLine("get"); return(studentSystemEntities.Courses.FirstOrDefault(x => x.ID == id)); } }
// GET api/Courses public IEnumerable <Courses> Get() { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Console.WriteLine("get"); return(studentSystemEntities.Courses.ToList()); } }
// DELETE api/Courses/id public void Delete(int courseID) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Courses course = studentSystemEntities.Courses.FirstOrDefault(x => x.ID == courseID); studentSystemEntities.Courses.Remove(course); studentSystemEntities.SaveChanges(); } }
// POST api/Courses public void Post([FromBody] Courses sub) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Console.WriteLine("get"); studentSystemEntities.Courses.Add(sub); studentSystemEntities.SaveChanges(); } }
// DELETE api/Teachers/id public void Delete(int teacherID) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Teachers teacher = studentSystemEntities.Teachers.FirstOrDefault(x => x.ID == teacherID); studentSystemEntities.Teachers.Remove(teacher); studentSystemEntities.SaveChanges(); } }
// DELETE api/Students/id public void Delete(int studentID) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Students student = studentSystemEntities.Students.FirstOrDefault(x => x.ID == studentID); studentSystemEntities.Students.Remove(student); studentSystemEntities.SaveChanges(); } }
public void PutCourseByID(int courseID, string startTime, string endTime, string context) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Courses course = studentSystemEntities.Courses.FirstOrDefault(x => x.ID == courseID); course.CourseStartTime = startTime; course.CourseEndTime = endTime; course.Context = context; studentSystemEntities.SaveChanges(); } }
// PUT api/Courses/5 public void PutEnrollment(int courseID, int studentID) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Courses course = studentSystemEntities.Courses.FirstOrDefault(x => x.ID == courseID); Students student = studentSystemEntities.Students.FirstOrDefault(x => x.ID == studentID); course.NumberOfEnrollments = course.NumberOfEnrollments + 1; course.EnrolledStudents = course.EnrolledStudents + "," + student.StudentName + " " + student.StudentSurname; student.EnrolledCourses = student.EnrolledCourses + "," + course.CourseName; studentSystemEntities.SaveChanges(); } }
public string GetEnrollment(string courseID, string studentID) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { int courseIDx = Int16.Parse(courseID); int studentIDx = Int16.Parse(studentID); Courses course = studentSystemEntities.Courses.FirstOrDefault(x => x.ID == courseIDx); Students student = studentSystemEntities.Students.FirstOrDefault(x => x.ID == studentIDx); course.NumberOfEnrollments = course.NumberOfEnrollments + 1; course.EnrolledStudents = course.EnrolledStudents + "," + student.StudentName + " " + student.StudentSurname; student.EnrolledCourses = student.EnrolledCourses + "," + course.CourseName; studentSystemEntities.SaveChanges(); return("ok"); } }
public void PutDisEnrollment(int courseID, int studentID) { using (ahmetDatabaseEntities studentSystemEntities = new ahmetDatabaseEntities()) { Courses course = studentSystemEntities.Courses.FirstOrDefault(x => x.ID == courseID); Students student = studentSystemEntities.Students.FirstOrDefault(x => x.ID == studentID); course.NumberOfEnrollments = course.NumberOfEnrollments - 1; List <string> words = course.EnrolledStudents.Split(',').ToList(); words.Remove(student.StudentName + " " + student.StudentSurname); course.EnrolledStudents = String.Join(",", words.ToArray()); List <string> words2 = student.EnrolledCourses.Split(',').ToList(); words2.Remove(course.CourseName); student.EnrolledCourses = String.Join(",", words2.ToArray()); studentSystemEntities.SaveChanges(); } }