public async Task <IActionResult> PutLocationRoute([FromRoute] int id, [FromBody] LocationRoute locationRoute) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != locationRoute.locationRouteID) { return(BadRequest()); } _context.Entry(locationRoute).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocationRouteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSubscriber([FromRoute] int id, [FromBody] Subscriber subscriber) { //If we failed the Authorize claims check, the response code will be set to 401 if (this.Response.StatusCode == 401) { return(Unauthorized()); } var tokenIn = this.HttpContext.Request.Headers.GetCommaSeparatedValues("Authorization"); tokenIn[0] = tokenIn[0].Substring(7); var handler = new JwtSecurityTokenHandler(); var token = handler.ReadJwtToken(tokenIn[0]); bool valid = false; foreach (Claim claim in token.Claims) { if (claim.Type.Equals("ID")) { if (claim.Value.Equals(id.ToString())) { valid = true; } } } if (!valid) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != subscriber.subscriberID) { return(BadRequest()); } _context.Entry(subscriber).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubscriberExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }