示例#1
0
 public async Task <Result <KAttributeDto> > SaveAsync(KAttributeDto entity)
 {
     if (entity.KAttributeId == Guid.Empty)
     {
         entity.KAttributeId = Guid.NewGuid();
         return(await _repository.KAttributes.AddAsync(entity));
     }
     else
     {
         return(await _repository.KAttributes.UpdateAsync(entity));
     }
 }
示例#2
0
    public async Task <Result <KAttributeDto> > SaveAsync(KAttributeDto kattribute)
    {
        HttpResponseMessage httpRes;

        if (kattribute.KAttributeId == Guid.Empty)
        {
            httpRes = await _httpClient.PostAsJsonAsync <KAttributeDto>("api/kattributes", kattribute);
        }
        else
        {
            httpRes = await _httpClient.PutAsJsonAsync <KAttributeDto>("api/kattributes", kattribute);
        }

        var res = await httpRes.Content.ReadFromJsonAsync <Result <KAttributeDto> >();

        return(res);
    }
示例#3
0
    public async Task <Result <KAttributeDto> > AddAsync(KAttributeDto entity)
    {
        var result = new Result <KAttributeDto>();

        try
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var db = GetOpenConnection();

                var sql = @"INSERT INTO KAttributes  (KAttributeId, [Name], Description, KAttributeDataType, RequiredValue, [Order], Script, Disabled, NoteTypeId)
                            VALUES (@KAttributeId, @Name, @Description, @KAttributeDataType, @RequiredValue, @Order, @Script, @Disabled, @NoteTypeId)";

                var r = await db.ExecuteAsync(sql.ToString(),
                                              new { entity.KAttributeId, entity.Name, entity.Description, entity.KAttributeDataType, entity.RequiredValue, entity.Order, entity.Script, entity.Disabled, entity.NoteTypeId });

                if (r == 0)
                {
                    result.ErrorList.Add("Entity not inserted");
                }

                var resTabValues = await SaveTabulateValueAsync(db, entity.KAttributeId, entity.KAttributeValues);

                if (!resTabValues.IsValid)
                {
                    CopyErrorList(resTabValues.ErrorList, result.ErrorList);
                }

                result.Entity = entity;

                scope.Complete();

                await CloseIsTempConnection(db);
            }
        }
        catch (Exception ex)
        {
            AddExecptionsMessagesToErrorsList(ex, result.ErrorList);
        }
        return(ResultDomainAction(result));
    }
示例#4
0
        public async Task <Result <KAttributeDto> > AddAsync(KAttributeDto entity)
        {
            var response = new Result <KAttributeDto>();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var ctx         = GetOpenConnection();
                    var kattributes = new GenericRepositoryEF <KntDbContext, KAttribute>(ctx);

                    var newEntity = new KAttribute();
                    newEntity.SetSimpleDto(entity);

                    var resGenRep = await kattributes.AddAsync(newEntity);

                    response.Entity    = resGenRep.Entity?.GetSimpleDto <KAttributeDto>();
                    response.ErrorList = resGenRep.ErrorList;

                    foreach (var value in entity.KAttributeValues)
                    {
                        var res = await SaveTabulateValueAsync(ctx, response.Entity.KAttributeId, value);

                        if (!res.IsValid)
                        {
                            response.ErrorList.Add(res.Message);
                        }
                        response.Entity.KAttributeValues.Add(res.Entity);
                    }

                    scope.Complete();

                    await CloseIsTempConnection(ctx);
                }
            }
            catch (Exception ex)
            {
                AddExecptionsMessagesToErrorsList(ex, response.ErrorList);
            }
            return(ResultDomainAction(response));
        }
示例#5
0
        public async Task <IActionResult> Post([FromBody] KAttributeDto entity)
        {
            try
            {
                var kresApi = await _service.KAttributes.SaveAsync(entity);

                if (kresApi.IsValid)
                {
                    return(Ok(kresApi));
                }
                else
                {
                    return(BadRequest(kresApi));
                }
            }
            catch (Exception ex)
            {
                var kresApi = new Result <KAttributeInfoDto>();
                kresApi.AddErrorMessage("Generic error: " + ex.Message);
                return(BadRequest(kresApi));
            }
        }
