Example #1
0
 protected override void BeforeInsert(RfidCard item, Microsoft.EntityFrameworkCore.DbContext dbContext)
 {
     if (string.IsNullOrEmpty(item.TowerNo))
     {
         item.TowerNo = "";
     }
 }
        public static void Reset(this Microsoft.EntityFrameworkCore.DbContext context)
        {
            var entries = context.ChangeTracker
                          .Entries()
                          .Where(e => e.State != Microsoft.EntityFrameworkCore.EntityState.Unchanged)
                          .ToArray();

            foreach (var entry in entries)
            {
                switch (entry.State)
                {
                case Microsoft.EntityFrameworkCore.EntityState.Modified:
                    entry.State = Microsoft.EntityFrameworkCore.EntityState.Unchanged;
                    break;

                case Microsoft.EntityFrameworkCore.EntityState.Added:
                    entry.State = Microsoft.EntityFrameworkCore.EntityState.Detached;
                    break;

                case Microsoft.EntityFrameworkCore.EntityState.Deleted:
                    entry.Reload();
                    break;
                }
            }
        }
Example #3
0
 protected override void BeforeUpdate(Bom item, Microsoft.EntityFrameworkCore.DbContext dbContext)
 {
     if (string.IsNullOrEmpty(item.BomNo))
     {
         item.BomNo = "";
     }
 }
Example #4
0
 public BaseService(IBaseRepository <T> repository, IDbSession dbSession)
 {
     this.Repository  = repository;
     this.DbSession   = dbSession;
     this.UserContext = dbSession.GetRequiredService <IUserContext>();
     this.Mapper      = dbSession.GetRequiredService <IMapper>();
     this.Db          = dbSession.GetRequiredService <Microsoft.EntityFrameworkCore.DbContext>();
 }
Example #5
0
 public object Create(Microsoft.EntityFrameworkCore.DbContext context, bool designTime)
 {
     if (designTime)
     {
         return(this);
     }
     return(new ExtendedModelCacheKey <TTenantId, TUserId>(context));
 }
Example #6
0
 private static void SaveChangeToDatabase(Microsoft.EntityFrameworkCore.DbContext context)
 {
     try
     {
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.GetBaseException());
     }
 }
        public static bool AllMigrationsApplied(this Microsoft.EntityFrameworkCore.DbContext context)
        {
            var applied = context.GetService <IHistoryRepository>()
                          .GetAppliedMigrations()
                          .Select(m => m.MigrationId);

            var total = context.GetService <IMigrationsAssembly>()
                        .Migrations
                        .Select(m => m.Key);

            return(!total.Except(applied).Any());
        }
        internal virtual void ApplyDbContext(Microsoft.EntityFrameworkCore.DbContext dbContext)
        {
            var entityTypes = dbContext.Model.GetEntityTypes();

            foreach (var entityType in entityTypes)
            {
                _metadata.AddEntityType(entityType);
            }

            foreach (var entityType in entityTypes)
            {
                (_metadata.FindEntityType(entityType.Name) as EntityType).AddForeignKeys(entityType.GetForeignKeys());
            }
        }
        internal static List <PropertyInfo> GetDbSetProperties(this Microsoft.EntityFrameworkCore.DbContext context)
        {
            var dbSetProperties = new List <PropertyInfo>();
            var properties      = context.GetType().GetProperties();

            foreach (var property in properties)
            {
                var setType = property.PropertyType;
                var isDbSet = setType.IsGenericType && (typeof(Microsoft.EntityFrameworkCore.DbSet <>).IsAssignableFrom(setType.GetGenericTypeDefinition()));
                if (isDbSet)
                {
                    dbSetProperties.Add(property);
                }
            }
            return(dbSetProperties);
        }
Example #10
0
        protected override void AfterInsert(RfidCard item, Microsoft.EntityFrameworkCore.DbContext dbContext)
        {
            CardIssue issue = new CardIssue();

            issue.CardNo = item.RfidNo;
            issue.CardId = item.RecordId;

            issue.WorkstationId   = -1;
            issue.WorkstationCode = "";
            issue.WorkstationName = "";

            SystemUser currentUser = GlobalConstants.GetCurrentUser();

            issue.IssueUserId   = currentUser.RecordId;
            issue.IssueUserCode = currentUser.UserCode;
            issue.IssueUserName = currentUser.UserName;

            issue.IssueQty = item.IssueQty;

            dbContext.Add(issue);
            dbContext.SaveChanges();
        }
