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()); }
public bool IsAuthorizedAdmin(FollowRequestData RequestData) { return(_riderService.IsAuthorizedAdmin(RequestData.RequestingId, RequestData.Authorization)); /* * bool result = false; * if (RiderExists(RequestData.RequestingId)) * { * if (Auth.IsValidToken(RequestData.Authorization)) * { * Rider foundRider = _context.Riders.SingleOrDefault(m => m.ID == RequestData.RequestingId); * if (foundRider != null) * { * string userAuth = Auth.GenerateJWT(foundRider); * if ((RequestData.Authorization == userAuth) && * (foundRider.Role == "Admin")) * result = true; * } * } * } * return result; */ }
public bool IsAuthorizedAdmin(RidesRequestData RequestData) { return(_riderService.IsAuthorizedAdmin(RequestData.RiderId, RequestData.Authorization)); }