public Task <List <Product> > GetAllProducts()
 {
     return(_dbContext.Set <Product>()
            .Include(x => x.Category)
            .Include(x => x.SubCategory)
            .ToListAsync());
 }
Example #2
0
        public Task <IEnumerable <CarModel> > GetAsync(params Guid[] identifiers)
        {
            var set = _dbContext.Set <Car>();

            if (identifiers.Any())
            {
                var entities = set.Where(item => identifiers.Any(identifier => item.Identifier.Equals(identifier))).ToList();
                var models   = _converter.Convert(entities);
                return(Task.FromResult(models));
            }

            return(Task.FromResult(_converter.Convert(set.ToList())));
        }
        public async Task <BaseEntity> GetEntity(Guid contactPersonId)
        {
            var result = await _dbContext.Set <ContactPerson>()
                         .Include(f => f.BaseEntity)
                         .FirstOrDefaultAsync(r => r.Id == contactPersonId);

            return(result.BaseEntity);
        }
        public static void SetDeleteStatus <T>(
            Guid objectID,
            DeleteStatus deleteStatus,
            List <object> relevanceOperations)
        {
            var _DbContext = new EntityDbContext();

            var dbSet         = _DbContext.Set(typeof(T));
            var returnStatus  = true;
            var returnMessage = "";
            var bo            = dbSet.Find(objectID);

            if (bo == null)
            {
                returnStatus  = false;
                returnMessage = "<li>你所删除的数据不存在,如果确定不是数据逻辑错误原因,请将本情况报告系统管理人员。</li>";
                deleteStatus.Initialize(returnStatus, returnMessage);
            }
            else
            {
                #region 处理关联关系
                foreach (var deleteOperationObject in relevanceOperations)
                {
                    var deleteProperty = deleteOperationObject.GetType().GetProperties().Where(pn => pn.Name == "CanDelete").FirstOrDefault();
                    var itCanDelete    = (bool)deleteProperty.GetValue(deleteOperationObject);

                    var messageProperty = deleteOperationObject.GetType().GetProperties().Where(pn => pn.Name == "OperationMessage").FirstOrDefault();
                    var messageValue    = messageProperty.GetValue(deleteOperationObject) as string;

                    if (!itCanDelete)
                    {
                        returnStatus   = false;
                        returnMessage += "<li>" + messageValue + "</li>";
                    }
                }
                #endregion

                if (returnStatus)
                {
                    try
                    {
                        dbSet.Remove(bo);
                        _DbContext.SaveChanges();
                        deleteStatus.Initialize(returnStatus, returnMessage);
                    }
                    catch (System.Data.Entity.Core.EntityException)
                    {
                        returnStatus  = false;
                        returnMessage = "<li>无法删除所选数据,其信息正被使用,如果确定不是数据逻辑错误原因,请将本情况报告系统管理人员。</li>";
                        deleteStatus.Initialize(returnStatus, returnMessage);
                    }
                }
                else
                {
                    deleteStatus.Initialize(returnStatus, returnMessage);
                }
            }
        }
Example #5
0
        public async Task <List <Region> > GetRegions(Guid countryId)
        {
            var result = await _dbContext.Set <Country>()
                         .Include(f => f.Regions)
                         .FirstOrDefaultAsync(r => r.Id == countryId);

            var regions = result.Regions.ToList();

            return(regions);
        }
Example #6
0
        public async Task <List <Address> > GetAddresses(Guid regionId)
        {
            var result = await _dbContext.Set <Region>()
                         .Include(f => f.Addresses)
                         .FirstOrDefaultAsync(r => r.Id == regionId);

            var addresses = result.Addresses.ToList();

            return(addresses);
        }
Example #7
0
        public async Task <Cashier> GetAsync(int id, CancellationToken cancellationToken)
        {
            var cashier = await dbContext.Set <Cashier>().FirstOrDefaultAsync(ent => ent.Id == id, cancellationToken);

            if (cashier == null)
            {
                throw new NotFoundException <Cashier>();
            }
            return(cashier);
        }
 public EntityDbContextDatabaseInitializer()
 {
     var dbContext = new EntityDbContext
     {
         Initializer = new DropCreateDatabaseIfModelChanges<EntityDbContext>()
     };
     dbContext.Initializer.InitializeDatabase(dbContext);
     var users = dbContext.Set<User>().ToArray();
     Assert.NotNull(users);
     users.Count().ShouldBeInRange(0, int.MaxValue);
     dbContext.Dispose();
 }
Example #9
0
 public virtual bool Add(T data)
 {
     try
     {
         db.Set <T>().Add(data);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         //log error
         return(false);
     }
 }
Example #10
0
 public virtual IQueryable <T> GetAll()
 {
     return(_EntitiesContext.Set <T>());
 }
Example #11
0
 public async Task <Merchant> GetByIdentityIdId(Guid id)
 {
     return(await _dbContext.Set <Merchant>()
            .FirstOrDefaultAsync(c => c.Id == id));
 }
Example #12
0
 public Task <List <Category> > GetAll()
 {
     return(_dbContext.Set <Category>()
            .ToListAsync());
 }
        public async Task Create(TEntity entity)
        {
            await _dbContext.Set <TEntity>().AddAsync(entity);

            await _dbContext.SaveChangesAsync();
        }
Example #14
0
 public T Insert(T entity)
 {
     _entityDbContext.Set <T>().Add(entity);
     _entityDbContext.SaveChanges();
     return(entity);
 }