Beispiel #1
0
 public ActionResult Preview(PostViewModel post)
 {
     post.Tags =
         post.TagListCommaDelimited
         .Split(char.Parse(","))
         .ToList()
         .Select(x => new TagViewModel { Name = x })
         .ToList();
     return View(post);
 }
 public ActionResult Edit(PostViewModel post)
 {
     string errorMessage = _postService.EditPost(post);
     if (string.IsNullOrEmpty(errorMessage))
         return RedirectToActionPermanent("Index");
     ModelState.AddModelError("error", errorMessage);
     PostViewModel vm = _postService.GetNewPostViewModel();
     vm.ErrorMessage = errorMessage;
     return View(vm);
 }
Beispiel #3
0
        public string EditPost(PostViewModel post)
        {
            post.DateModified = DateTime.Now;
            SetPublishDate(post);
            Post entity = _postMappingService.MapToEntity(post);

            if (entity.UniqueId.ToString() == "00000000-0000-0000-0000-000000000000") entity.UniqueId = Guid.NewGuid();

            string result = _postRepository.Edit(entity, post.SectedUserId, post.SelectedBlogId);
            SendPing(entity, result);
            return result;
        }
Beispiel #4
0
        public string AddPost(PostViewModel post)
        {
            post.DateCreated = DateTime.Now;
            post.DateModified = DateTime.Now;
            SetPublishDate(post);
            Post entity = _postMappingService.MapToEntity(post);
            entity.UniqueId = Guid.NewGuid();

            string result = _postRepository.Add(entity, post.SectedUserId, post.SelectedBlogId);

            SendPing(entity, result);

            return result;
        }
Beispiel #5
0
 public Post MapToEntity(PostViewModel viewModel)
 {
     return Mapper.Map<PostViewModel, Post>(viewModel);
 }
Beispiel #6
0
 private static void SetPublishDate(PostViewModel post)
 {
     if (post.IsPublished && post.UseCurrentDateTime) post.DatePublished = DateTime.Now;
     else if (post.IsPublished && !post.DatePublished.HasValue) post.DatePublished = DateTime.Now;
 }
Beispiel #7
0
        public PostViewModel GetNewPostViewModel()
        {
            var view = new PostViewModel();

            //get selected user and userlist
            string userName = _httpHelper.GetCurrentUserName();
            UserProfile cUser =
                _profileUserRepository.GetUserProfiles()
                    .FirstOrDefault(x => x.UserName == userName);

            int userId = 0;
            if (cUser != null) userId = cUser.Id;

            IEnumerable<UserViewModel> users = GetUserList();

            view.UserList = new SelectList(users, "Id", "UserName", userId);

            //get the selected blog and blog list
            Blog blog = GetCurrentBlog();
            view.SelectedBlog = _blogsSiteMappingService.MapToView(blog);

            //get blog list
            IEnumerable<BlogSiteViewModel> blogList = GetBlogList();

            //IList<BlogSiteViewModel> blogList = blogs.Select(b => _blogsSiteMappingService.MapToView(b)).ToList();
            view.BlogList = new SelectList(blogList, "BlogId", "BlogName", blog.Id);

            view.DateCreated = DateTime.Now;
            view.DateModified = DateTime.Now;

            return view;
        }