Ejemplo n.º 1
0
 void IEntityInterceptor.OnLoad(IEntityEntry entry, IRepository repository)
 {
     if (entry.Entity is T)
     {
         this.OnLoad(entry.Convert <T>(), repository);
     }
 }
        public void OnDelete(IEntityEntry <Patient> entry, IUnitOfWork unitOfWork)
        {
            User    user    = GetCurrentUser();
            Patient patient = entry.Entity;

            auditLog.Write(AuditType.Deleted, $"Patient was deleted. Patient Name: {patient.Name}", user);
        }
        public void OnLoad(IEntityEntry <Patient> entry, IRepository repository)
        {
            User    user    = GetCurrentUser();
            Patient patient = entry.Entity;

            auditLog.Write(AuditType.Read, $"Patient data was read. Patient Name: {patient.Name}", user);
        }
Ejemplo n.º 4
0
 void IEntityInterceptor.OnDelete(IEntityEntry entry, IUnitOfWork repository)
 {
     if (entry.Entity is T)
     {
         this.OnDelete(entry.Convert <T>(), repository);
     }
 }
Ejemplo n.º 5
0
        private void InterceptLoad(IEnumerable <IEntityInterceptor> interceptors, object entity)
        {
            IEntityEntry entry = this.contextUtilities.GetEntry(entity, this.Context);

            foreach (var interceptor in interceptors)
            {
                interceptor.OnLoad(entry, this.repository);
            }
        }
Ejemplo n.º 6
0
        private void Intercept <T>(IEnumerable <T> interceptors, object entity, Action <T, IEntityEntry> intercept)
        {
            IEntityEntry entry = contextUtilities.GetEntry(entity, contextBuilder.Context);

            foreach (var interceptor in interceptors)
            {
                intercept(interceptor, entry);
            }
        }
        public void OnSave(IEntityEntry <Patient> entry, IUnitOfWork unitOfWork)
        {
            User    user    = GetCurrentUser();
            Patient patient = entry.Entity;

            if (entry.State == EntityEntryState.Added)
            {
                auditLog.Write(AuditType.Added, $"Patient was added. Patient Name: {patient.Name}", user);
            }
            else
            {
                auditLog.Write(AuditType.Added, $"Patient was modified. Patient Name: {patient.Name}", user);
            }
        }
        public override void OnSave(IEntityEntry <IAuditable> entry, IUnitOfWork repository)
        {
            var systemDate = DateTime.Now;

            var    claimsIdentity = ClaimsPrincipal.Current.Identities.OfType <ClaimsIdentity>().FirstOrDefault();
            string userName       = claimsIdentity != null ? claimsIdentity.Name : ClaimsPrincipal.Current.Identities.First().Name;

            if (entry.State == EntityEntryState.Added)
            {
                entry.Entity.CreationDate = systemDate;
                entry.Entity.CreatedBy    = userName;
            }

            entry.Entity.LastEditDate = systemDate;
            entry.Entity.LastEditBy   = userName;
        }
Ejemplo n.º 9
0
        public void Intercept(IEntityEntry entityEntry, bool isPostSave)
        {
            if (entityEntry == null)
            {
                throw new ArgumentNullException("entityEntry");
            }

            if (!(entityEntry.Entity is TEntity))
            {
                return;
            }

            foreach (var method in _methods.Where(m => m.CanIntercept(entityEntry.State, isPostSave)))
            {
                method.Invoke(this, entityEntry);
            }
        }
        public void OnSave(IEntityEntry <SalesOrderHeader> entry, IUnitOfWork unitOfWork)
        {
            if (IsAddedOrModified(entry))
            {
                var order = entry.Entity;

                if (string.IsNullOrEmpty(order.AccountNumber))
                {
                    throw new InvalidOrderException();
                }

                decimal taxes = order.TaxAmt;
                decimal total = order.SalesOrderDetails.Sum(ol => ol.LineTotal);

                if (taxes > total)
                {
                    throw new InvalidOrderException();
                }
            }
        }
Ejemplo n.º 11
0
        public static void SaveIndex(ArrayList list, string path)
        {
            if (!Directory.Exists("Saves/Mobiles/"))
            {
                Directory.CreateDirectory("Saves/Mobiles/");
            }

            if (!Directory.Exists("Saves/Items/"))
            {
                Directory.CreateDirectory("Saves/Items/");
            }

            if (!Directory.Exists("Saves/Guilds/"))
            {
                Directory.CreateDirectory("Saves/Guilds/");
            }

            if (!Directory.Exists("Saves/Regions/"))
            {
                Directory.CreateDirectory("Saves/Regions/");
            }

            using (FileStream idx = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                BinaryWriter idxWriter = new BinaryWriter(idx);

                idxWriter.Write(list.Count);

                for (int i = 0; i < list.Count; ++i)
                {
                    IEntityEntry e = (IEntityEntry)list[i];

                    idxWriter.Write(e.TypeID);
                    idxWriter.Write(e.Serial);
                    idxWriter.Write(e.Position);
                    idxWriter.Write(e.Length);
                }

                idxWriter.Close();
            }
        }
Ejemplo n.º 12
0
 public Context(IEntityEntry entry)
 {
     Entry = entry;
 }
Ejemplo n.º 13
0
 public abstract void OnDelete(IEntityEntry <T> entry, IUnitOfWork repository);
Ejemplo n.º 14
0
 public abstract void OnLoad(IEntityEntry <T> entry, IRepository repository);
 public virtual void OnDelete(IEntityEntry <T> entry, IUnitOfWork unitOfWork)
 {
 }
 public void OnLoad(IEntityEntry entry, IRepository repository)
 {
     OnLoad(entry.Convert <T>(), repository);
 }
Ejemplo n.º 17
0
 public void OnSave(IEntityEntry entry, IUnitOfWork unitOfWork)
 {
 }
 public override void OnDelete(IEntityEntry <IAuditable> entry, IUnitOfWork repository)
 {
     throw new NotImplementedException();
 }
 public void OnSave(IEntityEntry entry, IUnitOfWork unitOfWork)
 {
     OnSave(entry.Convert <T>(), unitOfWork);
 }
 public DataValidationResult(IEntityEntry entry, IEnumerable<ValidationError> errors)
 {
     Entry = entry;
     this.errors = errors.ToList();
 }
 public virtual void OnLoad(IEntityEntry <T> entry, IRepository repository)
 {
 }
Ejemplo n.º 22
0
 public void Invoke(Interceptor <TEntity> target, IEntityEntry entityEntry)
 {
     _method.Invoke(target, new[] { Activator.CreateInstance(_contextType, entityEntry) });
 }
 public override void OnLoad(IEntityEntry <IAuditable> entry, IRepository repository)
 {
     throw new NotImplementedException();
 }