public async Task <IActionResult> UpdateRiderLocation([FromBody] RiderLocation LocationData) { if (LocationData.RequestingId == LocationData.RiderId) { if (!_service.IsAuthorizedRider(LocationData.RequestingId, LocationData.Authorization)) { return(Unauthorized()); } } else if (!_service.IsAuthorizedAdmin(LocationData.RequestingId, LocationData.Authorization)) { return(Unauthorized()); } Rider riderToUpdate = await _context.Riders.SingleOrDefaultAsync(r => r.ID == LocationData.RiderId); try { if (riderToUpdate != null) { _service.UpdateRiderLocation(riderToUpdate, LocationData); return(Ok(LocationData)); } } catch (DbUpdateException) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } return(NotFound()); }