Exemple #1
0
        public async Task <IActionResult> CheckCodeExist([FromBody] TemplateCheckCodeExistRequest request)
        {
            try
            {
                TemplateCheckCodeExistResponse response = new TemplateCheckCodeExistResponse();
                ValidationResult validate = TemplateCheckCodeExistRequestValidate.ValidateModel(request);
                if (validate.IsValid)
                {
                    response = await _templateConfigAppService.TemplateConfigCheckCodeExist(request);
                }
                else
                {
                    response.SetFail(validate.Errors.Select(p => p.ToString()));
                }

                return(Json(response));
            }
            catch (Exception e)
            {
                _logger.LogError(e, Common.Common.GetMethodName(), request);
                throw;
            }
        }
        public async Task <TemplateCheckCodeExistResponse> TemplateConfigCheckCodeExist(
            TemplateCheckCodeExistRequest request)
        {
            TemplateCheckCodeExistResponse response = new TemplateCheckCodeExistResponse();

            try
            {
                RTemplateConfig[] templateConfigs = await _templateService.GetTemplateConfigByTemplateId(request.TemplateId);

                if (!string.IsNullOrEmpty(request.CurrentTemplateConfigId))
                {
                    templateConfigs = templateConfigs.Where(p => p.Id != request.CurrentTemplateConfigId).ToArray();
                }
                response.IsExist = templateConfigs != null && templateConfigs.Length > 0 &&
                                   templateConfigs.Any(p => p.TemplatePositionCode == request.Code);
                response.SetSucess();
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }