public async Task <IHttpActionResult> Put(int id, [FromBody] MeetingDtoModel meeting) { if (meeting == null) { return(BadRequest("Required data was not supplied.")); } if (!await Exists(id)) { return(NotFound()); } var record = await db.Meetings.FindAsync(id); if (meeting.DateTime != null && record.DateTime != meeting.DateTime) { record.DateTime = meeting.DateTime; } if (meeting.Notes != null && record.Notes != meeting.Notes) { record.Notes = meeting.Notes; } if (meeting.BoardMeetingLocation.ID != null && record.BoardMeetingLocationID != meeting.BoardMeetingLocation.ID) { record.BoardMeetingLocationID = (int)meeting.BoardMeetingLocation.ID; } return(await SaveChanges(record, ActionType.Put)); }
public async Task <IHttpActionResult> Post([FromBody] MeetingDtoModel meeting) { if (meeting == null || meeting.BoardMeetingLocation?.ID == null) { return(BadRequest("Required data was not supplied.")); } if (await Exists(meeting.DateTime)) { return(Conflict()); } var record = Mapper.Map <MeetingModel>(meeting); record.BoardMeetingLocationID = (int)meeting.BoardMeetingLocation.ID; record.BoardMeetingLocation = null; // Otherwise, it will try to create a new location db.Meetings.Add(record); return(await SaveChanges(record, ActionType.Post)); }