Example #11
0
        private static void GrantDBContext_OnQtEFCommit(RpcContext rpcContext, Microsoft.EntityFrameworkCore.DbContext dbContext, DbInfo dbInfo, Z.EntityFramework.Plus.Audit audit)
        {
            var user = rpcContext.GetUserContext();

            if (haveAudit(user))
            {
                if (audit?.Entries == null)
                {
                    return;
                }

                var auditData = new List <AuditData>();
                try
                {
                    audit.Entries = audit.Entries.Where(x =>
                                                        x.State == AuditEntryState.EntityModified ||
                                                        x.State == AuditEntryState.EntityDeleted).ToList();

                    //修正空审计记录
                    if (audit.Entries.Count() == 0)
                    {
                        return;
                    }
                    auditData = AuditTool.AuditConvertToArgs(dbContext.Database, user, audit, dbInfo);
                    auditData?.ForEach(x =>
                    {
                        if (!string.IsNullOrEmpty(rpcContext.Args.rid))
                        {
                            x.TransactionId = rpcContext.Args.rid;
                        }
                    });
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "GrantDBContext_OnQtEFCommit error.");
                }
                AuditTool.SaveAuditData(dbContext.Database, auditData, dbInfo);
            }
        }
Example #12
0
 public UnitofWork(CoreDbContext context)
 {
     Context = context;
 }