示例#6
0
文件: LabForm.cs 项目: afumfer/KNote
    private void button3_Click(object sender, EventArgs e)
    {
        var attribute = new KAttributeDto();

        attribute.NoteTypeDto = new NoteTypeDto {
            Description = "aaa", Name = "bbbbb", NoteTypeId = Guid.NewGuid(), ParenNoteTypeId = null
        };

        attribute.KAttributeValues.Add(new KAttributeTabulatedValueDto
        {
            Description  = "bbb",
            KAttributeId = Guid.NewGuid()
            ,
            KAttributeTabulatedValueId = Guid.NewGuid(),
            Order = 1,
            Value = "111"
        });

        listMessages.Items.Add("TEST IsDirty: ");
        listMessages.Items.Add("----------------");
        listMessages.Items.Add("Original value IsDirty: " + attribute.IsDirty());
        listMessages.Items.Add("Original value NoteType IsDirty: " + attribute.NoteTypeDto.IsDirty());
        foreach (var a in attribute.KAttributeValues)
        {
            listMessages.Items.Add("Original value KAttributeValue IsDirty: " + a.IsDirty());
        }

        attribute.SetIsDirty(false);
        listMessages.Items.Add("==== changed IsDirty attribute to false with SetIsDirty()");

        listMessages.Items.Add("Changed value IsDirty: " + attribute.IsDirty());
        listMessages.Items.Add("Changed value NoteType IsDirty: " + attribute.NoteTypeDto.IsDirty());
        foreach (var a in attribute.KAttributeValues)
        {
            listMessages.Items.Add("Changed value KAttributeValue IsDirty: " + a.IsDirty());
        }

        attribute.KAttributeValues[0].Value = "222";
        listMessages.Items.Add("==== changed value to child object");

        listMessages.Items.Add("Changed value IsDirty: " + attribute.IsDirty());
        listMessages.Items.Add("Changed value NoteType IsDirty: " + attribute.NoteTypeDto.IsDirty());
        foreach (var a in attribute.KAttributeValues)
        {
            listMessages.Items.Add("Changed value KAttributeValue IsDirty: " + a.IsDirty());
        }

        listMessages.Items.Add("");
        listMessages.Items.Add("TEST IsValid: ");
        listMessages.Items.Add("----------------");
        listMessages.Items.Add("Original value IsValid: " + attribute.IsValid());
        listMessages.Items.Add("Original value NoteType IsValid: " + attribute.NoteTypeDto.IsValid());
        foreach (var a in attribute.KAttributeValues)
        {
            listMessages.Items.Add("Original value KAttributeValue IsValid: " + a.IsValid());
        }

        attribute.Name = "ZZZZZZZZZZ";

        listMessages.Items.Add("--OK --------------");
        listMessages.Items.Add("Original value IsValid: " + attribute.IsValid());
        listMessages.Items.Add("Original value NoteType IsValid: " + attribute.NoteTypeDto.IsValid());
        foreach (var a in attribute.KAttributeValues)
        {
            listMessages.Items.Add("Original value KAttributeValue IsValid: " + a.IsValid());
        }

        attribute.KAttributeValues[0].Value = "";

        listMessages.Items.Add("--Error --------------");
        listMessages.Items.Add("Original value IsValid: " + attribute.IsValid());
        listMessages.Items.Add("Original value NoteType IsValid: " + attribute.NoteTypeDto.IsValid());
        foreach (var a in attribute.KAttributeValues)
        {
            listMessages.Items.Add("Original value KAttributeValue IsValid: " + a.IsValid());
        }

        attribute.NoteTypeDto.Name = "";
        attribute.Name             = "";
        listMessages.Items.Add("--GetErrorMessage --------------");
        var errMsg = attribute.GetErrorMessage(false);

        listMessages.Items.Add(errMsg);
        errMsg = attribute.GetErrorMessage();
        listMessages.Items.Add(errMsg);
    }
示例#7
0
文件: LabForm.cs 项目: afumfer/KNote
    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));
    }
