예제 #1
0
        public async Task <IActionResult> AddCourse([FromBody] Course course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.Course.Add(course);
            await context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCourseByID), new { id = course.Id }, course));
        }
예제 #2
0
        public async Task <IActionResult> AddTeacher([FromBody] Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.Teacher.Add(teacher);
            await context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetbyID), new { id = teacher.Id }, CreateLinksForTeacher(teacher)));
        }
예제 #3
0
        public async Task <IActionResult> AddStudent([FromBody] Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.Student.Add(student);
            await context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetStudentByID), new { id = student.Id }, CreateLinksForStudent(student)));
        }
        public async Task <IActionResult> AddSubscription([FromBody] Coursemembership sub)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.Coursemembership.Add(sub);
            await context.SaveChangesAsync();

            return(Created("Successfully subscribed", sub));
        }