public HttpResponseMessage JobWaypointInsert([FromBody] JobOrderUpdateRequest model) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int JobScheduleId = 0; JobSchedule Sched = new JobSchedule(); Sched.JobId = model.JobId; Sched.ScheduleId = model.ScheduleId; Sched.Date = model.Date; if (model.Date != null && model.JobId != null) { try { JobScheduleId = _ScheduleService.JobScheduleUpsert(Sched); } catch (System.Exception ex) { throw (ex); } } JobScheduleItemsResponse <int> response = new JobScheduleItemsResponse <int>(); response.Items = _JobsService.SaveJob(model); response.JobScheduleId = JobScheduleId; return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public List <int> SaveJob(JobOrderUpdateRequest model) { List <int> list = new List <int>(); // create a list of WaypointIds, which are ints foreach (var waypoint in model.Waypoints) // goes through every Waypoint submitted in the payload { int waypointId = SaveWaypoint(waypoint); // Notice how this gets a waypointId after calling Savewaypoint() list.Add(waypointId); // This line gets exeuted after calling SaveWaypoint(), which calls another function SaveItem() } return(list); // this line executes last in this 'upsert' function }