Пример #1
0
        public async Task <ValidationResultModel> ValidateAsync(OrganizationDto model)
        {
            // Reset validation errors
            model.Errors.Clear();

            #region Formatting: Cleansing and formatting
            model.Code        = model.Code.ToUpper();
            model.Name        = model.Name.TrimExtraSpaces();
            model.Description = model.Description.TrimExtraSpaces();
            #endregion

            #region Validation: Duplicate
            // Check code duplicate
            var duplCode = new ParentDuplicate {
                Field = DuplicateField.Code, Value = model.Code, Id = model.Id
            };
            if (await ExistsAsync(duplCode))
            {
                model.Errors.AddError(nameof(model.Code), $"{nameof(model.Code)} '{model.Code}' already exists");
            }
            // Check name duplicate
            var duplName = new ParentDuplicate {
                Field = DuplicateField.Name, Value = model.Name, Id = model.Id
            };
            if (await ExistsAsync(duplName))
            {
                model.Errors.AddError(nameof(model.Name), $"{nameof(model.Name)} '{model.Name}' already exists");
            }
            #endregion

            return(model.Errors);
        }
Пример #2
0
 public Task <bool> ExistsAsync(ParentDuplicate data) => _context.ExistsAsync <Organization>(data);