Esempio n. 1
0
        public Result <Boolean> Update(EmployeePassDto item)
        {
            var currentPass = _employeePassRepository.Get(item.PassId);

            if (currentPass == null)
            {
                return(Result <bool> .Failed($"Пропуск под номером {item.PassId} не найден"));
            }

            var domainModel      = EntityMapper.MapEmployeePassToDomain(item);
            var validationResult = EmployeePassValidator.Validate(domainModel);

            if (validationResult.IsFailed)
            {
                return(Result <bool> .Failed(validationResult.Errors));
            }

            _employeePassRepository.Update(domainModel);

            return(Result <bool> .Success(true));
        }
Esempio n. 2
0
        public Result <int?> Add(EmployeePassDto employeePass)
        {
            try
            {
                var domainModel = EntityMapper.MapEmployeePassToDomain(employeePass);

                var validationResult = EmployeePassValidator.Validate(domainModel);
                if (validationResult.IsFailed)
                {
                    return(Result <int?> .Failed(validationResult.Errors));
                }

                var passId = _employeePassRepository.Create(domainModel);

                return(Result <int?> .Success(passId));
            }
            catch (Exception e)
            {
                //write to log error
                return(Result <int?> .Failed("Ошибка при создании нового пропуска"));
            }
        }