Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
 public BlogArticle Map(AddBlogArticleModel model, Guid userId)
 {
     return(new BlogArticle
     {
         AuthorId = userId,
         Content = model.Content,
         Title = model.Title
     });
 }
Ejemplo n.º 3
0
        public void Post(Guid bandId, [FromBody] AddBlogArticleModel model)
        {
            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);
            });
        }
Ejemplo n.º 4
0
        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);
        }