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

            var course = this.StudentSystemData.Courses.Find(courseModel.CourseId);
            if (course == null)
            {
                return this.NotFound();
            }

            try
            {
                course.Description = courseModel.Description;
                this.StudentSystemData.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!this.CourseExists(courseModel.CourseId))
                {
                    return this.NotFound();
                }
                else
                {
                    throw;
                }
            }

            return this.StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult Create(CourseModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var course = new Course() { Description = model.Description, Name = model.Name, };
            this.data.Courses.Add(course);
            this.data.SaveChanges();
            return this.Ok(CourseModel.TransformCourse(course));
        }
        public IHttpActionResult Add(CourseModel course)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

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

            this.repository.Add(newCourse);
            this.repository.Save();

            return this.Ok($"course [{course.Name}] was added and has id : {newCourse.Id}");
        }
        public IHttpActionResult Create(CourseModel course)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

            course.CourseId = newCourse.CourseId;

            return Ok(course);
        }
        public IHttpActionResult Create(CourseModel item)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newItem = new Course()
            {
                Name = item.Name
            };

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

            item.ID = newItem.ID;

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

            Course existingCourse = this.data.Courses.All().FirstOrDefault(a => a.Id == id);

            if (existingCourse == null)
            {
                return BadRequest("The Course does not exist");
            }

            existingCourse.Description = course.Description;
            this.data.SaveChanges();

            course.Id = existingCourse.Id;
            return Ok(course);
        }
Пример #7
0
        public IHttpActionResult Create(CourseModel Course)
        {
            throw new NotImplementedException("I can't add my CourseModel as an Course :(");

            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var newCourse = new CourseModel
            {
                Description = Course.Description
            };

            //Why? Why?Why?Why?Why?Why?Why?Why?!!!!!!!
            //this.data.Courses.Add((Course)newCourse);
            this.data.SaveChanges();

            Course.Id = newCourse.Id;
            return Ok(newCourse);
        }
        public IHttpActionResult Update(int id, CourseModel course)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var existingCourse = this.data.Courses.All().First(c => c.CourseId == id);

            if (existingCourse == null)
            {
                return BadRequest("Such course does not exist!");
            }

            existingCourse.Name = course.Name;
            this.data.SaveChanges();

            course.CourseId = id;

            return Ok(course);
        }
        public IHttpActionResult Update(int id, CourseModel item)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var existingItem = this.data.Courses.All().FirstOrDefault(x => x.ID == id);

            if (existingItem == null)
            {
                return BadRequest("Invalid Course");
            }

            // Check if some of the fields in the new data are not null
            existingItem.Name = item.Name;
            this.data.Courses.SaveChanges();

            item.ID = existingItem.ID;
            return Ok(item);
        }
Пример #10
0
        public IHttpActionResult Update(Guid id, CourseModel course)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var courseToUpdate = this.data.Courses.All().FirstOrDefault(c => c.CourseId == id);

            if (courseToUpdate == null)
            {
                return BadRequest("Course with id: " + id + " does not exists.");
            }

            courseToUpdate.Description = course.Description;
            courseToUpdate.Name = course.Name;

            this.data.SaveChanges();

            course.CourseId = id;
            return Ok(course);
        }