Exemple #1
0
        public IActionResult SaveContentPage(ContentPageModel model)
        {
            var contentPage = model.Id > 0 ? _contentPageService.Get(model.Id) : new ContentPage();

            if (contentPage == null)
            {
                return(NotFound());
            }
            if (model.Published && (model.SeoMeta?.Slug.IsNullEmptyOrWhiteSpace() ?? true))
            {
                if (model.Id > 0)
                {
                    return(R.Fail.With("error", T("Can't publish page without slug")).Result);
                }
            }
            _modelMapper.Map(model, contentPage, nameof(ContentPage.CreatedOn), nameof(ContentPage.PublishedOn), nameof(ContentPage.UserId));
            if (contentPage.Id == 0)
            {
                contentPage.CreatedOn   = DateTime.UtcNow;
                contentPage.PublishedOn = model.PublishedOn == default(DateTime) ? DateTime.UtcNow : model.PublishedOn;
                contentPage.UserId      = ApplicationEngine.CurrentUser.Id;
            }
            contentPage.UpdatedOn = DateTime.UtcNow;
            contentPage.ParentId  = model.ParentId;
            _contentPageService.InsertOrUpdate(contentPage);

            //update the seometa
            _seoMetaService.UpdateSeoMetaForEntity(contentPage, model.SeoMeta);
            return(R.Success.With("contentPageId", contentPage.Id).Result);
        }