public IHttpActionResult Put(int id, AssignmentModel assignment) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var existingAssignment = this.GetCurrentAssignment(id); if (existingAssignment == null) { return BadRequest("Assignment does not exist."); } var newAssignment = new Assignment { Name = assignment.Name, Description = assignment.Description, Priority = assignment.Priority, Status = (AssignmentStatus)Enum.Parse(typeof(AssignmentStatus), assignment.Status) }; existingAssignment = newAssignment; this.data.SaveChanges(); return Ok(); }
public IHttpActionResult Create(int id, AssignmentModel assignment) { if (!this.ModelState.IsValid) { return BadRequest(this.ModelState); } var teamwork = this.data.TeamWorks.Find(id); if (teamwork == null) { return BadRequest("Teamwork does not exist - invalid id"); } var newAssignment = new Assignment { Name = assignment.Name, Description = assignment.Description, Priority = assignment.Priority }; teamwork.Assignments.Add(newAssignment); this.data.SaveChanges(); assignment.Id = newAssignment.Id; return Ok(assignment); }