public async Task <long> UpdateHistoryChangeAsync(HistoryChangeDto historyChangeDto) { var historyChange = new HistoryChange(); Mapper.Map(historyChangeDto, historyChange); var rowsUpdated = await historyChangeRepository.UpdateHistoryChangeAsync(historyChange, historyChangeDto.MappingScheme); return(rowsUpdated); }
public async Task <long> UpdateHistoryChangeAsync(HistoryChange historyChange, string mappingScheme) { historyChangeMappingSchemeRegistrator.Register(); var updatedHistoryChange = unitOfWork.Add(historyChange, mappingScheme); await unitOfWork.SaveAsync(); return(updatedHistoryChange.Id); }
public async Task <IActionResult> AddHistory(int countI, string userId, string documentId, string datetime, string documentStatus) { int count = _context.HistoryChanges.Count() + 1 + countI; HistoryChange hs = new HistoryChange() { Id = "HS_" + count, UserId = userId, SecurityDocumentId = documentId, Date = DateTime.Parse(datetime), DocumentStatus = (DocumentStatus)Enum.Parse(typeof(DocumentStatus), documentStatus) }; _context.HistoryChanges.Add(hs); await _context.SaveChangesAsync(); return(Ok()); }
public void AppendDiff(string propertyName, Func <Issue, object> getValueExpression) { var value1 = getValueExpression(_issue1).ToString(); var value2 = getValueExpression(_issue2).ToString(); if (value1 == value2) { return; } var change = new HistoryChange { FieldName = propertyName, ValueBefore = value1, ValueAfter = value2, }; _changes.Add(change); }
/// <summary> /// Determines whether [has event happened] [the specified entity]. /// </summary> /// <param name="followingEvent">The following event.</param> /// <param name="entity">The entity.</param> /// <param name="lastNotified">The last notified.</param> /// <returns></returns> public override bool HasEventHappened(FollowingEventType followingEvent, IEntity entity, DateTime?lastNotified) { if (followingEvent != null && entity != null) { var personAlias = entity as PersonAlias; if (personAlias != null && personAlias.Person != null) { // // Get all the attributes/settings we need. // int daysBack = GetAttributeValue(followingEvent, "MaxDaysBack").AsInteger(); string targetOldValue = GetAttributeValue(followingEvent, "OldValue") ?? string.Empty; string targetNewValue = GetAttributeValue(followingEvent, "NewValue") ?? string.Empty; string targetPersonGuid = GetAttributeValue(followingEvent, "Person"); bool negateChangedBy = GetAttributeValue(followingEvent, "NegatePerson").AsBoolean(); bool matchBothValues = GetAttributeValue(followingEvent, "MatchBoth").AsBoolean(); var attributes = GetAttributeValue(followingEvent, "Fields").Split(',').Select(a => a.Trim()); // // Populate all the other random variables we need for processing. // PersonAlias targetPersonAlias = new PersonAliasService(new RockContext()).Get(targetPersonGuid.AsGuid()); DateTime daysBackDate = RockDateTime.Now.AddDays(-daysBack); var person = personAlias.Person; int personEntityTypeId = EntityTypeCache.Read(typeof(Person)).Id; int categoryId = CategoryCache.Read(Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid()).Id; // // Start building the basic query. We want all History items that are for // people objects and use the Demographic Changes category. // var qry = new HistoryService(new RockContext()).Queryable() .Where(h => h.EntityTypeId == personEntityTypeId && h.EntityId == person.Id && h.CategoryId == categoryId); // // Put in our limiting dates. We always limit by our days back date, // and conditionally limit based on the last time we notified the // stalker - I mean the follower. // if (lastNotified.HasValue) { qry = qry.Where(h => h.CreatedDateTime >= lastNotified.Value); } qry = qry.Where(h => h.CreatedDateTime >= daysBackDate); // // Walk each history item found that matches our filter. // Dictionary <string, List <HistoryChange> > changes = new Dictionary <string, List <HistoryChange> >(); foreach (var history in qry.ToList()) { Match modified = Regex.Match(history.Summary, ModifiedRegex); Match added = Regex.Match(history.Summary, AddedRegex); Match deleted = Regex.Match(history.Summary, DeletedRegex); // // Walk each attribute entered by the user to match against. // foreach (var attribute in attributes) { HistoryChange change = new HistoryChange(); string title = null; // // Check what kind of change this was. // if (modified.Success) { title = modified.Groups[1].Value; change.Old = modified.Groups[2].Value; change.New = modified.Groups[3].Value; } else if (added.Success) { title = added.Groups[1].Value; change.Old = string.Empty; change.New = added.Groups[2].Value; } else if (deleted.Success) { title = deleted.Groups[1].Value; change.Old = deleted.Groups[2].Value; change.New = string.Empty; } // // Check if this is one of the attributes we are following. // if (title != null && title.Trim() == attribute) { // // Get the ValuePair object to work with. // if (!changes.ContainsKey(attribute)) { changes.Add(attribute, new List <HistoryChange>()); } change.PersonId = history.CreatedByPersonId; changes[attribute].Add(change); // // If the value has been changed back to what it was then ignore the change. // if (changes[attribute].Count >= 2) { var changesList = changes[attribute].ToList(); if (changesList[changesList.Count - 2].Old == changesList[changesList.Count - 1].New) { changes.Remove(title); } } } } } // // Walk the list of final changes and see if we need to notify. // foreach (var items in changes.Values) { foreach (HistoryChange change in items) { // // Check for a match on the person who made the change. // if (targetPersonAlias == null || targetPersonAlias.Id == 0 || (!negateChangedBy && targetPersonAlias.PersonId == change.PersonId) || (negateChangedBy && targetPersonAlias.PersonId != change.PersonId)) { bool oldMatch = (string.IsNullOrEmpty(targetOldValue) || targetOldValue == change.Old); bool newMatch = (string.IsNullOrEmpty(targetNewValue) || targetNewValue == change.New); // // If the old value and the new value match then trigger the event. // if ((matchBothValues && oldMatch && newMatch) || (!matchBothValues && (oldMatch || newMatch))) { return(true); } } } } } } return(false); }
protected bool Equals(HistoryChange other) { return(HistoryEntry.Equals(other.HistoryEntry)); }
public void AddHistoryChange(HistoryChange historyChange) { _db.HistoryChanges.Add(historyChange); _db.SaveChanges(); }