public ActionResult Create(AddBlogArticleModel model) { try { return CatalogsConsumerHelper.ExecuteWithCatalogScope( container => { var membershipUser = Membership.GetUser(); var userId = (Guid) membershipUser.ProviderUserKey; var blogArticleMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer<IBlogArticleMapper>(container); var blogArticle = blogArticleMapper.Map(model, userId); var blogProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer<IBlogProcess>(container); blogProcess.AddBlogArticle(blogArticle); return RedirectToAction("Index"); }); } catch (Exception) { ModelState.AddModelError("", ExceptionMessages.GenericExceptionMessage); return View(model); } }
public BlogArticle Map(AddBlogArticleModel model, Guid userId) { return new BlogArticle { AuthorId = userId, Content = model.Content, Title = model.Title }; }
public void When_AddBlogArticle_is_mapped_to_a_BlogArticle_then_the_User_is_retrieved_from_the_IUserProcess() { var user = UserCreator.CreateSingle(); var addBlogArticleModel = new AddBlogArticleModel { Content = "content", Title = "title" }; var result = Mapper.Map(addBlogArticleModel, user.Id); Assert.AreEqual(user.Id, result.AuthorId); Assert.AreEqual(addBlogArticleModel.Title, result.Title); Assert.AreEqual(addBlogArticleModel.Content, result.Content); }