Beispiel #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "updatelibrarybookstatus")] 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();
                LibraryBookStatusApiModel model = JsonConvert.DeserializeObject <LibraryBookStatusApiModel>(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 = _libraryBookStatusWebApiManager.UpdateLibraryBookStatus(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] LibraryBookStatusApiModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            model.ModifiedBy = GetCurrentUser();

            var result = _libraryBookStatusWebApiManager.UpdateLibraryBookStatus(model);

            switch (result)
            {
            case 1:
                return(Ok());

            default:
                ModelState.AddModelError(string.Empty, "Unable to Update book status");
                break;
            }

            return(BadRequest(ModelState));
        }