Exemple #1
0
 /// <summary>
 /// Gets a list of all GroupPrivileges.
 /// </summary>
 /// <returns>Returns all the GroupPrivileges in the database.</returns>
 public IEnumerable <GroupPrivilege> GetGroupPrivileges()
 {
     try
     {
         return(repo.All <GroupPrivilege>().AsEnumerable());
     }
     catch (Exception ex)
     {
         repo.LogError(ex);
         throw ex;
     }
 }
		/// <summary>
        /// Gets a list of all OrganizationPrivileges.
        /// </summary>
        /// <returns>Returns all the OrganizationPrivileges in the database.</returns>
        public IEnumerable<OrganizationPrivilege> GetOrganizationPrivileges()
        {
            try
            {
                return repo.All<OrganizationPrivilege>().AsEnumerable();
            }
            catch (Exception ex)
            {
                repo.LogError(ex);
                throw ex;
            }
        }
Exemple #3
0
 /// <summary>
 /// Gets a list of all Users.
 /// </summary>
 /// <returns>Returns all the Users in the database.</returns>
 public IEnumerable <User> GetUsers()
 {
     try
     {
         return(repo.All <User>().AsEnumerable());
     }
     catch (Exception ex)
     {
         repo.LogError(ex);
         throw ex;
     }
 }
 /// <summary>
 /// Gets a list of all LogEvents.
 /// </summary>
 /// <returns>Returns all the LogEvents in the database.</returns>
 public IEnumerable <LogEvent> GetLogEvents()
 {
     try
     {
         return(repo.All <LogEvent>().AsEnumerable());
     }
     catch (Exception ex)
     {
         repo.LogError(ex);
         throw ex;
     }
 }
Exemple #5
0
 /// <summary>
 /// Gets a list of all Organizations.
 /// </summary>
 /// <returns>Returns all the Organizations in the database.</returns>
 public IEnumerable <Organization> GetOrganizations()
 {
     try
     {
         return(repo.All <Organization>().AsEnumerable());
     }
     catch (Exception ex)
     {
         repo.LogError(ex);
         throw ex;
     }
 }
Exemple #6
0
        public T Update <T>(T t) where T : class
        {
            try
            {
                // Log the Create event type
                LogEvent log = new LogEvent();
                //log.LogEventType = LogEventType.Update;
                log.LogEventType = "Update";

                // Log the user name, Id, and current date
                log.ChangedByUserId   = this.GetCurrentUserId();
                log.ChangedByUserName = this.GetCurrentUserName();
                log.Date = DateTime.Now;


                // Detach the etities so we can access both old and new values
                var entities = repo.All <T>().AsNoTracking();

                // Log the entity's type
                Type entityType = typeof(T);
                log.EntityType = entityType.Name;

                // Log the primary key/Id for the entity based on the config data
                // Note: This assumes the class names for the db model match the table names
                var configProp     = loggingConfig_PrimaryKeys.GetType().GetProperty(entityType.Name);
                var primaryKeyName = configProp.GetValue(loggingConfig_PrimaryKeys, null).ToString();
                var entityProp     = t.GetType().GetProperty(primaryKeyName);
                log.EntityId = entityProp.GetValue(t, null).ToString();

                // Get the current entity from the database with the "old" values
                var param = Expression.Parameter(typeof(T), "p");
                var exp   = Expression.Lambda <Func <T, bool> >(
                    Expression.Equal(
                        Expression.Property(param, primaryKeyName),
                        Expression.Constant(entityProp.GetValue(t, null))
                        ),
                    param
                    );
                var entity = (T)entities.Where(exp).ToList().ElementAt(0);

                // Compare old and new properties and log those that have changed
                foreach (var propInfo in t.GetType().GetProperties())
                {
                    var newValue       = propInfo.GetValue(t, null);
                    var oldValue       = propInfo.GetValue(entity, null);
                    var newValueString = "";
                    var oldValueString = "";
                    if (newValue != null)
                    {
                        newValueString = newValue.ToString();
                    }
                    if (oldValue != null)
                    {
                        oldValueString = oldValue.ToString();
                    }
                    if (newValue != null && oldValue != null && !newValueString.Equals(oldValueString) && !propInfo.PropertyType.Name.Contains("ICollection"))
                    {
                        log.PropertyName = propInfo.Name;
                        log.PropertyType = propInfo.PropertyType.Name;
                        log.OldValue     = oldValueString;
                        log.NewValue     = newValueString;
                        repo.Create <LogEvent>(log);
                    }
                }

                return(repo.Update <T>(t));
            }
            catch (Exception ex)
            {
                LogError(ex);
                throw ex;
            }
        }