Пример #1
0
        private void OnEntryRemoved(IDbTransaction tx, ICommit commit, EntryRemoved @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            // Get the original where entry.
            const string sql1   = @"
				SELECT [UserId]
				FROM [dbo].[ActivityProjector.Entry]
				WHERE [EntryId] = @Id;"                ;
            var          userId = tx.Connection.QuerySingle <int>(sql1, (object)sqlParams, tx);

            const string sql2 = @"
				DELETE FROM [dbo].[ActivityProjector.Entry]
				WHERE [EntryId] = @Id;"                ;

            tx.Connection.Execute(sql2, (object)sqlParams, tx);

            RecordActivity(tx, new Models.Activity {
                UserId = userId,
                Type   = (int)ActivityType.EntryRemoved,
                When   = commit.CommitStamp,
                Link   = commit.AggregateId().ToString()
            });
        }
Пример #2
0
        private void OnEntryCommentCreated(IDbTransaction tx, ICommit commit, EntryCommentCreated @event)
        {
            RecordActivity(tx, new Models.Activity {
                UserId = @event.CreatedBy,
                Type   = (int)ActivityType.EntryCommentCreated,
                When   = @event.CreatedAt,
                Link   = $"{commit.AggregateId()},{@event.Id}"
            });

            var author        = new UserDto(_userService.GetUser(@event.CreatedBy, tx));
            var collaborators =
                (_entryService.GetCollaborators(commit.AggregateId())).ToArray()
                .Union(new[] { author })
                .Where(c => c.Id != @event.CreatedBy);

            foreach (var collaborator in collaborators)
            {
                var notification = new Models.EmailNotification {
                    Id          = Guid.NewGuid(),
                    UserId      = @event.CreatedBy,
                    To          = collaborator.Email,
                    When        = @event.CreatedAt,
                    Subject     = $"{author.FirstName} {author.LastName} has made a comment",
                    HtmlBody    = $"<p>{collaborator.FirstName} {collaborator.LastName},</p> <p>Just to let you know {author.FirstName} {author.LastName} has made a new comment on an entry in Folium.</p>",
                    ActionLink  = $"{_applicationConfiguration.Value.BaseUrl}/entries/{commit.AggregateId()}?comment-id={@event.Id}",
                    ActionTitle = "View Entry"
                };
                CreateEmailNotification(tx, notification);
            }
        }
Пример #3
0
        private void OnEntryCreated(IDbTransaction tx, ICommit commit, EntryCreated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            // Record who created the entry so it can be used when it is updated.
            const string sql = @"
				INSERT INTO [dbo].[ActivityProjector.Entry]
					   ([EntryId]
					   ,[UserId])
				 SELECT
					   @Id
					   ,@UserId
				WHERE NOT EXISTS(SELECT * FROM [dbo].[ActivityProjector.Entry] WHERE [EntryId] = @Id);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);

            RecordActivity(tx, new Models.Activity {
                UserId = @event.UserId,
                Type   = (int)ActivityType.EntryCreated,
                When   = @event.CreatedAt,
                Link   = commit.AggregateId().ToString()
            });
        }