Example #13
0
 public CoreDao(Microsoft.EntityFrameworkCore.DbContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #14
0
 public LogTypeRepository(Microsoft.EntityFrameworkCore.DbContext context) : base(context)
 {
 }
Example #15
0
 public UnitOfWork()
 {
     _db = new TContext();
 }
Example #16
0
 public static void TryUpdateManyToMany <T, TKey>(this Microsoft.EntityFrameworkCore.DbContext db, IEnumerable <T> currentItems, IEnumerable <T> newItems, Func <T, TKey> getKey) where T : class
 {
     db.Set <T>().RemoveRange(currentItems.Except(newItems, getKey));
     db.Set <T>().AddRange(newItems.Except(currentItems, getKey));
 }
 public UserStore(Microsoft.EntityFrameworkCore.DbContext context, Microsoft.AspNetCore.Identity.IdentityErrorDescriber describer = null) : base(default(Microsoft.EntityFrameworkCore.DbContext), default(Microsoft.AspNetCore.Identity.IdentityErrorDescriber))
 {
 }
 public TeamRepository(Microsoft.EntityFrameworkCore.DbContext dbContext)
     : base(dbContext)
 {
 }
Example #19
0
 public UserGroupRepository(Microsoft.EntityFrameworkCore.DbContext context) : base(context)
 {
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public UnitOfWork()
 {
     _context = new winterwooddbContext();
 }
Example #21
0
 public Repository(Microsoft.EntityFrameworkCore.DbContext _context)
 {
     this.Context = _context;
 }
Example #22
0
 protected internal LogRepository
     (Microsoft.EntityFrameworkCore.DbContext databaseContext) : base(databaseContext: databaseContext)
 {
 }
 public SimbaToursEastAfricaUnitOfWork(
     AbstractRepository <Address> addressRepository,
     AbstractRepository <Destination> destinationRepository,
     AbstractRepository <Driver> driverRepository,
     AbstractRepository <HotelBooking> hotelBookingRepository,
     AbstractRepository <InAndOutBoundAirTravel> inAndOutBoundAirTravelRepository,
     AbstractRepository <InternalVehicleTravel> internalVehicleTravelRepository,
     AbstractRepository <Invoice> invoiceRepository,
     AbstractRepository <Item> itemRepository,
     AbstractRepository <Itinary> itinaryRepository,
     AbstractRepository <Laguage> laguageRepository,
     AbstractRepository <Location> locationRepository,
     AbstractRepository <Meal> mealRepository,
     AbstractRepository <Schedule> scheduleRepository,
     AbstractRepository <TourClient> tourClientRepository,
     AbstractRepository <Vehicle> vehicleRepository,
     AbstractRepository <SchedulesPricing> schedulesPricingRepository,
     AbstractRepository <MealPricing> mealPricingRepository,
     AbstractRepository <DealsPricing> dealsPricingRepository,
     AbstractRepository <LaguagePricing> laguagePricingRepository,
     AbstractRepository <HotelPricing> hotelPricingRepostory,
     AbstractRepository <Hotel> hotelRepostory,
     AbstractRepository <TransportPricing> transportPricingRepository,
     Microsoft.EntityFrameworkCore.DbContext simbaToursEastAfricaDbContext)
 {
     SimbaToursEastAfricaDbContext = simbaToursEastAfricaDbContext as SimbaToursEastAfricaDbContext;
     _addressRepository            = addressRepository as AddressRepository;
     _addressRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _destinationRepository = destinationRepository as DestinationRepository;
     _destinationRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _driverRepository = driverRepository as DriverRepository;
     _driverRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _hotelBookingRepository = hotelBookingRepository as HotelBookingRepository;
     _hotelBookingRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _inAndOutBoundAirTravelRepository = inAndOutBoundAirTravelRepository as InAndOutBoundAirTravelRepository;
     _inAndOutBoundAirTravelRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _internalVehicleTravelRepository = internalVehicleTravelRepository as InternalVehicleTravelRepository;
     _internalVehicleTravelRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _invoiceRepository = invoiceRepository as InvoiceRepository;
     _invoiceRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _itemRepository = itemRepository as ItemRepository;
     _itemRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _itinaryRepository = itinaryRepository as ItinaryRepository;
     _itinaryRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _laguageRepository = laguageRepository as LaguageRepository;
     _laguageRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _locationRepository = locationRepository as LocationRepository;
     _locationRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _mealRepository = mealRepository as MealRepository;
     _mealRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _scheduleRepository = scheduleRepository as ScheduleRepository;
     _scheduleRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _tourClientRepository = tourClientRepository as TourClientRepository;
     _tourClientRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _vehicleRepository = vehicleRepository as VehicleRepository;
     _vehicleRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _mealsPricingRepository = mealPricingRepository as MealsPricingRepository;
     _mealsPricingRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _dealsPricingRepository = dealsPricingRepository as DealsPricingRepository;
     _dealsPricingRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _laguagePricingRepository = laguagePricingRepository as LaguagePricingRepository;
     _laguagePricingRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _schedulesPricingRepository = schedulesPricingRepository as SchedulesPricingRepository;
     _schedulesPricingRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _hotelPricingRepository = hotelPricingRepostory as HotelPricingRepository;
     _hotelPricingRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _hotelRepository = hotelRepostory as HotelRepository;
     _hotelRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
     _transportPricingRepository = transportPricingRepository as TransportPricingRepository;
     _transportPricingRepository.SimbaToursEastAfricaDbContext = SimbaToursEastAfricaDbContext;
 }
Example #24
0
 public UserRepository(AuctionDbContext context) : base(context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Example #25
0
 public CommandServiceRepository()
 {
     _context = new AdaptivContext();
 }
Example #26
0
 public object Create(Microsoft.EntityFrameworkCore.DbContext context)
 {
     return(new ExtendedModelCacheKey <TTenantId, TUserId>(context));
 }
 public DeviceRuleRepository(Microsoft.EntityFrameworkCore.DbContext context) : base(context)
 {
 }
        /// <summary>Make a repository of type T.</summary>
        /// <typeparam name="T">Type of repository to make.</typeparam>
        /// <param name="dbContext">
        /// The <see cref="DbContext"/> with which to initialize the repository.
        /// </param>
        /// <param name="factory">
        /// Factory with <see cref="DbContext"/> argument. Used to make the repository.
        /// If null, gets factory from <see cref="_repositoryFactories"/>.
        /// </param>
        /// <returns></returns>
        protected virtual T MakeRepository <T>(Func <Microsoft.EntityFrameworkCore.DbContext, object> factory, Microsoft.EntityFrameworkCore.DbContext dbContext)
        {
            var f = factory ?? _repositoryFactories.GetRepositoryFactory <T>();

            if (f == null)
            {
                throw new NotImplementedException("No factory for repository type, " + typeof(T).FullName);
            }
            var repo = (T)f(dbContext);

            Repositories[typeof(T)] = repo;
            return(repo);
        }
Example #29
0
 public ProductTypeRepository(Microsoft.EntityFrameworkCore.DbContext db) : base(db)
 {
     this.db = db;
 }
Example #30
0
 /// <summary>
 /// Creates a new instance of <see cref="BaseStoredDataRepository"/>
 /// </summary>
 /// <param name="dbContext">Entity Framework DbContext to use with this repository</param>
 public BaseRepository(Microsoft.EntityFrameworkCore.DbContext dbContext) => DbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));