Ejemplo n.º 1
0
 public IEnumerable <T> Execute(bool includeDeleted = false)
 {
     if (typeof(ISoftEntity).IsAssignableFrom(typeof(T)) && !includeDeleted)
     {
         return(_context.Set <T>().Where(x => !(x as ISoftEntity).IsDeleted));
     }
     else
     {
         return(_context.Set <T>());
     }
 }
Ejemplo n.º 2
0
 public virtual bool Delete(TEntity entity)
 {
     if (entity == null)
     {
         throw new Exception("删除对象不能为空");
     }
     CoreContext.Set <TEntity>().Remove(entity);
     return(CoreContext.SaveChanges() > 0);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 插入并返回最新对象
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public virtual TEntity InsertReturnEntity(TEntity entity)
 {
     if (entity == null)
     {
         throw new Exception("新增对象不能为空");
     }
     CoreContext.Set <TEntity>().Add(entity);
     CoreContext.SaveChanges();
     return(entity);
 }
Ejemplo n.º 4
0
        public Processes GetProcess(string connectionString, int processId)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var query = from e in entityContext.Set <Processes>()
                            select e;

                var entitiy = query.Where(c => c.ProcessId == processId).FirstOrDefault();

                return(entitiy);
            }
        }
Ejemplo n.º 5
0
        public ExtractionJob GetExtractionJob(string connectionString, string code)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var query = from e in entityContext.Set <ExtractionJob>()
                            select e;

                var job = query.Where(c => c.Code == code).FirstOrDefault();

                return(job);
            }
        }
Ejemplo n.º 6
0
        public List <ExtractionJob> GetNewOrPendingExtractionJobs(string connectionString)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var query = from e in entityContext.Set <ExtractionJob>()
                            select e;

                var jobs = query.Where(c => c.Status == PackageStatus.New || c.Status == PackageStatus.Pending);

                return(jobs.ToList());
            }
        }
Ejemplo n.º 7
0
        public List <ExtractionJob> GetExtractionJobsToStop(string connectionString)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var query = from e in entityContext.Set <ExtractionJob>()
                            select e;

                var jobs = query.Where(c => c.Status == PackageStatus.Stop || c.Status == PackageStatus.Done || c.Status == PackageStatus.Fail);

                return(jobs.ToList());
            }
        }
Ejemplo n.º 8
0
        public List <ExtractionTrigger> GetExtractionTriggers(string connectionString, int jobId)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var query = from e in entityContext.Set <ExtractionTrigger>()
                            select e;

                var entities = query.Where(c => c.ExtractionJobId == jobId).ToList();

                return(entities);
            }
        }
Ejemplo n.º 9
0
        public Extraction GetExtraction(string connectionString, int extractionId)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var query = from e in entityContext.Set <Extraction>()
                            select e;

                var entitiy = query.Where(c => c.ExtractionId == extractionId).FirstOrDefault();

                return(entitiy);
            }
        }
        public void Add(TEntityDTO entity)
        {
            var mappedEntity = Mapper.Map <TEntity>(entity);

            Db.Set <TEntity>().Add(mappedEntity);
            Db.SaveChanges();
        }
Ejemplo n.º 11
0
        public void UpdateProcessTrigger(string connectionString, ProcessTrigger trigger)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var existingEntity = (from e in entityContext.Set <ProcessTrigger>()
                                      where e.ProcessTriggerId == trigger.ProcessTriggerId
                                      select e).FirstOrDefault();

                SimpleMapper.PropertyMap(trigger, existingEntity);

                entityContext.SaveChanges();
            }
        }
Ejemplo n.º 12
0
        public void UpdateExtractionJob(string connectionString, ExtractionJob job)
        {
            using (var entityContext = new CoreContext(connectionString))
            {
                var existingEntity = (from e in entityContext.Set <ExtractionJob>()
                                      where e.ExtractionJobId == job.ExtractionJobId
                                      select e).FirstOrDefault();

                SimpleMapper.PropertyMap(job, existingEntity);

                entityContext.SaveChanges();
            }
        }
