Exemplo n.º 1
0
        private static void BeforeSaveChangesWithHistory(IEntityFrameworkDbContext dbContext)
        {
            DateTime dateTime = DateTime.UtcNow;

            IModificationHistory entity;
            EntityState          entityState;

            foreach (var history in dbContext.ChangeTracker.Entries()
                     .Where(e => e.Entity is IModificationHistory && (e.State == EntityState.Added || e.State == EntityState.Modified))
                     .Select(e => new { Entity = e.Entity as IModificationHistory, e.State }))
            {
                entity      = history.Entity;
                entityState = history.State;

                if (entityState == EntityState.Modified)
                {
                    dbContext.Entry(entity).Property(e => e.DateCreated).IsModified = false;
                }

                if (entityState == EntityState.Added)
                {
                    entity.DateCreated = dateTime;
                }

                entity.DateModified = dateTime;
            }
        }
Exemplo n.º 2
0
 public SqlRepositoryEntityFrameworkDisconnected(IEntityFrameworkDbContext ctx,
                                                 ILogger logger,
                                                 IMapper mapper,
                                                 IDataAccessStrategy <T> dataAccessStrategy) : base(ctx, logger, mapper)
 {
     this.dataAccessStrategy = dataAccessStrategy;
 }
Exemplo n.º 3
0
 private static void AfterSaveChangesWithHistory(IEntityFrameworkDbContext dbContext)
 {
     foreach (var history in dbContext.ChangeTracker.Entries()
              .Where(e => e.Entity is IModificationHistory)
              .Select(e => e.Entity as IModificationHistory))
     {
         history.IsDirty = false;
     }
 }
Exemplo n.º 4
0
        protected UnitOfWork(IRepositoryProvider repositoryProvider, IEntityFrameworkDbContext dbContext)
        {
            //CreateDbContext();

            RepositoryProvider           = repositoryProvider;
            repositoryProvider.DbContext = dbContext;
            this.dbContext = dbContext;

            PrepareDbContext();
        }
Exemplo n.º 5
0
        public static async Task <int> SaveChangesWithModificationHistoryAsync(this IEntityFrameworkDbContext dbContext)
        {
            BeforeSaveChangesWithHistory(dbContext);

            int result = await dbContext.SaveChangesAsync();

            AfterSaveChangesWithHistory(dbContext);

            return(result);
        }
Exemplo n.º 6
0
        public static int SaveChangesWithModificationHistory(this IEntityFrameworkDbContext dbContext)
        {
            BeforeSaveChangesWithHistory(dbContext);

            int result = dbContext.SaveChanges();

            AfterSaveChangesWithHistory(dbContext);

            return(result);
        }
Exemplo n.º 7
0
 public DictionaryRepository(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper)
 {
 }
Exemplo n.º 8
0
 public SqlRepositoryEntityFrameworkAsync(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper)
 {
 }
Exemplo n.º 9
0
        protected UnitOfWork2(IEntityFrameworkDbContext context)
        {
            this.context = context;

            PrepareDbContext();
        }
 public PreSaleOrderDataAccess(IEntityFrameworkDbContext context, bool isNoTracking = true) : base(context, isNoTracking)
 {
 }
Exemplo n.º 11
0
 public static DataTable DataTable(this IEntityFrameworkDbContext context, string query)
 {
     return(SqlUtils.GetDataTable(query, context.Database.Connection));
 }
Exemplo n.º 12
0
 public SqlRepositoryEntityFrameworkDisconnected(IEntityFrameworkDbContext ctx,
                                                 ILogger logger,
                                                 IMapper mapper) : base(ctx, logger, mapper)
 {
     dataAccessStrategy = ServiceLocator.Current.GetInstance <IDataAccessStrategy <T> >();
 }
Exemplo n.º 13
0
 /// <summary>
 /// /Initializes a new instance of the <see cref="AuthorizationDataProvider"/> class.
 /// </summary>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="connectionString">
 /// The Database context.
 /// </param>
 public UserDataProvider(ILogger logger, IEntityFrameworkDbContext entityFrameworkDbContext, IHelpers helpers)
 {
     this._logger = logger;
     this._entityFrameworkDbContext = entityFrameworkDbContext;
     this._helpers = helpers;
 }
Exemplo n.º 14
0
        /// <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 <IEntityFrameworkDbContext, ILogger, IMapper, object> factory, IEntityFrameworkDbContext dbContext, ILogger logger, IMapper mapper)
        {
            var f = factory ?? _repositoryFactories.GetRepositoryFactory <T>() ?? _repositoryFactories.GetDefaultRepositoryFactory <T>();

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

            var repo = (T)f(dbContext, logger, mapper);

            Repositories[typeof(T)] = repo;

            return(repo);
        }
Exemplo n.º 15
0
 public TicketRepository(IEntityFrameworkDbContext ctx,
                         ILogger logger,
                         IMapper mapper,
                         IDataAccessStrategy <Ticket> strategy) : base(ctx, logger, mapper, strategy)
 {
 }
Exemplo n.º 16
0
 public LogRepo(IEntityFrameworkDbContext ctx) : base(ctx, null, null)
 {
 }
Exemplo n.º 17
0
 public static bool ExistsLocal <T>(this IEntityFrameworkDbContext dbContext, T entity) where T : class
 {
     return(dbContext.Set <T>().Local.Contains(entity));
 }
Exemplo n.º 18
0
 private static DbContext GetDbContext(this IEntityFrameworkDbContext context) => (context as DbContext);
Exemplo n.º 19
0
 public EmployeeRepository(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper)
 {
 }
 public SqlRepositoryEntityFramework(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger)
 {
     this.ctx    = ctx;
     this.mapper = mapper;
     set         = this.ctx.Set <T>();
 }
Exemplo n.º 21
0
 public ContrahentRepository(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper)
 {
 }
Exemplo n.º 22
0
 public static T FirstOrDefautLocal <T>(this IEntityFrameworkDbContext dbContext, Func <T, bool> predicate) where T : class
 {
     return(dbContext.Set <T>().Local.FirstOrDefault(predicate));
 }
Exemplo n.º 23
0
 public TaskManagerUow(IRepositoryProvider repositoryProvider, IEntityFrameworkDbContext dbContext) : base(repositoryProvider, dbContext)
 {
 }
Exemplo n.º 24
0
 public AddressDataAccess(IEntityFrameworkDbContext context, bool isNoTracking = true) : base(context, isNoTracking)
 {
 }
Exemplo n.º 25
0
 public EntityFrameworkRepository(IEntityFrameworkDbContext dbcontext, IUnitOfWork unitOfWork)
     : base(unitOfWork)
 {
     dbContext = dbcontext;
 }
Exemplo n.º 26
0
 public static string GetQuery <T>(this IEntityFrameworkDbContext context) where T : class
 {
     return(context.GetDbContext().GetQuery <T>());
 }
Exemplo n.º 27
0
 public GenericRepository(IEntityFrameworkDbContext context, bool isNoTracking = true)
 {
     this.context      = context;
     this.isNoTracking = isNoTracking;
 }
Exemplo n.º 28
0
 public static bool ExistsLocal <T>(this IEntityFrameworkDbContext dbContext, Func <T, bool> predicate) where T : class
 {
     return(dbContext.Set <T>().Local.Any(predicate));
 }