public IHttpActionResult Create(HomeworksOutputModel homeworksInfo) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var newHomework = new Homework() { Id = homeworksInfo.Id, FilePath = homeworksInfo.FilePath, SentDateTime = homeworksInfo.SentDateTime }; this.studentData.Homeworks.Add(newHomework); homeworksInfo.Id = newHomework.Id; return this.Ok(homeworksInfo); }
public IHttpActionResult Update(HomeworksOutputModel homeworksInfo) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var homeworkToUpdate = this.studentData.Homeworks.FirstOrDefault(hm => hm.Id == homeworksInfo.Id); if (homeworkToUpdate == null) { return this.BadRequest(NoSuchHomeWork); } homeworkToUpdate.FilePath = homeworksInfo.FilePath; homeworkToUpdate.SentDateTime = homeworksInfo.SentDateTime; this.studentData.SaveChanges(); return this.Ok(homeworksInfo); }