public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "insertlibraryuser")] 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();
                LibraryUserApiModel model = JsonConvert.DeserializeObject <LibraryUserApiModel>(requestBody);

                if (model == null)
                {
                    return(new BadRequestObjectResult("Please pass LibraryUserApiModel in the request body"));
                }

                int    retVal          = 0;
                string libraryUserCode = string.Empty;
                if (model != null)
                {
                    model.CreatedBy    = _tokenProvider.User;
                    model.DateCreated  = DateTime.Now;
                    model.ModifiedBy   = _tokenProvider.User;
                    model.DateModified = DateTime.Now;

                    retVal = _libraryUserWebApiManager.InsertLibraryUser(model, out libraryUserCode);
                }

                if (retVal < 1)
                {
                    return(new BadRequestObjectResult("Failed to insert record"));
                }

                return((ActionResult) new OkObjectResult(new ContentResult
                {
                    Content = libraryUserCode,
                    ContentType = "text/plain",
                    StatusCode = 200
                }));
            }
            catch (Exception ex)
            {
                log.LogError($"Caught exception: {ex.Message}");
                return(new BadRequestObjectResult(ex.Message));
            }
        }
        public IActionResult Insert([FromBody] LibraryUserApiModel model)
        {
            int result          = 0;
            var libraryUserCode = "";

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (model != null)
            {
                model.CreatedBy    = GetCurrentUser();
                model.DateCreated  = DateTime.Now;
                model.ModifiedBy   = GetCurrentUser();
                model.DateModified = DateTime.Now;

                result = _libraryUserWebApiManager.InsertLibraryUser(model, out libraryUserCode);
            }

            switch (result)
            {
            case 1:
                return(new ContentResult
                {
                    Content = libraryUserCode,
                    ContentType = "text/plain",
                    StatusCode = 200
                });

            default:
                ModelState.AddModelError(string.Empty, "Failed to insert record");
                break;
            }

            return(BadRequest(ModelState));
        }