/* ---------------------------------------------------------------------------------------------------------- */ #region Private Methods /// <summary> /// Creates a new row in the database. /// </summary> private SaveResult CreateNavItem(NavigationModel model, ContentManagementDb db) { try { DomainNavigationItem navItem = new DomainNavigationItem(); navItem.Initialise(); AutoMap.Map(model, navItem); int domainId = UserSession.Current.DomainId; navItem.DomainId = domainId; navItem.Ordinal = db.DomainNavigationItems.Where(s => s.DomainId == domainId && s.IsDeleted == false).Select(s => s.Ordinal).Max() + 1; db.DomainNavigationItems.Add(navItem); db.SaveChanges(); return(SaveResult.Success); } catch { return(SaveResult.Fail); } }
/* ---------------------------------------------------------------------------------------------------------- */ #region Private Methods /// <summary> /// Creates a new row in the database. /// </summary> private SaveResult CreateBlog(BlogPostModel model, ContentManagementDb db) { try { BlogPost blog = db.Blogs.CreateAdd(); blog.Initialise(); blog.BlogPostContent = new List <BlogPostContent>(); AutoMap.Map(model, blog); blog.CreatedByUserId = UserSession.Current.UserId; blog.DomainId = UserSession.Current.DomainId; BlogPostContent blogContent = new BlogPostContent(); AutoMap.Map(model, blogContent); blog.BlogPostContent.Add(blogContent); blogContent.Initialize(); blogContent.LastEditedByUserId = blog.CreatedByUserId; SetPublishStatus(blog, blogContent, model.Publish); db.SaveChanges(); return(SaveResult.Success); } catch { return(SaveResult.Fail); } }
/// <summary> /// Updates an existing row in the database. /// </summary> private SaveResult UpdateNavItem(DomainNavigationItem navItem, NavigationModel model, ContentManagementDb db) { if (UserSession.Current.IsAdministrator == false) { return(SaveResult.AccessDenied); } if (UserSession.Current.CurrentDomain().CanAccess(navItem) == false) { return(SaveResult.IncorrectDomain); } try { AutoMap.Map(model, navItem); navItem.UpdateTimeStamp(); db.SaveChanges(); return(SaveResult.Success); } catch { return(SaveResult.Fail); } }
/// <summary> /// Saves the home page model into the database. /// </summary> public SaveResult SaveHomePageModel(HomePageModel model) { try { ContentManagementDb db = new ContentManagementDb(); DomainHomePage homePage = db.DomainHomePages.Find(UserSession.Current.DomainId); if (homePage == null) { homePage = db.DomainHomePages.CreateAdd(); homePage.DomainId = UserSession.Current.DomainId; } homePage.ModelType = model.HomePageTemplate; homePage.HomePage = JsonConvert.SerializeObject(model.HomePageTemplateModel); db.SaveChanges(); return(SaveResult.Success); } catch { return(SaveResult.Fail); } }
public SaveResult SaveDomainSettings(DomainModel model) { ContentManagementDb db = new ContentManagementDb(); Domain domain = db.Domains.Find(UserSession.Current.DomainId); AutoMap.Map(model, domain); domain.UpdateTimeStamp(); db.SaveChanges(); return(SaveResult.Success); }
/// <summary> /// Updates an existing row in the database. /// </summary> private SaveResult UpdatePage(Page page, PageModel model, ContentManagementDb db) { if (UserSession.Current.IsAdministrator == false) { return(SaveResult.AccessDenied); } if (UserSession.Current.CurrentDomain().CanAccess(page) == false) { return(SaveResult.IncorrectDomain); } try { PageContent pageContent = page.PageContent.FirstOrDefault(s => s.PublishStatus == PublishStatus.Draft); if (pageContent == null) { pageContent = new PageContent(); page.PageContent.Add(pageContent); } AutoMap.Map(model, pageContent); UpdateWithPageModel(pageContent, model); page.UpdateTimeStamp(); pageContent.UpdateTimeStamp(); pageContent.LastEditedByUserId = UserSession.Current.UserId; SetPublishStatus(page, pageContent, model.Publish); db.SaveChanges(); return(SaveResult.Success); } catch (Exception ex) { ErrorLog.Error("Could not update page", ex); return(SaveResult.Fail); } }
/* ---------------------------------------------------------------------------------------------------------- */ #region Private Methods /// <summary> /// Creates a new row in the database. /// </summary> private SaveResult CreateNavItem(NavigationModel model, ContentManagementDb db) { try { DomainNavigationItem navItem = new DomainNavigationItem(); navItem.Initialise(); AutoMap.Map(model, navItem); navItem.DomainId = UserSession.Current.DomainId; db.DomainNavigationItems.Add(navItem); db.SaveChanges(); return(SaveResult.Success); } catch { return(SaveResult.Fail); } }
/// <summary> /// Updates an existing row in the database. /// </summary> private SaveResult UpdateBlog(BlogPost blog, BlogPostModel model, ContentManagementDb db) { if (UserSession.Current.IsAdministrator == false) { return(SaveResult.AccessDenied); } if (UserSession.Current.CurrentDomain().CanAccess(blog) == false) { return(SaveResult.IncorrectDomain); } try { BlogPostContent pageContent = blog.BlogPostContent.FirstOrDefault(s => s.PublishStatus == PublishStatus.Draft); if (pageContent == null) { pageContent = new BlogPostContent(); blog.BlogPostContent.Add(pageContent); } AutoMap.Map(model, pageContent); blog.UpdateTimeStamp(); pageContent.UpdateTimeStamp(); pageContent.LastEditedByUserId = UserSession.Current.UserId; SetPublishStatus(blog, pageContent, model.Publish); db.SaveChanges(); return(SaveResult.Success); } catch { return(SaveResult.Fail); } }
/* ---------------------------------------------------------------------------------------------------------- */ #region Private Methods /// <summary> /// Creates a new row in the database. /// </summary> private SaveResult CreatePage(PageModel model, ContentManagementDb db) { try { Page page = db.Pages.CreateAdd(); page.Initialise(); page.PageContent = new List <PageContent>(); AutoMap.Map(model, page); page.CreatedByUserId = UserSession.Current.UserId; page.DomainId = UserSession.Current.DomainId; PageContent pageContent = new PageContent(); AutoMap.Map(model, pageContent); UpdateWithPageModel(pageContent, model); page.PageContent.Add(pageContent); pageContent.Initialize(); pageContent.LastEditedByUserId = page.CreatedByUserId; SetPublishStatus(page, pageContent, model.Publish); db.SaveChanges(); return(SaveResult.Success); } catch { return(SaveResult.Fail); } }