Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public async Task <Result <FolderDto> > UpdateAsync(FolderDto entity)
        {
            var resGenRep = new Result <Folder>();
            var response  = new Result <FolderDto>();

            try
            {
                var ctx     = GetOpenConnection();
                var folders = new GenericRepositoryEF <KntDbContext, Folder>(ctx);

                var resGenRepGet = await folders.GetAsync(entity.FolderId);

                Folder entityForUpdate;

                if (resGenRepGet.IsValid)
                {
                    entityForUpdate = resGenRepGet.Entity;
                    entityForUpdate.SetSimpleDto(entity);
                    entityForUpdate.ModificationDateTime = DateTime.Now;
                    resGenRep = await folders.UpdateAsync(entityForUpdate);
                }
                else
                {
                    resGenRep.Entity = null;
                    resGenRep.AddErrorMessage("Can't find entity for update.");
                }

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

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

            return(ResultDomainAction(response));
        }
Ejemplo n.º 3
0
        public async Task <Result <SystemValueDto> > UpdateAsync(SystemValueDto entity)
        {
            var resGenRep = new Result <SystemValue>();
            var response  = new Result <SystemValueDto>();

            try
            {
                var ctx          = GetOpenConnection();
                var systemValues = new GenericRepositoryEF <KntDbContext, SystemValue>(ctx);

                var resGenRepGet = await systemValues.GetAsync(entity.SystemValueId);

                SystemValue entityForUpdate;

                if (resGenRepGet.IsValid)
                {
                    entityForUpdate = resGenRepGet.Entity;
                    entityForUpdate.SetSimpleDto(entity);
                    resGenRep = await systemValues.UpdateAsync(entityForUpdate);
                }
                else
                {
                    resGenRep.Entity = null;
                    resGenRep.AddErrorMessage("Can't find entity for update.");
                }

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

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

            return(ResultDomainAction(response));
        }
Ejemplo n.º 4
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));
        }