public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "updatelibrarybook")] HttpRequest req, ILogger log) { try { var result = _tokenProvider.ValidateToken(req); if (result.Status == AccessTokenStatus.Valid) { log.LogInformation($"Request received for {result.Principal.Identity.Name}."); } else { return(new UnauthorizedResult()); } string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); LibraryBookApiModel model = JsonConvert.DeserializeObject <LibraryBookApiModel>(requestBody); if (model == null) { return(new BadRequestObjectResult("Please pass LibraryBookApiModel in the request body")); } int retVal = 0; if (model != null) { model.ModifiedBy = _tokenProvider.User; model.DateModified = DateTime.Now; retVal = _libraryBookWebApiManager.UpdateLibraryBook(model); } if (retVal < 1) { return(new BadRequestObjectResult("Failed to insert record")); } return(new OkResult()); } catch (Exception ex) { log.LogError($"Caught exception: {ex.Message}"); return(new BadRequestObjectResult(ex.Message)); } }
public IActionResult Update([FromBody] LibraryBookApiModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } model.ModifiedBy = GetCurrentUser(); var result = _libraryBookWebApiManager.UpdateLibraryBook(model); switch (result) { case 1: return(Ok()); default: ModelState.AddModelError(string.Empty, "Unable to Update user"); break; } return(BadRequest(ModelState)); }