Exemplo n.º 1
0
        protected override async Task SaveValidateAsync(List <AccountForSave> entities)
        {
            //foreach (var (entity, index) in entities.Select((e, i) => (e, i)))
            //{
            //    if (ModelState.HasReachedMaxErrors)
            //    {
            //        // No need to keep going forever
            //        break;
            //    }
            //}

            //// No need to invoke SQL if the model state is full of errors
            //if (ModelState.HasReachedMaxErrors)
            //{
            //    // null Ids will cause an error when calling the SQL validation
            //    return;
            //}

            // SQL validation
            int remainingErrorCount = ModelState.MaxAllowedErrors - ModelState.ErrorCount;
            var sqlErrors           = await _repo.Accounts_Validate__Save(entities, top : remainingErrorCount);

            // Add errors to model state
            ModelState.AddLocalizedErrors(sqlErrors, _localizer);
        }
Exemplo n.º 2
0
        protected override async Task SaveValidateAsync(List <AccountForSave> entities)
        {
            foreach (var(entity, index) in entities.Select((e, i) => (e, i)))
            {
                //if (entity.IsSmart ?? false)
                //{
                //    // These are required for smart accounts
                //    if(entity.ContractType == null)
                //    {
                //        string path = $"[{index}].{nameof(entity.ContractType)}";
                //        string propDisplayName = _localizer["Account_ContractType"];
                //        string errorMsg = _localizer[nameof(RequiredAttribute), propDisplayName];

                //        ModelState.AddModelError(path, errorMsg);
                //    }
                //}

                if (ModelState.HasReachedMaxErrors)
                {
                    // No need to keep going forever
                    break;
                }
            }

            // No need to invoke SQL if the model state is full of errors
            if (ModelState.HasReachedMaxErrors)
            {
                // null Ids will cause an error when calling the SQL validation
                return;
            }

            // SQL validation
            int remainingErrorCount = ModelState.MaxAllowedErrors - ModelState.ErrorCount;
            var sqlErrors           = await _repo.Accounts_Validate__Save(entities, top : remainingErrorCount);

            // Add errors to model state
            ModelState.AddLocalizedErrors(sqlErrors, _localizer);
        }