예제 #1
0
 public void Handle(ChangedToDoListDescriptionEvent @event)
 {
     using (var db = new ToDoContext())
     {
         int      modelId = _identityMapper.GetModelId <ToDoList>(@event.ToDoListId);
         ToDoList list    = db.Lists.First(t => t.Id.Equals(modelId));
         if (list != null)
         {
             list.Description     = @event.Description;
             db.Entry(list).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
 }
예제 #2
0
 public void Handle(ChangedUserEmailEvent @event)
 {
     using (var db = new DisciturContext())
     {
         // ATTENTION: I can use Discitur.QueryStack.Model.User, instead of Discitur.Domain.Model.User
         //            just because the class Name (User) is the same in both classes.
         //           This implementation of _identityMapper uses Class.Name to map (not FullName)
         int  userId = _identityMapper.GetModelId <User>(@event.Id);
         User user   = db.Users.Find(userId);
         if (user != null)
         {
             user.Email           = @event.Email;
             db.Entry(user).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
 }
예제 #3
0
        public void Handle(SavedNewDraftLessonEvent @event)
        {
            using (var db = new DisciturContext())
            {
                int  userId = _identityMapper.GetModelId <User>(@event.AuthorId);
                User _user  = db.Users.Find(userId);

                Lesson lesson = new Lesson();
                lesson.Title        = @event.Title;
                lesson.Discipline   = @event.Discipline;
                lesson.School       = @event.School;
                lesson.Classroom    = @event.Classroom;
                lesson.Author       = _user;
                lesson.UserId       = _user.UserId;
                lesson.Content      = @event.Content;
                lesson.Conclusion   = @event.Conclusion;
                lesson.PublishDate  = @event.CreationDate;
                lesson.CreationDate = @event.CreationDate;
                UpdateLessonArchFields(lesson, _user.UserName, @event.CreationDate, @event.Version);
                //lesson.LastModifDate = @event.CreationDate;
                //lesson.LastModifUser = _user.UserName;
                //lesson.Vers = 1;
                lesson.RecordState = Constants.RECORD_STATE_ACTIVE;

                // Create FeedBacks Collection
                if (@event.FeedBacks.ContainsKey(EntityStatus.A))
                {
                    @event.FeedBacks[EntityStatus.A].ToList()
                    .ForEach(feedback => {
                        LessonFeedback fb = new LessonFeedback()
                        {
                            Feedback           = feedback.Feedback,
                            Nature             = feedback.Nature,
                            LessonFeedbackGuid = feedback.Id
                        };
                        lesson.FeedBacks.Add(fb);
                    });
                }
                // Create Tags Collection
                if (@event.Tags.ContainsKey(EntityStatus.A))
                {
                    @event.Tags[EntityStatus.A].ToList()
                    .ForEach(tag =>
                    {
                        LessonTag t = new LessonTag()
                        {
                            LessonTagName = tag.LessonTagName
                        };
                        lesson.Tags.Add(t);
                    });
                }

                db.Lessons.Add(lesson);
                db.SaveChanges();
                //Ids mapping
                _identityMapper.Map <Lesson>(lesson.LessonId, @event.Id);
                if (lesson.FeedBacks.Count > 0)
                {
                    lesson.FeedBacks.ToList()
                    .ForEach(feedback => _identityMapper.Map <LessonFeedback>(feedback.LessonFeedbackId, feedback.LessonFeedbackGuid));
                }
            }
        }