コード例 #1
0
        public new TEntity Create(TEntity entity)
        {
            var ormLibEntity = repository.Create(libMapper.MapToDal(entity));
            var lib          = entity;

            uow.Commit();
            entity.Id = ormLibEntity.id;
            ISelectedEntityMapper <UEntity> selectedEntityMapper = new SelectedEntityMapper <UEntity, Service>(uow);

            foreach (var Entity in lib.SelectedEntities)
            {
                var dalEntity = selectedEntityMapper.MapToDal(Entity);
                dalEntity.Lib_id = entity.Id;
                var ormEntity = selectedEntityRepository.Create(dalEntity);
                uow.Commit();
                Entity.Id = ormEntity.id;
            }

            return(lib);
        }
コード例 #2
0
        public new TEntity Update(TEntity entity)
        {
            ISelectedEntityMapper <UEntity> selectedEntityMapper = new SelectedEntityMapper <UEntity, Service>(uow);
            var lib = (IBllEntityLib <UEntity>)entity;

            foreach (var Entity in lib.SelectedEntities)
            {
                var dalEntity = selectedEntityMapper.MapToDal(Entity);
                dalEntity.Lib_id = entity.Id;
                if (Entity.Id == 0)
                {
                    selectedEntityRepository.Create(dalEntity);
                }
                else
                {
                    selectedEntityRepository.Update(dalEntity);
                }
            }
            var EntitysWithLibId = ((IGetterByLibId <IDalSelectedEntity>)selectedEntityRepository).GetEntitiesByLibId(entity.Id);

            foreach (var Entity in EntitysWithLibId)
            {
                bool isTrashEntity = true;
                foreach (var selectedEntity in lib.SelectedEntities)
                {
                    if (Entity.Id == selectedEntity.Id)
                    {
                        isTrashEntity = false;
                        break;
                    }
                }
                if (isTrashEntity == true)
                {
                    selectedEntityRepository.Delete(Entity.Id);
                }
            }
            uow.Commit();

            return((TEntity)lib);
        }