Exemple #1
0
        public async Task <Unit> Handle(UpdateEntity request, CancellationToken cancellationToken)
        {
            var solution = await _solutionRepository.GetEntities()
                           .Where(e => e.Id == request.SolutionId)
                           .FirstOrDefaultAsync();

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var newEntity        = _mapper.Map <UpdateEntity, Generator.Models.Entity>(request);
            var oldEntity        = (await solutionAccessor.GetEntitiesAsync()).FirstOrDefault(e => e.Id == request.Id);
            await solutionAccessor.UpdateEntityAsync(newEntity);

            // reload Entity from Solution
            newEntity = (await solutionAccessor.GetEntitiesAsync())
                        .FirstOrDefault(e => e.Id == request.Id);
            await _codeGenerator.UpgradeEntityAsync(solutionAccessor, oldEntity, newEntity);

            await _codeGenerator.UpgradeViewAsync(solutionAccessor, new Generator.Models.View(), oldEntity, newEntity);

            return(Unit.Value);
        }
Exemple #2
0
        public async Task <EntityModel> Handle(GetEntity request, CancellationToken cancellationToken)
        {
            var solution = await _solutionRepository.GetEntities()
                           .Where(e => e.Id == request.SolutionId)
                           .FirstOrDefaultAsync();

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var entities         = await solutionAccessor.GetEntitiesAsync();

            var entity = entities.FirstOrDefault(e => e.Id == request.Id);

            return(_mapper.Map <Generator.Models.Entity, EntityModel>(entity));
        }
Exemple #3
0
        public async Task <Unit> Handle(GenerateEntity request, CancellationToken cancellationToken)
        {
            var solution = await _solutionRepository.GetEntities()
                           .Where(e => e.Id == request.SolutionId)
                           .FirstOrDefaultAsync();

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var entity           = (await solutionAccessor.GetEntitiesAsync()).FirstOrDefault(e => e.Id == request.Id);
            await _codeGenerator.GenerateEntityAsync(solutionAccessor, entity);

            await _codeGenerator.GenerateViewAsync(solutionAccessor, new Generator.Models.View(), entity);

            return(Unit.Value);
        }
Exemple #4
0
        public async Task <PageModel <EntityModel> > Handle(GetEntities request, CancellationToken cancellationToken)
        {
            var solution = await _solutionRepository.GetEntities()
                           .Where(e => e.Id == request.SolutionId)
                           .FirstOrDefaultAsync();

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var entities         = await solutionAccessor.GetEntitiesAsync();

            if (!string.IsNullOrEmpty(request.Filter?.Text))
            {
                entities = entities.Where(e => e.Name.Contains(request.Filter.Text, StringComparison.CurrentCultureIgnoreCase) ||
                                          e.PluralName.Contains(request.Filter.Text, StringComparison.CurrentCultureIgnoreCase) ||
                                          e.DisplayName.Contains(request.Filter.Text, StringComparison.CurrentCultureIgnoreCase) ||
                                          e.PluralDisplayName.Contains(request.Filter.Text, StringComparison.CurrentCultureIgnoreCase)).ToList();
            }
            return(entities.ToPagedList(request.PageIndex, request.PageSize)
                   .Map <Generator.Models.Entity, EntityModel>(_mapper));
        }
Exemple #5
0
        public async Task <Guid> Handle(CreateEntity request, CancellationToken cancellationToken)
        {
            var solution = await _solutionRepository.GetEntities()
                           .Where(e => e.Id == request.SolutionId)
                           .FirstOrDefaultAsync();

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var entity           = _mapper.Map <CreateEntity, Generator.Models.Entity>(request);

            entity.Id = Guid.NewGuid();
            await solutionAccessor.CreateEntityAsync(entity);

            // reload Entity from Solution
            entity = (await solutionAccessor.GetEntitiesAsync())
                     .First(e => e.Id == entity.Id);
            await _codeGenerator.GenerateEntityAsync(solutionAccessor, entity);

            await _codeGenerator.GenerateViewAsync(solutionAccessor, new Generator.Models.View(), entity);

            return(entity.Id);
        }