Esempio n. 1
0
        public void SaveDraftLesson(SaveLessonAndPublishViewModel model)
        {
            Guid authorId = database.IdMaps.GetAggregateId <User>(model.Author.UserId);
            Guid lessonId = database.IdMaps.GetAggregateId <Lesson>(model.LessonId);

            //Guid lessonId = Guid.NewGuid();
            SaveDraftLessonCommand command = new SaveDraftLessonCommand(lessonId, model.Vers, model.Title, model.Discipline, model.School, model.Classroom, authorId, model.Content, model.Conclusion, DateTime.Now, model.Feedbacks.ToDictionary(database.IdMaps), model.Tags.ToDictionary());

            bus.Send <SaveDraftLessonCommand>(command);

            Lesson lesson = repo.GetById <Lesson>(lessonId);

            if (lesson.Published.Equals(Constants.LESSON_NOT_PUBLISHED) && model.Published.Equals(Constants.LESSON_PUBLISHED))
            {
                bus.Send <PublishLessonCommand>(new PublishLessonCommand(command.Id, DateTime.Now, model.Vers));
            }
            else if (lesson.Published.Equals(Constants.LESSON_PUBLISHED) && model.Published.Equals(Constants.LESSON_NOT_PUBLISHED))
            {
                bus.Send <UnPublishLessonCommand>(new UnPublishLessonCommand(command.Id, DateTime.Now, model.Vers));
            }

            // Possibile only into in-process command-query thread
            // If async is necessary the Ids (both Repo and Database) should be generated into the command process
            model.LessonId = database.IdMaps.GetModelId <Lesson>(command.Id);
        }
 //[ResponseType(typeof(Lesson))]
 public IHttpActionResult PutLesson(int id, SaveLessonAndPublishViewModel lesson)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     try
     {
         CommandWorker.SaveDraftLesson(lesson);
         return RedirectToRoute("GetLessonById", new { lessonId = id });
     }
     catch (Exception e)
     {
         return BadRequest(e.Message);
     }
 }
 public void PublishLesson(SaveLessonAndPublishViewModel model)
 {
     Guid lessonId = database.IdMaps.GetAggregateId<Lesson>(model.LessonId);
     bus.Send<PublishLessonCommand>(new PublishLessonCommand(lessonId, DateTime.Now, model.Vers));
 }
        public void SaveDraftLesson(SaveLessonAndPublishViewModel model)
        {
            Guid authorId = database.IdMaps.GetAggregateId<User>(model.Author.UserId);
            Guid lessonId = database.IdMaps.GetAggregateId<Lesson>(model.LessonId);

            //Guid lessonId = Guid.NewGuid();
            SaveDraftLessonCommand command = new SaveDraftLessonCommand(lessonId, model.Vers, model.Title, model.Discipline, model.School, model.Classroom, authorId, model.Content, model.Conclusion, DateTime.Now, model.Feedbacks.ToDictionary(database.IdMaps), model.Tags.ToDictionary());
            bus.Send<SaveDraftLessonCommand>(command);

            Lesson lesson = repo.GetById<Lesson>(lessonId);
            if (lesson.Published.Equals(Constants.LESSON_NOT_PUBLISHED) && model.Published.Equals(Constants.LESSON_PUBLISHED))
                bus.Send<PublishLessonCommand>(new PublishLessonCommand(command.Id, DateTime.Now, model.Vers));
            else if(lesson.Published.Equals(Constants.LESSON_PUBLISHED) && model.Published.Equals(Constants.LESSON_NOT_PUBLISHED))
                bus.Send<UnPublishLessonCommand>(new UnPublishLessonCommand(command.Id, DateTime.Now, model.Vers));

            // Possibile only into in-process command-query thread
            // If async is necessary the Ids (both Repo and Database) should be generated into the command process
            model.LessonId = database.IdMaps.GetModelId<Lesson>(command.Id);
        }