示例#1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var validator = new CompanyViewModelValidator();
            var result    = validator.Validate(this);

            return(result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new[] { item.PropertyName })));
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!PageContext.ModelState.IsValid)
            {
                var validator   = new CompanyViewModelValidator();
                var createCheck = validator.Validate(Company);
                createCheck.AddToModelState(ModelState, nameof(Company));

                return(Page());
            }

            var company = new Company
            {
                Name = Company.Name,
                Nip  = Company.Nip,
                BankAccountNumber = Company.BankAccountNumber,
                OwnerId           = SelectedUser
            };

            await _companyService.AddAsync(company);

            return(Redirect("/"));
        }