Пример #1
0
        public IHttpActionResult Create(CourseModel course)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var newStudent = new Course()
            {
                Description = course.Description,
                Name = course.Name,
            };

            this.data.Courses.Add(newStudent);
            this.data.SaveChanges();

            return Ok(course);
        }
Пример #2
0
        public IHttpActionResult Create(CourseModel course)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newCourse = new Course
            {
                Name = course.Name,
                Description = course.Description
            };

            this.db.Courses.Add(newCourse);
            this.db.SaveChanges();

            course.CourseId = newCourse.Id;

            return Ok(newCourse);
        }
Пример #3
0
        public IHttpActionResult Update(Guid id, CourseModel student)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var existingStudent = this.data
                .Courses
                .All()
                .FirstOrDefault(s => s.Id == id);

            if (existingStudent == null)
            {
                return this.BadRequest("No such student found!");
            }

            existingStudent.Name = student.Name;
            existingStudent.Description = student.Description;
            this.data.SaveChanges();

            return this.Ok(student);
        }