Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blog admin support eventPublisher for Tab #1507

Closed
pineportal opened this issue Sep 18, 2018 · 2 comments
Closed

blog admin support eventPublisher for Tab #1507

pineportal opened this issue Sep 18, 2018 · 2 comments
Assignees
Milestone

Comments

@pineportal
Copy link

i want create plugin for blog .but cant use blog-post-edit tab

@pineportal pineportal changed the title blog admin support TabbableModel blog admin support eventPublisher for Tab Sep 18, 2018
@mgesing mgesing self-assigned this Sep 18, 2018
@mgesing mgesing added this to the 3.2 milestone Sep 18, 2018
@pineportal
Copy link
Author

pineportal commented Sep 18, 2018

in BlogController

private readonly IEventPublisher _eventPublisher;

` [HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")]
public ActionResult Create(BlogPostModel model, bool continueEditing, FormCollection form)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
return AccessDeniedView();

        if (ModelState.IsValid)
        {
            var blogPost = model.ToEntity();
            blogPost.CreatedOnUtc = model.CreatedOnUtc;
            blogPost.StartDateUtc = model.StartDate;
            blogPost.EndDateUtc = model.EndDate;
            blogPost.CreatedOnUtc = DateTime.UtcNow;
            _blogService.InsertBlogPost(blogPost);

	_eventPublisher.Publish(new ModelBoundEvent(model, blogPost, form));
			//search engine name
			var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
            _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

			//Stores
			_storeMappingService.SaveStoreMappings<BlogPost>(blogPost, model.SelectedStoreIds);

            NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Added"));
            return continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List");
        }

        //If we got this far, something failed, redisplay form
        ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
		//Stores
		PrepareStoresMappingModel(model, null, true);
        return View(model);
    }

`

[HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")]
public ActionResult Edit(BlogPostModel model, bool continueEditing, FormCollection form)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
return AccessDeniedView();

        var blogPost = _blogService.GetBlogPostById(model.Id);
        if (blogPost == null)
            return RedirectToAction("List");

        if (ModelState.IsValid)
        {
            blogPost = model.ToEntity(blogPost);
            blogPost.CreatedOnUtc = model.CreatedOnUtc;
            blogPost.StartDateUtc = model.StartDate;
            blogPost.EndDateUtc = model.EndDate;
            _blogService.UpdateBlogPost(blogPost);

            //search engine name
            var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
            _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

			//Stores
			_storeMappingService.SaveStoreMappings<BlogPost>(blogPost, model.SelectedStoreIds);

			_eventPublisher.Publish(new ModelBoundEvent(model, blogPost, form));

			NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Updated"));
            return continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List");
        }

        //If we got this far, something failed, redisplay form
        ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
		//Store
		PrepareStoresMappingModel(model, blogPost, true);
        return View(model);
	}

@pineportal
Copy link
Author

add _eventPublisher.Publish(new ModelBoundEvent(model, blogPost, form));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants