public IHttpActionResult Get(Guid id) { var item = this.Data.Courses.GetById(id); if (item != null) { var result = new CourseModel() { Name = item.Name, Description = item.Description }; return this.Ok(result); } return this.NotFound(); }
public IHttpActionResult Post(CourseModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Incorrect data"); } var item = new Course() { Name = model.Name, Description = model.Description }; this.Data.Courses.Add(item); this.Data.SaveChanges(); return this.Ok("Record added"); }
public IHttpActionResult Update(Guid id, CourseModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Invalid model"); } var item = this.Data.Courses.GetById(id); if (item == null) { return this.NotFound(); } item.Name = model.Name; item.Description = model.Description; this.Data.Courses.Update(item); this.Data.SaveChanges(); return this.Ok("Updated"); }