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

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var newEnum          = _mapper.Map <UpdateEnum, Generator.Models.Enum>(request);
            var oldEnum          = (await solutionAccessor.GetEnumsAsync()).FirstOrDefault(e => e.Id == request.Id);
            await solutionAccessor.UpdateEnumAsync(newEnum);

            // reload Enum from Solution
            newEnum = (await solutionAccessor.GetEnumsAsync())
                      .FirstOrDefault(e => e.Id == request.Id);
            await _codeGenerator.UpgradeEnumAsync(solutionAccessor, oldEnum, newEnum);

            await _codeGenerator.UpgradeEnumViewAsync(solutionAccessor, new Generator.Models.View(), oldEnum, newEnum);

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

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var enums            = await solutionAccessor.GetEnumsAsync();

            var @enum = enums.FirstOrDefault(e => e.Id == request.Id);

            return(_mapper.Map <Generator.Models.Enum, EnumModel>(@enum));
        }
Beispiel #3
0
        public async Task <Unit> Handle(GenerateEnum request, CancellationToken cancellationToken)
        {
            var solution = await _solutionRepository.GetEntities()
                           .Where(e => e.Id == request.SolutionId)
                           .FirstOrDefaultAsync();

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var @enum            = (await solutionAccessor.GetEnumsAsync()).FirstOrDefault(e => e.Id == request.Id);
            await _codeGenerator.GenerateEnumAsync(solutionAccessor, @enum);

            await _codeGenerator.GenerateEnumViewAsync(solutionAccessor, new Generator.Models.View(), @enum);

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

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var enums            = await solutionAccessor.GetEnumsAsync();

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

            var solutionAccessor = new SolutionAccessor(solution.Path);
            var @enum            = _mapper.Map <CreateEnum, Generator.Models.Enum>(request);

            @enum.Id = Guid.NewGuid();
            await solutionAccessor.CreateEnumAsync(@enum);

            // reload Enum from Solution
            @enum = (await solutionAccessor.GetEnumsAsync())
                    .First(e => e.Id == @enum.Id);
            await _codeGenerator.GenerateEnumAsync(solutionAccessor, @enum);

            await _codeGenerator.GenerateEnumViewAsync(solutionAccessor, new Generator.Models.View(), @enum);

            return(@enum.Id);
        }