Пример #4
0
        private void OnEntryUpdated(IDbTransaction tx, ICommit commit, EntryUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"

				DECLARE @UserId int;  
				SELECT @UserId = [PlacementProjector_Entry].[UserId]
				FROM [dbo].[PlacementProjector.Entry] AS [PlacementProjector_Entry]
				WHERE Id = @Id;

				UPDATE [PlacementProjector_Entry]
				SET [Title] = @Title
					,[Description] = @Description
					,[Where] = @Where
					,[When] = @When
					,[PlacementId] = [PlacementProjector_Placement].[Id]
				FROM [dbo].[PlacementProjector.Entry] AS [PlacementProjector_Entry] 
				INNER JOIN [dbo].[PlacementProjector.Placement] AS [PlacementProjector_Placement]
						ON [PlacementProjector_Placement].[FullyQualifiedTitle] = @Where
						AND [PlacementProjector_Placement].[UserId] = @UserId
				WHERE [PlacementProjector_Entry].Id = @Id;

				DELETE FROM [dbo].[PlacementProjector.Entry]
				WHERE [Id] = @Id
				AND [Where] != @Where;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #5
0
        private void OnEntryCreated(IDbTransaction tx, ICommit commit, EntryCreated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				INSERT INTO [dbo].[PlacementProjector.Entry]
					   ([Id]
					   ,[PlacementId]
					   ,[SkillSetId]
					   ,[Title]
					   ,[Description]
					   ,[UserId]
					   ,[Where]
					   ,[When]
					   ,[Shared])
				SELECT TOP 1
					   @Id
					   ,Id
					   ,@SkillSetId
					   ,@Title
					   ,@Description
					   ,@UserId
					   ,[FullyQualifiedTitle]
					   ,@When
					   ,0 -- Not shared
				FROM [PlacementProjector.Placement]
				WHERE [FullyQualifiedTitle] = @Where
				AND [UserId] = @UserId
				AND NOT EXISTS(SELECT * FROM [dbo].[PlacementProjector.Entry] WHERE Id = @Id);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #6
0
        private void OnEntryCreated(IDbTransaction tx, ICommit commit, EntryCreated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				INSERT INTO [dbo].[EntryProjector.Entry]
					   ([Id]
					   ,[SkillSetId]
					   ,[Title]
					   ,[Description]
					   ,[UserId]
					   ,[Where]
					   ,[When]
					   ,[CreatedAt]
					   ,[LastUpdatedAt]
					   ,[Shared])
				 SELECT
					   @Id
					   ,@SkillSetId
					   ,@Title
					   ,@Description
					   ,@UserId
					   ,@Where
					   ,@When
					   ,@CreatedAt
					   ,@LastUpdatedAt
					   ,0 -- Not shared
				WHERE NOT EXISTS(SELECT * FROM [dbo].[EntryProjector.Entry] WHERE Id = @Id);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #7
0
        private void OnEntryRemoved(IDbTransaction tx, ICommit commit, EntryRemoved @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            // Get the original where entry.
            const string sql1 = @"
				SELECT [Where]
					  ,[UserId]
				FROM [dbo].[WhereProjector.Entry]
				WHERE [EntryId] = @Id;"                ;
            var          row  = tx.Connection.QuerySingle <dynamic>(sql1, (object)sqlParams, tx);

            var where = row.Where;
            var userId = row.UserId;

            const string sql2 = @"
				DELETE FROM [dbo].[WhereProjector.Entry]
				WHERE [EntryId] = @Id;"                ;

            tx.Connection.Execute(sql2, (object)sqlParams, tx);

            DeleteWhereProjection(tx, userId, where);
        }
Пример #8
0
        private void OnEntryShared(IDbTransaction tx, ICommit commit, EntryShared @event)
        {
            RecordActivity(tx, new Models.Activity {
                UserId = @event.UserId,
                Type   = (int)ActivityType.EntryShared,
                When   = commit.CommitStamp,
                Link   = commit.AggregateId().ToString()
            });

            var author        = _userService.GetUser(@event.UserId, tx);
            var collaborators = @event.CollaboratorIds.Select(collaboratorId => _userService.GetUser(collaboratorId, tx));

            foreach (var collaborator in collaborators)
            {
                var customText   = string.IsNullOrWhiteSpace(@event.Message) ? "" : $"<p>{WebUtility.HtmlEncode(@event.Message)}</p>";
                var notification = new Models.EmailNotification {
                    Id          = Guid.NewGuid(),
                    UserId      = @event.UserId,
                    To          = collaborator.Email,
                    When        = commit.CommitStamp,
                    Subject     = $"{author.FirstName} {author.LastName} has shared an entry with you",
                    HtmlBody    = $"<p>{collaborator.FirstName} {collaborator.LastName},</p> <p>Just to let you know {author.FirstName} {author.LastName} has shared an entry in Folium with you.</p>{customText}",
                    ActionLink  = $"{_applicationConfiguration.Value.BaseUrl}/entries/{commit.AggregateId()}",
                    ActionTitle = "View Entry"
                };
                CreateEmailNotification(tx, notification);
            }
        }
Пример #9
0
 private void OnPlacementUpdated(IDbTransaction tx, ICommit commit, PlacementUpdated @event)
 {
     RecordActivity(tx, new Models.Activity {
         UserId = @event.UserId,
         Type   = (int)ActivityType.PlacementUpdated,
         When   = @event.LastUpdatedAt,
         Link   = commit.AggregateId().ToString()
     });
 }
Пример #10
0
 private void OnEntryCollaboratorRemoved(IDbTransaction tx, ICommit commit, EntryCollaboratorRemoved @event)
 {
     RecordActivity(tx, new Models.Activity {
         UserId = @event.UserId,
         Type   = (int)ActivityType.EntryCollaboratorRemoved,
         When   = commit.CommitStamp,
         Link   = commit.AggregateId().ToString()
     });
 }
Пример #11
0
        private void OnPlacementUpdated(IDbTransaction tx, ICommit commit, PlacementUpdated @event)
        {
            var placementSqlParams = new {
                Id    = commit.AggregateId(),
                Where = @event.FullyQualifiedTitle
            };

            // Get the original where Placement.
            const string sql1          = @"
				SELECT [Where]
				FROM [dbo].[WhereProjector.Placement]
				WHERE [PlacementId] = @Id;"                ;
            var          row           = tx.Connection.QuerySingle <dynamic>(sql1, (object)placementSqlParams, tx);
            var          originalWhere = row.Where;

            const string sql2 = @"
				UPDATE [dbo].[WhereProjector.Placement]
				SET [Where] = @Where
				WHERE [PlacementId] = @Id;"                ;

            tx.Connection.Execute(sql2, (object)placementSqlParams, tx);

            var whereSqlParams = new {
                UserId        = @event.UserId,
                Where         = @event.FullyQualifiedTitle,
                OriginalWhere = originalWhere
            };

            const string sql = @"
				DECLARE @where_count int;  
				SELECT @where_count = [UsageCount]
				FROM [dbo].[WhereProjector.Where]
				WHERE [UserId] = @UserId 
				AND [Name] = @OriginalWhere;

				DELETE FROM [dbo].[WhereProjector.Where]
				WHERE [UserId] = @UserId 
				AND [Name] = @OriginalWhere;

				UPDATE [dbo].[WhereProjector.Where]
				SET [UsageCount] = [UsageCount] + @where_count
				WHERE [UserId] = @UserId 
				AND [Name] = @Where;

				INSERT INTO [dbo].[WhereProjector.Where]
					   ([UserId]
					   ,[Name]
					   ,[UsageCount])
				 SELECT
					   @UserId
					   ,@Where
					   ,@where_count
				WHERE NOT EXISTS(SELECT * FROM [dbo].[WhereProjector.Where] WHERE [UserId] = @UserId AND [Name] = @Where);"                ;

            tx.Connection.Execute(sql, (object)whereSqlParams, tx);
        }
Пример #12
0
        private void OnEntryUpdated(IDbTransaction tx, ICommit commit, EntryUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            // Get the original where entry.
            const string sql1          = @"
				SELECT [Where]
					  ,[UserId]
				FROM [dbo].[WhereProjector.Entry]
				WHERE [EntryId] = @Id;"                ;
            var          row           = tx.Connection.QuerySingle <dynamic>(sql1, (object)sqlParams, tx);
            var          originalWhere = row.Where;
            var          userId        = row.UserId;

            const string sql2 = @"
				UPDATE [dbo].[WhereProjector.Entry]
				SET [Where] = @Where
				WHERE [EntryId] = @Id;"                ;

            tx.Connection.Execute(sql2, (object)sqlParams, tx);

            sqlParams = new {
                UserId        = userId,
                Where         = @event.Where,
                OriginalWhere = originalWhere
            };

            const string sql = @"
				UPDATE [dbo].[WhereProjector.Where]
				SET [UsageCount] = [UsageCount] - 1
				WHERE [UserId] = @UserId AND [Name] = @OriginalWhere;

				DELETE FROM [dbo].[WhereProjector.Where]
				WHERE [UserId] = @UserId 
				AND [Name] = @OriginalWhere
				AND [UsageCount] = 0;

				UPDATE [dbo].[WhereProjector.Where]
				SET [UsageCount] = [UsageCount] + 1
				WHERE [UserId] = @UserId AND [Name] = @Where;

				INSERT INTO [dbo].[WhereProjector.Where]
					   ([UserId]
					   ,[Name]
					   ,[UsageCount])
				 SELECT
					   @UserId
					   ,@Where
					   ,1
				WHERE NOT EXISTS(SELECT * FROM [dbo].[WhereProjector.Where] WHERE [UserId] = @UserId AND [Name] = @Where);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #13
0
        private void OnEntryRemoved(IDbTransaction tx, ICommit commit, EntryRemoved @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				DELETE FROM [dbo].[PlacementProjector.Entry]
				WHERE [Id] = @Id;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #14
0
        private void OnPlacementRemoved(IDbTransaction tx, ICommit commit, PlacementRemoved @event)
        {
            var sqlParams = new {
                Id = commit.AggregateId()
            };

            const string sql = @"
				DELETE FROM [dbo].[WhereProjector.Placement]
				WHERE [PlacementId] = @Id;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);

            DeleteWhereProjection(tx, @event.UserId, @event.FullyQualifiedTitle);
        }
Пример #15
0
        private void OnPlacementNameUpdated(IDbTransaction tx, ICommit commit, PlacementNameUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				UPDATE [EntryProjector.Entry]
				SET [Where] = @FullyQualifiedTitle
				WHERE [UserId] = @UserId
				AND [Where] = @OriginalFullyQualifiedTitle;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #16
0
        private void OnEntryUpdated(IDbTransaction tx, ICommit commit, EntryUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				UPDATE [dbo].[EntryProjector.Entry]
				SET [Title] = @Title
					,[Description] = @Description
					,[Where] = @Where
					,[When] = @When
					,[LastUpdatedAt] = @LastUpdatedAt
				WHERE Id = @Id;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #17
0
        private void OnEntryCreatedWithType(IDbTransaction tx, ICommit commit, EntryCreatedWithType @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
			UPDATE [PlacementProjector.Entry]
			SET	[TypeName] = [EntryType].[Name]
			FROM (
				SELECT [Id], [Name]
				FROM [dbo].[EntryType]) AS EntryType
			WHERE
				[EntryType].[Id] = @TypeId
				AND [PlacementProjector.Entry].[Id] = @Id"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #18
0
        private void OnEntryCollaboratorRemoved(IDbTransaction tx, ICommit commit, EntryCollaboratorRemoved @event)
        {
            var sqlParams = new {
                EntryId = commit.AggregateId(),
                @event.UserId
            };

            const string sql = @"
				DELETE FROM [dbo].[PlacementProjector.EntrySharedWith]
				WHERE [EntryId] = @EntryId
					  AND [UserId] = @UserId;

				UPDATE [PlacementProjector.Entry]
				SET	[Shared] = CASE WHEN EXISTS (SELECT 1 FROM [dbo].[PlacementProjector.EntrySharedWith] WHERE [EntryId] = @EntryId) THEN 1 ELSE 0 END
				WHERE [Id] = @EntryId;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #19
0
        private void OnEntryCreated(IDbTransaction tx, ICommit commit, EntryCreated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				INSERT INTO [dbo].[WhereProjector.Entry]
					   ([EntryId]
					   ,[UserId]
					   ,[Where])
				 SELECT
					   @Id
					   ,@UserId
					   ,@Where
				WHERE NOT EXISTS(SELECT * FROM [dbo].[WhereProjector.Entry] WHERE [EntryId] = @Id);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);

            CreateWhereProjection(tx, @event.UserId, @event.Where);
        }
Пример #20
0
        private void OnEntryCommentCreated(IDbTransaction tx, ICommit commit, EntryCommentCreated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.EntryId = commit.AggregateId();

            const string sql = @"
				INSERT INTO [dbo].[EntryProjector.EntryComment]
					   ([Id]
					  ,[EntryId]
					  ,[Comment]
					  ,[CreatedBy]
					  ,[CreatedAt])
				 SELECT
					   @Id
					  ,@EntryId
					  ,@Comment
					  ,@CreatedBy
					  ,@CreatedAt
				WHERE NOT EXISTS(SELECT * FROM [dbo].[EntryProjector.EntryComment] WHERE [EntryId] = @EntryId AND [Id] = @Id);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #21
0
        private void OnPlacementCreated(IDbTransaction tx, ICommit commit, PlacementCreated @event)
        {
            var sqlParams = new {
                Id = commit.AggregateId(),
                @event.UserId,
                Where = @event.FullyQualifiedTitle
            };

            const string sql = @"
				INSERT INTO [dbo].[WhereProjector.Placement]
					   ([PlacementId]
					   ,[UserId]
					   ,[Where])
				 SELECT
					   @Id
					   ,@UserId
					   ,@Where
				WHERE NOT EXISTS(SELECT * FROM [dbo].[WhereProjector.Placement] WHERE [PlacementId] = @Id);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);

            CreateWhereProjection(tx, @event.UserId, @event.FullyQualifiedTitle);
        }
Пример #22
0
        private void OnPlacementUpdated(IDbTransaction tx, ICommit commit, PlacementUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				UPDATE [dbo].[PlacementProjector.Placement]
				SET [Title] = @Title
					,[FullyQualifiedTitle] = @FullyQualifiedTitle
					,[Start] = @Start
					,[End] = @End
					,[Reference] = @Reference
					,[LastUpdatedBy] = @LastUpdatedBy
					,[LastUpdatedAt] = @LastUpdatedAt
				WHERE Id = @Id;

				UPDATE [PlacementProjector.Entry]
				SET [Where] = @FullyQualifiedTitle
				WHERE [PlacementProjector.Entry].PlacementId = @Id;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Пример #23
0
        private void OnEntryShared(IDbTransaction tx, ICommit commit, EntryShared @event)
        {
            foreach (var collaboratorId in @event.CollaboratorIds)
            {
                var sqlParams = new {
                    EntryId = commit.AggregateId(),
                    UserId  = collaboratorId
                };
                const string sql = @"
				INSERT INTO [dbo].[PlacementProjector.EntrySharedWith]
					   ([EntryId]
					   ,[UserId])
				 SELECT
					   @EntryId
					   ,@UserId
				WHERE NOT EXISTS(SELECT * FROM [dbo].[PlacementProjector.EntrySharedWith] WHERE EntryId = @EntryId AND UserId = @UserId);
				
				UPDATE [PlacementProjector.Entry]
				SET	[Shared] = 1
				WHERE [Id] = @EntryId;"                ;
                tx.Connection.Execute(sql, (object)sqlParams, tx);
            }
        }
Пример #24
0
        private void OnPlacementCreated(IDbTransaction tx, ICommit commit, PlacementCreated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();
            _logger.LogDebug($"Creating with CommitId:{commit.CommitId}, CommitSequence:{commit.CommitSequence}, StreamId:{commit.StreamId}, StreamRevision:{commit.StreamRevision}, Events:{commit.Events.FoldLeft("", (s, m) => $"{s}{m.Body} ")},  placement with id {commit.AggregateId()} with the values: Title:{@event.Title}, FullyQualifiedTitle:{@event.FullyQualifiedTitle}, Start:{@event.Start}, End:{@event.End}, Reference:{@event.Reference}, LastUpdatedBy:{@event.LastUpdatedBy}, LastUpdatedAt:{@event.LastUpdatedAt}, UserId:{@event.UserId}, CreatedAt:{@event.CreatedAt}, CreatedBy:{@event.CreatedBy}");

            const string sql = @"
				INSERT INTO [dbo].[PlacementProjector.Placement]
					   ([Id]
					   ,[UserId]
					   ,[Title]
					   ,[FullyQualifiedTitle]
					   ,[Start]
					   ,[End]
					   ,[Reference]
					   ,[CreatedBy]
					   ,[CreatedAt]
					   ,[LastUpdatedBy]
					   ,[LastUpdatedAt])
				 SELECT
					   @Id
					   ,@UserId
					   ,@Title
					   ,@FullyQualifiedTitle
					   ,@Start
					   ,@End
					   ,@Reference
					   ,@CreatedBy
					   ,@CreatedAt
					   ,@CreatedBy
					   ,@CreatedAt
				WHERE NOT EXISTS(SELECT * FROM [dbo].[PlacementProjector.Placement] WHERE Id = @Id);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }