Exemplo n.º 1
0
        public async Task <IActionResult> UpdateContextWrapepr([FromBody] ContextDto context)
        {
            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(context, null, null);
            var validationResults = new List <ValidationResult>();

            Validator.TryValidateObject(context, validationContext, validationResults, true);

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

            if (!HasAccess(_validationRepo.GetContextOwnerId(context.Id)))
            {
                return(StatusCode(403));
            }

            var contextObj = _mapper.Map <ContextWrapper>(context);

            if (await _patternRepo.UpdateContextAsync(contextObj))
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> AddBotResponse([FromBody] BotResponseDto resp)
        {
            if (resp == null)
            {
                return(BadRequest());
            }

            if (!HasAccess(_validationRepo.GetContextOwnerId(resp.PatternId)))
            {
                return(StatusCode(403));
            }

            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(resp, null, null);
            var validationResults = new List <ValidationResult>();

            Validator.TryValidateObject(resp, validationContext, validationResults, true);

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

            BotResponse respObj = _mapper.Map <BotResponse>(resp);

            if (await _patternRepo.AddBotResponseToPatternAsync(respObj))
            {
                return(StatusCode(201));
            }
            else
            {
                return(BadRequest());
            };
        }