public IHttpActionResult PostLesson(SaveDraftLessonViewModel lesson) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { CommandWorker.SaveNewDraftLesson(lesson); return RedirectToRoute("GetLessonById", new { lessonId = lesson.LessonId }); } catch (Exception e) { return BadRequest(e.Message); } }
public void SaveNewDraftLesson(SaveDraftLessonViewModel model) { Guid authorId = database.IdMaps.GetAggregateId <User>(model.Author.UserId); Guid lessonId = model.LessonId.Equals(0) ? Guid.Empty : database.IdMaps.GetAggregateId <Lesson>(model.LessonId); //Guid lessonId = Guid.NewGuid(); SaveNewDraftLessonCommand command = new SaveNewDraftLessonCommand(lessonId, 1, model.Title, model.Discipline, model.School, model.Classroom, authorId, model.Content, model.Conclusion, model.Feedbacks.ToDictionary(database.IdMaps), model.Tags.ToDictionary()); bus.Send <SaveNewDraftLessonCommand>(command); if (model.Published.Equals(Constants.LESSON_PUBLISHED)) { bus.Send <PublishLessonCommand>(new PublishLessonCommand(command.Id, DateTime.Now, command.Version)); } // 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); }
public void SaveNewDraftLesson(SaveDraftLessonViewModel model) { Guid authorId = database.IdMaps.GetAggregateId<User>(model.Author.UserId); Guid lessonId = model.LessonId.Equals(0) ? Guid.Empty : database.IdMaps.GetAggregateId<Lesson>(model.LessonId); //Guid lessonId = Guid.NewGuid(); SaveNewDraftLessonCommand command = new SaveNewDraftLessonCommand(lessonId, 1, model.Title, model.Discipline, model.School, model.Classroom, authorId, model.Content, model.Conclusion, model.Feedbacks.ToDictionary(database.IdMaps), model.Tags.ToDictionary()); bus.Send<SaveNewDraftLessonCommand>(command); if (model.Published.Equals(Constants.LESSON_PUBLISHED)) bus.Send<PublishLessonCommand>(new PublishLessonCommand(command.Id, DateTime.Now, command.Version)); // 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); }