public IHttpActionResult Get(int id) { var item = this.Data.Homeworks.GetById(id); if (item != null) { var result = new HomeworkModel() { FileUrl = item.FileUrl, TimeSent = item.TimeSent, StudentId = item.StudentId, CourseId = item.CourseId }; return this.Ok(result); } return this.NotFound(); }
public IHttpActionResult Post(HomeworkModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Incorrect data"); } // Just adding first student and course var item = new Homework() { FileUrl = model.FileUrl, TimeSent = DateTime.Now, StudentId = this.Data.Students.All().First().Id, CourseId = this.Data.Courses.All().First().Id }; this.Data.Homeworks.Add(item); this.Data.SaveChanges(); return this.Ok("Record added"); }