/// <summary> /// Updates a/an OrganizationPrivilege. /// </summary> /// <param name="entity"></param> /// <returns>Returns the OrganizationPrivilege that was updated in the database.</returns> public OrganizationPrivilege UpdateOrganizationPrivilege(OrganizationPrivilege entity) { try { return repo.Update<OrganizationPrivilege>(entity); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
/// <summary> /// Updates a/an GroupPrivilege. /// </summary> /// <param name="entity"></param> /// <returns>Returns the GroupPrivilege that was updated in the database.</returns> public GroupPrivilege UpdateGroupPrivilege(GroupPrivilege entity) { try { return(repo.Update <GroupPrivilege>(entity)); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
/// <summary> /// Updates a/an UserPrivilege. /// </summary> /// <param name="entity"></param> /// <returns>Returns the UserPrivilege that was updated in the database.</returns> public UserPrivilege UpdateUserPrivilege(UserPrivilege entity) { try { return(repo.Update <UserPrivilege>(entity)); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
/// <summary> /// Updates a/an User. /// </summary> /// <param name="entity"></param> /// <returns>Returns the User that was updated in the database.</returns> public User UpdateUser(User entity) { try { return(repo.Update <User>(entity)); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
/// <summary> /// Updates a/an LogEvent. /// </summary> /// <param name="entity"></param> /// <returns>Returns the LogEvent that was updated in the database.</returns> public LogEvent UpdateLogEvent(LogEvent entity) { try { return(repo.Update <LogEvent>(entity)); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
/// <summary> /// Updates a/an Group. /// </summary> /// <param name="entity"></param> /// <returns>Returns the Group that was updated in the database.</returns> public Group UpdateGroup(Group entity) { try { return(repo.Update <Group>(entity)); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
/// <summary> /// Updates a/an Organization. /// </summary> /// <param name="entity"></param> /// <returns>Returns the Organization that was updated in the database.</returns> public Organization UpdateOrganization(Organization entity) { try { return(repo.Update <Organization>(entity)); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
/// <summary> /// Updates a/an Application. /// </summary> /// <param name="entity"></param> /// <returns>Returns the Application that was updated in the database.</returns> public Application UpdateApplication(Application entity) { try { return(repo.Update <Application>(entity)); } catch (Exception ex) { repo.LogError(ex); throw ex; } }
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; } }