Exemplo n.º 1
0
        public virtual ValidationResult Add(TEntity entity)
        {
            if (!_validationResult.IsValid)
            {
                return(_validationResult);
            }

            var selfValidationEntity = entity as ISelfValidation;

            if (selfValidationEntity != null && !selfValidationEntity.IsValid)
            {
                return(selfValidationEntity.ValidationResult);
            }

            if (!_dapperRepository.Add(entity))
            {
                _validationResult.Add(string.Format("添加实体对象{0}失败", entity.GetType().FullName));
            }
            var baseEntity = entity as BaseEntity;

            if (baseEntity != null)
            {
                _validationResult.SetData(LsConstant.IdKey, baseEntity.Id);
            }

            return(_validationResult);
        }
        public async Task HandleDapperLogic()
        {
            IDapperRepository <Employee> _dapperRepositoryValue = _dapperRepository.Value;

            Guid id  = Guid.NewGuid();
            var  emp = new Employee {
                Id = id, first_name = "aaa11", last_name = "bbb11"
            };
            await _dapperRepositoryValue.Add(emp);

            emp.address = "tehran";
            await _dapperRepositoryValue.Update(emp);

            await _dapperRepositoryValue.Commit();

            Employee given = await _dapperRepositoryValue.FindById(id, nameof(Employee));

            await _dapperRepositoryValue.Remove(emp);

            await _dapperRepositoryValue.Commit();
        }
Exemplo n.º 3
0
 public object Add(ObjectDTO obj)
 {
     return(_dapperRepository.Add(_mapper.Map <TEntity>(obj)));
 }