Exemplo n.º 1
0
    private async Task <bool> ImportTags(IKntService service, List <EtiquetaExport> etiquetas)
    {
        int orderAtrTab = 0;
        int orderAtr    = 0;

        var filtroEtiquetas = etiquetas
                              .Where(e => (e.CodPadre == "[!EtiquetaRaiz]" || e.CodPadre == "UU") &&
                                     (e.CodEtiqueta != "TB" && e.CodEtiqueta != "ND" && e.CodEtiqueta != "OP" && e.CodEtiqueta != "TR" && e.CodEtiqueta != "TU" && e.CodEtiqueta != "UU"))
                              .Select(e => e).OrderBy(e => e.DesEtiqueta).ToList();

        foreach (var e in filtroEtiquetas)
        {
            listMessages.Items.Add($"{e.DesEtiqueta} - {e.CodEtiqueta} - {e.CodPadre?.ToString()}");
            KAttributeDto attributeDto = new KAttributeDto
            {
                Description        = $"[{e.CodEtiqueta}] - " + e.DesEtiqueta,
                Name               = e.DesEtiqueta,
                KAttributeDataType = EnumKAttributeDataType.TagsValue,
                Disabled           = false,
                Order              = orderAtr++,
                RequiredValue      = false
            };

            var tabulatedValues = etiquetas.Where(ev => ev.CodPadre == e.CodEtiqueta).Select(ev => ev).ToList();
            List <KAttributeTabulatedValueDto> tabulatedValuesAtr = new List <KAttributeTabulatedValueDto>();
            orderAtrTab = 0;
            foreach (var t in tabulatedValues)
            {
                KAttributeTabulatedValueDto atrValue = new KAttributeTabulatedValueDto
                {
                    Value       = t.DesEtiqueta,
                    Description = $"[{t.CodEtiqueta}] - " + t.DesEtiqueta,
                    Order       = orderAtrTab++
                };
                tabulatedValuesAtr.Add(atrValue);
            }

            attributeDto.KAttributeValues = tabulatedValuesAtr;

            // Hack import TareasDesarrolloDB
            if (attributeDto.Name == "Consejería de Educación")
            {
                attributeDto.Name        = "00 - Usuario Consejería de Educación";
                attributeDto.Description = $"[{e.CodEtiqueta}] - " + attributeDto.Name;
                attributeDto.Order       = 0;
            }
            if (attributeDto.Name == "Empresa de Servicios TIC")
            {
                attributeDto.Name        = "00 - Usuarios Empresa de Servicios TIC";
                attributeDto.Description = $"[{e.CodEtiqueta}] - " + attributeDto.Name;
                attributeDto.Order       = 0;
            }
            //if (attributeDto.Name[0] == '!')
            //    attributeDto.Name = attributeDto.Name.Substring(1, attributeDto.Name.Length - 1 );

            // Save Data
            var res = await service.KAttributes.SaveAsync(attributeDto);
        }

        return(await Task.FromResult <bool>(true));
    }
Exemplo n.º 2
0
        private async Task <Result <KAttributeTabulatedValueDto> > SaveTabulateValueAsync(KntDbContext ctx, Guid attributeId, KAttributeTabulatedValueDto entity)
        {
            Result <KAttributeTabulatedValue> resRep = null;
            var resService = new Result <KAttributeTabulatedValueDto>();

            try
            {
                var kattributeTabulatedValues = new GenericRepositoryEF <KntDbContext, KAttributeTabulatedValue>(ctx);

                if (entity.KAttributeTabulatedValueId == Guid.Empty)
                {
                    entity.KAttributeTabulatedValueId = Guid.NewGuid();
                    var newEntity = new KAttributeTabulatedValue();
                    newEntity.SetSimpleDto(entity);
                    newEntity.KAttributeId = attributeId;
                    resRep = await kattributeTabulatedValues.AddAsync(newEntity);
                }
                else
                {
                    var entityForUpdate = kattributeTabulatedValues.Get(entity.KAttributeTabulatedValueId).Entity;
                    if (entityForUpdate != null)
                    {
                        entityForUpdate.SetSimpleDto(entity);
                        resRep = await kattributeTabulatedValues.UpdateAsync(entityForUpdate);
                    }
                    else
                    {
                        var newEntity = new KAttributeTabulatedValue();
                        newEntity.SetSimpleDto(entity);
                        newEntity.KAttributeId = attributeId;
                        resRep = await kattributeTabulatedValues.AddAsync(newEntity);
                    }
                }
            }
            catch (Exception ex)
            {
                AddExecptionsMessagesToErrorsList(ex, resService.ErrorList);
            }

            resService.Entity    = resRep.Entity?.GetSimpleDto <KAttributeTabulatedValueDto>();
            resService.ErrorList = resRep.ErrorList;

            return(ResultDomainAction(resService));
        }