示例#8
0
    public async Task <Result <KAttributeDto> > UpdateAsync(KAttributeDto entity)
    {
        var result = new Result <KAttributeDto>();

        try
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var db = GetOpenConnection();

                // Check notetype in notes.
                if (entity.NoteTypeId != null)
                {
                    var sqlType     = @"SELECT NoteTypeId FROM KAttributes WHERE KAttributeId = @KAttributeId";
                    var noteTypeOld = await db.QueryFirstOrDefaultAsync <Guid?>(sqlType, new { KAttributeId = entity.KAttributeId });

                    if (noteTypeOld != entity.NoteTypeId)
                    {
                        var sqlType2 = "SELECT count(*) FROM NoteKAttributes WHERE KAttributeId = @KAttributeId";
                        var n        = await db.ExecuteScalarAsync <long>(sqlType2, new { KAttributeId = entity.KAttributeId });

                        if (n > 0)
                        {
                            result.AddErrorMessage("You can not change the note type for this attribute. This attribute is already being used by several notes. ");
                            result.Entity = entity;
                            return(result);
                        }
                    }
                }

                var sql = @"UPDATE KAttributes SET                     
                        [Name] = @Name, 
                        Description = @Description, 
                        KAttributeDataType = @KAttributeDataType, 
                        RequiredValue = @RequiredValue, 
                        [Order] = @Order, 
                        Script = @Script, 
                        Disabled = @Disabled, 
                        NoteTypeId = @NoteTypeId
                    WHERE KAttributeId = @KAttributeId";

                var r = await db.ExecuteAsync(sql.ToString(),
                                              new { entity.KAttributeId, entity.Name, entity.Description, entity.KAttributeDataType, entity.RequiredValue, entity.Order, entity.Script, entity.Disabled, entity.NoteTypeId });

                if (r == 0)
                {
                    result.ErrorList.Add("Entity not updated");
                }

                var resTabValues = await SaveTabulateValueAsync(db, entity.KAttributeId, entity.KAttributeValues);

                if (!resTabValues.IsValid)
                {
                    CopyErrorList(resTabValues.ErrorList, result.ErrorList);
                }

                result.Entity = entity;

                scope.Complete();

                await CloseIsTempConnection(db);
            }
        }
        catch (Exception ex)
        {
            AddExecptionsMessagesToErrorsList(ex, result.ErrorList);
        }
        return(ResultDomainAction(result));
    }
示例#9
0
        public async Task <Result <KAttributeDto> > UpdateAsync(KAttributeDto entity)
        {
            var resGenRep = new Result <KAttribute>();
            var response  = new Result <KAttributeDto>();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var ctx         = GetOpenConnection();
                    var kattributes = new GenericRepositoryEF <KntDbContext, KAttribute>(ctx);

                    var resGenRepGet = await kattributes.GetAsync(entity.KAttributeId);

                    KAttribute entityForUpdate;

                    if (resGenRepGet.IsValid)
                    {
                        // Check notetype in notes.
                        if (entity.NoteTypeId != null && resGenRepGet.Entity.NoteTypeId != entity.NoteTypeId)
                        {
                            var noteKAttributes = new GenericRepositoryEF <KntDbContext, NoteKAttribute>(ctx);
                            var nAttributes     = (await noteKAttributes.GetAllAsync(n => n.KAttributeId == entity.KAttributeId)).Entity;
                            if (nAttributes.Count > 0)
                            {
                                response.AddErrorMessage("You can not change the note type for this attribute. This attribute is already being used by several notes. ");
                                response.Entity = entity;
                            }
                        }

                        if (response.IsValid)
                        {
                            entityForUpdate = resGenRepGet.Entity;
                            entityForUpdate.SetSimpleDto(entity);

                            resGenRep = await kattributes.UpdateAsync(entityForUpdate);

                            response.Entity = resGenRep.Entity?.GetSimpleDto <KAttributeDto>();

                            var guidsUpdated = new List <Guid>();
                            foreach (var value in entity.KAttributeValues)
                            {
                                var res = await SaveTabulateValueAsync(ctx, response.Entity.KAttributeId, value);

                                if (!res.IsValid)
                                {
                                    response.ErrorList.Add(res.Message);
                                }
                                response.Entity.KAttributeValues.Add(res.Entity);
                                guidsUpdated.Add(value.KAttributeTabulatedValueId);
                            }

                            await DeleteNoContainsTabulateValueAsync(ctx, response.Entity.KAttributeId, guidsUpdated);

                            response.ErrorList = resGenRep.ErrorList;
                        }
                    }
                    else
                    {
                        response.Entity = entity;
                        response.AddErrorMessage("Can't find entity for update.");
                    }

                    scope.Complete();

                    await CloseIsTempConnection(ctx);
                }
            }
            catch (Exception ex)
            {
                AddExecptionsMessagesToErrorsList(ex, response.ErrorList);
            }

            return(ResultDomainAction(response));
        }