Beispiel #1
0
        void Apply(AddedNewCommentEvent @event)
        {
            var comment = new LessonComment()
            {
                Id            = @event.CommentId,
                AuthorId      = @event.AuthorId,
                Content       = @event.Content,
                CreationDate  = @event.Date,
                LastModifDate = @event.Date,
                ParentId      = @event.ParentId,
                Level         = @event.Level,
                RecordState   = Constants.RECORD_STATE_ACTIVE
            };

            Comments.Add(comment);
        }
Beispiel #2
0
        public void Handle(AddedNewCommentEvent @event)
        {
            using (var db = new DisciturContext())
            {
                // get read-model Ids (ID-maps)
                int lessonId = _identityMapper.GetModelId <Lesson>(@event.Id);
                int userId   = _identityMapper.GetModelId <User>(@event.AuthorId);
                int?parentId = @event.ParentId.Equals(Guid.Empty) ? null : (int?)_identityMapper.GetModelId <LessonComment>(@event.ParentId);
                // get involved read-model entities
                User   author = db.Users.Find(userId);
                Lesson lesson = db.Lessons.Find(lessonId);

                // Create new Read-Model Lesson's Comment
                LessonComment comment = new LessonComment();
                comment.Content       = @event.Content;
                comment.CreationDate  = @event.Date;
                comment.Date          = @event.Date;
                comment.LastModifDate = @event.Date;
                comment.LessonId      = lessonId;
                comment.Level         = @event.Level;
                comment.ParentId      = parentId;
                comment.Vers          = 1;
                comment.RecordState   = Constants.RECORD_STATE_ACTIVE;
                comment.UserId        = userId;
                comment.Author        = author;
                comment.LastModifUser = author.UserName;
                db.LessonComments.Add(comment);

                // Update Lesson's version
                // TODO: is it correct to update readModel "devops fields" of lesson in this case?
                UpdateLessonArchFields(lesson, author.UserName, @event.Date, @event.Version);
                // Persist changes
                db.Entry(lesson).State = EntityState.Modified;
                db.SaveChanges();
                // Map new IDs
                // NOTE: Comment is NOT and AR, but it's mapped with it's own Id-map for compatibility with existant read-model
                _identityMapper.Map <LessonComment>(comment.Id, @event.CommentId);
            }
        }
Beispiel #3
0
 void Apply(AddedNewCommentEvent @event)
 {
     var comment = new LessonComment()
     {
         Id = @event.CommentId,
         AuthorId = @event.AuthorId,
         Content = @event.Content,
         CreationDate = @event.Date,
         LastModifDate = @event.Date,
         ParentId = @event.ParentId,
         Level = @event.Level,
         RecordState = Constants.RECORD_STATE_ACTIVE
     };
     Comments.Add(comment);
 }