Пример #1
0
 public Student Get(int id)
 {
     using (StudentDetailsEntities entities = new StudentDetailsEntities())
     {
         return(entities.Students.FirstOrDefault(e => e.ID == id));
     }
 }
Пример #2
0
 public IEnumerable <Student> Get()
 {
     using (StudentDetailsEntities entities = new StudentDetailsEntities())
     {
         return(entities.Students.ToList());
     }
 }
 public Course Get(int id)
 {
     using (StudentDetailsEntities entities = new StudentDetailsEntities())
     {
         return(entities.Course.FirstOrDefault(e => e.COURSEID == id));
     }
 }
 public IEnumerable <Course> Get()
 {
     using (StudentDetailsEntities entities = new StudentDetailsEntities())
     {
         return(entities.Course.ToList());
     }
 }
Пример #5
0
        public IHttpActionResult Post(Student student)
        {
            using (StudentDetailsEntities entities = new StudentDetailsEntities())
            {
                entities.Student.Add(new Student()
                {
                    FIRSTNAME = student.FIRSTNAME,
                    LASTNAME  = student.LASTNAME,
                    AGE       = student.AGE,
                    GENDER    = student.GENDER
                });

                entities.SaveChanges();
            }

            return(Ok());
        }
Пример #6
0
        public IHttpActionResult Put(Student student)
        {
            using (StudentDetailsEntities entities = new StudentDetailsEntities())
            {
                var exisingStudent = entities.Student.Where(s => s.ID == student.ID)
                                     .FirstOrDefault();

                if (exisingStudent != null)
                {
                    exisingStudent.FIRSTNAME = student.FIRSTNAME;
                    exisingStudent.LASTNAME  = student.LASTNAME;
                    exisingStudent.GENDER    = student.GENDER;
                    exisingStudent.AGE       = student.AGE;

                    entities.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }

                return(Ok());
            }
        }
Пример #7
0
 public StudentsController(StudentDetailsEntities _db)
 {
     db = _db;
 }