Beispiel #1
0
        public override SingleEntityResponse <UnitModel> Create(UnitModel model)
        {
            var newUnitValidator = new NewUnitValidator(_companyService, _translationsService, this, _unitTypeService);
            var validationResult = newUnitValidator.Validate(model);

            if (!validationResult.IsValid)
            {
                return(new SingleEntityResponse <UnitModel>(model, validationResult.GetErrorsObjects().ToList()));
            }
            return(base.Create(model));
        }
Beispiel #2
0
        public override ListEntityResponse <UnitModel> Create(IEnumerable <UnitModel> models)
        {
            var newUnitValidator = new NewUnitValidator(_companyService, _translationsService, this, _unitTypeService);
            var responses        = new List <SingleEntityResponse <UnitModel> >();

            foreach (var model in models)
            {
                var validationResult = newUnitValidator.Validate(model);
                if (!validationResult.IsValid)
                {
                    responses.Add(new SingleEntityResponse <UnitModel>(model, validationResult.GetErrorsObjects().ToList()));
                }
            }

            if (responses.Any(r => r.Errors != null))
            {
                return(new ListEntityResponse <UnitModel>(responses));
            }

            return(base.Create(models));
        }