Exemplo n.º 1
0
        public async Task <CompanyFieldsDTO> Handle(GetCompanyFieldsCommand request, CancellationToken cancellationToken)
        {
            var dto = new CompanyFieldsDTO();

            dto.Groups = new List <CompanyFieldGroupItem>();
            var groups = await _companyFieldGroupRepository.Set().OrderBy(x => x.Sort).ToListAsync();

            var fields = await _companyFieldRepository.Set().OrderBy(x => x.Sort).ToListAsync();

            var fieldVlaues = await _companyFieldDefaultValueRepository.Set().OrderBy(x => x.Sort).ToListAsync();

            groups.ForEach(g =>
            {
                var group = new CompanyFieldGroupItem
                {
                    Id   = g.Id,
                    Name = g.Name,
                    Sort = g.Sort,
                    CompanyFieldItems = new List <CompanyFieldItem>()
                };
                var _fields = fields.Where(f => f.GroupId == g.Id).ToList();
                _fields.ForEach(f =>
                {
                    var fieldItem = new CompanyFieldItem
                    {
                        Id       = f.Id,
                        Name     = f.Name,
                        Sort     = f.Sort,
                        GroupId  = f.GroupId,
                        Alias    = f.Alias,
                        Type     = f.Type,
                        Required = f.Required,
                        CompanyFieldDefaultValues = new List <CompanyFieldDefaultValueItem>()
                    };

                    var _fieldVlaues = fieldVlaues.Where(v => v.CompanyFieldId == f.Id).ToList();

                    _fieldVlaues.ForEach(v =>
                    {
                        var valueItem = new CompanyFieldDefaultValueItem
                        {
                            Id      = v.Id,
                            Sort    = v.Sort,
                            Text    = v.Text,
                            Value   = v.Value,
                            FieldId = v.CompanyFieldId
                        };

                        fieldItem.CompanyFieldDefaultValues.Add(valueItem);
                    });
                    group.CompanyFieldItems.Add(fieldItem);
                });

                dto.Groups.Add(group);
            });


            return(dto);
        }
Exemplo n.º 2
0
        public async Task <CompanyEditDto> Handle(GetCompanyCommand request, CancellationToken cancellationToken)
        {
            var company = new CompanyEditDto();
            var dto     = new CompanyFieldsDTO
            {
                Groups = new List <CompanyFieldGroupItem>()
            };
            var _company = await _companyRepository.Set().FindAsync(request.CompanyId);

            company.CompanyId = _company.Id;
            company.Logo      = _company.Logo;
            company.Name      = _company.Name;
            company.Status    = _company.Status;

            var groups = await _companyFieldGroupRepository.Set().OrderBy(x => x.Sort).ToListAsync();

            var fields = await _companyFieldRepository.Set().OrderBy(x => x.Sort).ToListAsync();

            var fieldVlaues = await _companyFieldDefaultValueRepository.Set().OrderBy(x => x.Sort).ToListAsync();

            var data = await _companyFieldDataRepository.Set().Where(x => x.CompanyId == request.CompanyId).ToListAsync();


            groups.ForEach(g =>
            {
                var group = new CompanyFieldGroupItem
                {
                    Id   = g.Id,
                    Name = g.Name,
                    Sort = g.Sort,
                    CompanyFieldItems = new List <CompanyFieldItem>()
                };
                var _fields = fields.Where(f => f.GroupId == g.Id).ToList();
                _fields.ForEach(f =>
                {
                    var _value    = data.FirstOrDefault(x => x.FieldId == f.Id);
                    var fieldItem = new CompanyFieldItem
                    {
                        Id       = f.Id,
                        Name     = f.Name,
                        Sort     = f.Sort,
                        GroupId  = f.GroupId,
                        Alias    = f.Alias,
                        Type     = f.Type,
                        Required = f.Required,
                        CompanyFieldDefaultValues = new List <CompanyFieldDefaultValueItem>(),
                        Value = _value?.Value
                    };


                    var _fieldVlaues = fieldVlaues.Where(v => v.CompanyFieldId == f.Id).ToList();

                    _fieldVlaues.ForEach(v =>
                    {
                        var valueItem = new CompanyFieldDefaultValueItem
                        {
                            Id      = v.Id,
                            Sort    = v.Sort,
                            Text    = v.Text,
                            Value   = v.Value,
                            FieldId = v.CompanyFieldId
                        };

                        fieldItem.CompanyFieldDefaultValues.Add(valueItem);
                    });
                    group.CompanyFieldItems.Add(fieldItem);
                });

                dto.Groups.Add(group);
            });

            company.Fields = dto;
            return(company);
        }