Ejemplo n.º 13
0
 public virtual bool Insert(TEntity entity)
 {
     try
     {
         if (entity == null)
         {
             throw new Exception("新增对象不能为空");
         }
         CoreContext.Set <TEntity>().Add(entity);
         return(CoreContext.SaveChanges() > 0);
     }
     catch (DbEntityValidationException ex)
     {
         return(false);
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Returns all the active registries from the database
 /// </summary>
 /// <returns>List of Entities</returns>
 public virtual IQueryable <TEntity> GetAllActive()
 {
     return(Context.Set <TEntity>().Where(x => x.Active));
 }
Ejemplo n.º 15
0
 protected RepoBase()
 {
     Db    = new CoreContext();
     Table = Db.Set <T>();
 }
Ejemplo n.º 16
0
 protected RepoBase(DbContextOptions <CoreContext> options)
 {
     Db    = new CoreContext(options);
     Table = Db.Set <T>();
 }
Ejemplo n.º 17
0
 protected Repository(CoreContext context)
 {
     Db    = context;
     DbSet = Db.Set <TEntity>();
 }
Ejemplo n.º 18
0
 public BaseRepository(CoreContext context)
 {
     _context = context;
     _dbSet   = context.Set <TEntity>();
 }
Ejemplo n.º 19
0
 public virtual int Count(Expression <Func <TEntity, bool> > expression)
 {
     return(CoreContext.Set <TEntity>().Count(expression));
 }
Ejemplo n.º 20
0
 public virtual async Task <IEnumerable <T> > GetAllAsync()
 {
     return(await _context.Set <T>().ToListAsync());
 }
Ejemplo n.º 21
0
 public virtual IQueryable <TEntity> Find(Expression <Func <TEntity, bool> > expression)
 {
     return(CoreContext.Set <TEntity>().Where(expression));
 }
Ejemplo n.º 22
0
 protected Repository(CoreContext db)
 {
     Db         = db;
     DbSet      = Db.Set <TEntity>();
     Connection = Db.Database.GetDbConnection();
 }
Ejemplo n.º 23
0
 public virtual bool Insert(IEnumerable <TEntity> batch)
 {
     CoreContext.Set <TEntity>().AddRange(batch);
     return(CoreContext.SaveChanges() > 0);
 }
Ejemplo n.º 24
0
        protected override CommandResult <ProductData> OnExecute(object commandParameter)
        {
            var result = new CommandResult <ProductData>();
            var param  = commandParameter as LoadBookProductDetailParameter;

            using (CoreContext context = new CoreContext())
            {
                var bookConfig = new BookUtil();
                if (bookConfig._Config == null)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动已结束";
                    return(result);
                }
                if (DateTime.Now < bookConfig._Config.StartTime)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动未开始";
                    return(result);
                }
                if (bookConfig._Config.EndTime < DateTime.Now)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动已结束";
                    return(result);
                }

                var pmodel = bookConfig._ProductConfig.Where(p => p.ProductNo == param.ProductNo).FirstOrDefault();
                if (pmodel == null)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "产品对象为空";
                    return(result);
                }
                var productInfo = context.ProductInfo.Where(p => p.ProductNo == pmodel.ProductNo).FirstOrDefault();
                var pinfo       = context.Set <ShopProductInfo>().FromSql($@"select * from shop_product_info where product_no ={pmodel.ProductNo}").FirstOrDefault();
                if (pinfo != null)
                {
                    pmodel.ProductImage = pinfo.ProductImg;
                    pmodel.Description  = pinfo.Description;
                    pmodel.ThumbnailImg = pinfo.ThumbnailImg;
                }
                if (productInfo != null)
                {
                    if (!string.IsNullOrEmpty(productInfo.ProductName))
                    {
                        pmodel.ProductName = productInfo.ProductName;
                    }
                    if (!string.IsNullOrEmpty(productInfo.ProductDesc))
                    {
                        pmodel.ShortDesc = productInfo.ProductDesc;
                    }
                    if (!string.IsNullOrEmpty(productInfo.ImageUrl))
                    {
                        pmodel.ThumbnailImg = productInfo.ImageUrl;
                    }
                }

                result.Data = pmodel;
            }

            return(result);
        }
Ejemplo n.º 25
0
 public RepositoryBase(CoreContext context)
 {
     Context = context;
     DbSet   = Context.Set <TEntity>();
 }
Ejemplo n.º 26
0
 public BaseRepository(CoreContext context)
 {
     Context    = context;
     this.DbSet = Context.Set <T>();
 }
Ejemplo n.º 27
0
 public Driver()
 {
     this.dbContext = new CoreContext();
     this.dbSet     = dbContext.Set <TEntity>();
 }
Ejemplo n.º 28
0
        public virtual async Task <T> FindAsync(object[] keys, CancellationToken cancellationToken)
        {
            var entity = await _contexto.Set <T>().FindAsync(keys, cancellationToken);

            return(entity);
        }
Ejemplo n.º 29
0
 public virtual bool Delete(IEnumerable <TEntity> batch)
 {
     CoreContext.Set <TEntity>().RemoveRange(batch);
     return(CoreContext.SaveChanges() > 0);
 }
Ejemplo n.º 30
0
        public async Task CreateAsync(T entity)
        {
            await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();
        }