示例#1
0
        public async Task <ActionResult <bool> > Enqueued([FromForm] string code, [FromForm] string pass, [FromForm] string captcha = "")
        {
            try
            {
                if (string.IsNullOrEmpty(code))
                {
                    throw new ArgumentException("Zadajte svoj 9 miestny kód registrácie");
                }

                if (string.IsNullOrEmpty(pass))
                {
                    throw new ArgumentException("Zadajte posledné štvorčíslie svojho rodného čísla");
                }

                if (!string.IsNullOrEmpty(configuration["googleReCaptcha:SiteKey"]))
                {
                    if (string.IsNullOrEmpty(captcha))
                    {
                        throw new Exception("Please provide captcha");
                    }

                    var validation = await captchaValidator.IsCaptchaPassedAsync(captcha);

                    if (!validation)
                    {
                        throw new Exception("Please provide valid captcha");
                    }
                }
                var codeClear = ResultController.FormatBarCode(code);
                if (int.TryParse(codeClear, out var codeInt))
                {
                    return(Ok(await visitorRepository.Enqueued(codeInt, pass)));
                }
                throw new Exception("Registračný kód vyzerá byť neplatný");
            }
            catch (ArgumentException exc)
            {
                logger.LogError(exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
        }