示例#1
0
        public async Task <bool> TestDbConnection()
        {
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <KntDbContext>();

                if (_repositoryRef.Provider == "Microsoft.Data.SqlClient")
                {
                    optionsBuilder.UseSqlServer(_repositoryRef.ConnectionString);
                }
                else if (_repositoryRef.Provider == "Microsoft.Data.Sqlite")
                {
                    optionsBuilder.UseSqlite(_repositoryRef.ConnectionString);
                    optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.AmbientTransactionWarning));
                }
                else
                {
                    return(false);
                }

                var dbContext    = new KntDbContext(optionsBuilder.Options, false);
                var systemValues = new KntSystemValuesRepository(dbContext, _repositoryRef);
                var res          = await systemValues.GetAllAsync();

                if (!res.IsValid)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        public virtual async Task <bool> CloseIsTempConnection(KntDbContext db)
        {
            try
            {
                if (SingletonConnection == null)
                {
                    await db.DisposeAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#3
0
 public KntNoteTypeRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }
示例#4
0
 public KntRepository(KntDbContext singletonContext)
 {
     _context = singletonContext;
 }
示例#5
0
 public KntSystemValuesRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }
示例#6
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));
        }
示例#7
0
 private async Task DeleteNoContainsTabulateValueAsync(KntDbContext ctx, Guid attributeId, List <Guid> guids)
 {
     var kattributeTabulatedValues = new GenericRepositoryEF <KntDbContext, KAttributeTabulatedValue>(ctx);
     var tabValuesForDelete        = (await kattributeTabulatedValues.GetAllAsync(v => (v.KAttributeId == attributeId && !guids.Contains(v.KAttributeTabulatedValueId)))).Entity;
     var res = kattributeTabulatedValues.DeleteRange(tabValuesForDelete);
 }
示例#8
0
 public KntKAttributeRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }
示例#9
0
 public KntRepositoryBase(KntDbContext singletonConnection, RepositoryRef repositoryRef)
 {
     SingletonConnection             = singletonConnection;
     _repositoryRef                  = repositoryRef;
     _repositoryRef.ConnectionString = singletonConnection.Database.GetConnectionString();
 }
示例#10
0
 public KntFolderRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }