public async Task SaveCmsPage(CmsPage cmsPage)
 {
     CmsPage result = CmsPages.AsQueryable().FirstOrDefault<CmsPage>(x => x.Id == cmsPage.Id);
     if (result != null)
         await CmsPages.FindOneAndReplaceAsync(x => x.Id == cmsPage.Id, cmsPage);
     else
         await CmsPages.InsertOneAsync(cmsPage);
 }
        public CmsPageViewModel(CmsPage content)
        {
            if (content != null)
            {
                ObjectId = content.Id.ToString();
                PageContents = content.PageContents;
                PageName = content.PageName;
                UrlName = content.UrlName;
            }

        }
        public async Task<IActionResult> EditCmsPage(CmsPageViewModel model)
        {
            if (ModelState.IsValid)
            {
                CmsPage result = null;
                //load category if available
                if (string.IsNullOrEmpty(model.ObjectId) == false)
                {
                    result = _cmsPageService.GetCmsPageById(new MongoDB.Bson.ObjectId(model.ObjectId));
                }

                if (result == null)
                    result = new CmsPage();

                result.PageContents = model.PageContents;
                result.PageName = model.PageName;
                result.UrlName = model.UrlName;
                if (string.IsNullOrEmpty(result.UrlName))
                    result.UrlName = result.PageName;
                result.UrlName = _mungeUrlService.MungeUrl(result.UrlName);

                await _cmsPageService.SaveCmsPage(result);

                return RedirectToAction("CmsPages");
            }
            return View();
        }