public IHttpActionResult Post(CourseRequestModel model) { if (model == null) { return this.BadRequest("Course is not set to un instance of object"); } var newCourse = new Course() { Name = model.Name, Description = model.Description, }; this.data.Courses.Add(newCourse); this.data.SaveChanges(); return this.Ok(newCourse.Id); }
public IHttpActionResult Put(CourseRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var courseForUpdate = this.data.Courses .SearchFor(c => c.Name == model.Name) .FirstOrDefault(); if (courseForUpdate == null) { return this.NotFound(); } courseForUpdate.Description = model.Description; courseForUpdate.Name = model.Name; this.data.Courses.Update(courseForUpdate); this.data.SaveChanges(); return this.Ok(courseForUpdate); }