public void Update(string workItemId, IMigrationAction action) { FileAttachmentMetadata attchMetadata = FileAttachmentMetadata.Create(action.MigrationActionDescription); if (null != attchMetadata) { var queryByItem = QueryByItem(workItemId); if (action.Action == WellKnownChangeActionId.AddAttachment) { if (queryByItem.Count() > 0) { queryByItem.First().RelationshipExistsOnServer = true; if (queryByItem.First().OtherProperty.HasValue) { queryByItem.First().OtherProperty = queryByItem.First().OtherProperty.Value + 1; } else { queryByItem.First().OtherProperty = 1; } } else { var newAttchRecord = CreateNewAttachmentStoreRecord( workItemId, FileAttachmentMetadata.CreateAttachmentStorageId(action.MigrationActionDescription), 1); } } else if (action.Action == WellKnownChangeActionId.DelAttachment) { if (queryByItem.Count() > 0) { if (queryByItem.First().RelationshipExistsOnServer) { if (queryByItem.First().OtherProperty.HasValue&& queryByItem.First().OtherProperty.Value > 0) { queryByItem.First().OtherProperty = queryByItem.First().OtherProperty.Value - 1; if (queryByItem.First().OtherProperty == 0) { queryByItem.First().RelationshipExistsOnServer = false; } } else { queryByItem.First().OtherProperty = 0; queryByItem.First().RelationshipExistsOnServer = false; } } } } m_context.TrySaveChanges(); } }
public int GetWorkItemAttachmentSpecificCount(string workItemId, XmlDocument updateDocument) { var queryByItem = QueryByItem(workItemId); var perItemExistingAttachments = from attch in queryByItem where attch.RelationshipExistsOnServer select attch; string attachmentStorageId = FileAttachmentMetadata.CreateAttachmentStorageId(updateDocument); var attachmentInStore = QueryItemSpecificAttachment(perItemExistingAttachments, attachmentStorageId); return(GetAttachmentInStoreCount(attachmentInStore)); }