private UserSession( HttpContext context ) { ContentManagementDb db = new ContentManagementDb(); Domain domain = Domain.FindMatchedDomain( context.Request.Url, db ); if ( context.User.Identity.Name == string.Empty ) { if ( domain != null ) { this.Initialise( domain ); } return; } UserProfile user = db.Users.FirstOrDefault( u => u.UserName == context.User.Identity.Name ); if ( user != null ) { if ( domain != null ) { this.Initialise( domain, user ); } } }
private SaveResult CreatePage( PageModel model, ContentManagementDb db ) { try { Page page = new Page(); page.Initialise(); AutoMap.Map( model, page ); page.CreatedByUserId = UserSession.Current.UserId; page.DomainId = UserSession.Current.DomainId; PageContent pageContent = new PageContent(); AutoMap.Map( model, pageContent ); page.PageContent.Add( pageContent ); pageContent.Initialize(); pageContent.LastEditedByUserId = page.CreatedByUserId; SetPublishStatus( page, pageContent, model.Publish ); db.Pages.Add( page ); db.SaveChanges(); return SaveResult.Success; } catch { return SaveResult.Fail; } }
private SaveResult CreateBlog( BlogPostModel model, ContentManagementDb db ) { try { Blog blog = new Blog(); blog.Initialise(); AutoMap.Map( model, blog ); blog.CreatedByUserId = UserSession.Current.UserId; blog.DomainId = UserSession.Current.DomainId; BlogContent blogContent = new BlogContent(); AutoMap.Map( model, blogContent ); blog.BlogContent.Add( blogContent ); blogContent.Initialize(); blogContent.LastEditedByUserId = blog.CreatedByUserId; SetPublishStatus( blog, blogContent, model.Publish ); db.Blogs.Add( blog ); db.SaveChanges(); return SaveResult.Success; } catch { return SaveResult.Fail; } }
/// <summary> /// Finds the domain record that matches the url specified. /// </summary> public static Domain FindMatchedDomain( Uri uri, ContentManagementDb db = null ) { string url = uri.Authority.ToLower(); db = db ?? new ContentManagementDb(); return db.Domains.FirstOrDefault( d => d.DomainUrl.ToLower() == url ); }
public ProductModel( int productId, ContentManagementDb db ) { Product product = db.Products.Find( productId ); AutoMap.Map( product, this ); this.ProductImageModels = product.ProductImages.Where( s => s.IsDeleted == false ).OrderBy( s => s.Ordinal ).ToList().Select( s => new ProductImageModel( s ) ).ToList(); }
public NavigationModel GetNavigationModel( int? navItemId ) { ContentManagementDb db = new ContentManagementDb(); DomainNavigationItem navItem = db.DomainNavigationItems.Find( navItemId ); if ( navItem == null ) return new NavigationModel(); return new NavigationModel( navItem ); }
public PageModel GetPageModel( int? pageId ) { ContentManagementDb db = new ContentManagementDb(); Page page = db.Pages.Find( pageId ); if ( page == null ) return new PageModel(); return new PageModel( page ); }
public SaveResult SavePage( PageModel model ) { ContentManagementDb db = new ContentManagementDb(); Page page = db.Pages.Find( model.PageId ); if ( page == null ) { return CreatePage( model, db ); } return UpdatePage( page, model, db ); }
public SaveResult SaveNavigationItem( NavigationModel model ) { ContentManagementDb db = new ContentManagementDb(); DomainNavigationItem navItem = db.DomainNavigationItems.Find( model.DomainNavigationItemId ); if ( navItem == null ) { return CreateNavItem( model, db ); } return UpdateNavItem( navItem, model, db ); }
public SaveResult SaveBlogPost( BlogPostModel model ) { ContentManagementDb db = new ContentManagementDb(); Blog blog = db.Blogs.Find( model.PageId ); if ( blog == null ) { return CreateBlog( model, db ); } return UpdateBlog( blog, model, db ); }
public SaveResult SaveProductCategory( ProductCategoryModel model ) { ContentManagementDb db = new ContentManagementDb(); ProductCategory productCategory = db.ProductCategories.Find( model.ProductCategoryId ); if ( productCategory == null ) { return CreateProductCategory( model, db ); } return UpdateProductCategory( productCategory, model, db ); }
public SaveResult SaveProduct( ProductModel model ) { ContentManagementDb db = new ContentManagementDb(); Product product = db.Products.Find( model.ProductId ); if ( product == null ) { return CreateProduct( model, db ); } return UpdateProduct( product, model, db ); }
/* ---------------------------------------------------------------------------------------------------------- */ #region Static Methods /// <summary> /// Finds the domain record that matches the url specified. /// </summary> public static Domain FindMatchedDomain(Uri uri, ContentManagementDb db = null) { string url = uri.Authority.ToLower(); int lastIndex = url.Substring(0, url.LastIndexOf(".")).LastIndexOf("."); if (lastIndex > -1) { url = url.Substring(lastIndex + 1); } //if ( url.StartsWith( "www." ) ) //{ // url = url.Substring( "www.".Length ); //} db = db ?? new ContentManagementDb(); return(db.Domains.Include(s => s.BackgroundUpload).Include(s => s.LogoUpload).FirstOrDefault(d => d.DomainUrl.ToLower() == url)); }
private SaveResult UpdateNavItem( DomainNavigationItem navItem, NavigationModel model, ContentManagementDb db ) { if ( UserSession.Current.IsAdministrator == false ) return SaveResult.AccessDenied; if ( UserSession.Current.CurrentDomain( db ).CanAccess( navItem ) == false ) return SaveResult.IncorrectDomain; try { AutoMap.Map( model, navItem ); navItem.UpdateTimeStamp(); db.SaveChanges(); return SaveResult.Success; } catch { return SaveResult.Fail; } }
private SaveResult UpdateProductCategory( ProductCategory product, ProductCategoryModel model, ContentManagementDb db ) { if ( UserSession.Current.IsAdministrator == false ) return SaveResult.AccessDenied; if ( UserSession.Current.CurrentDomain( db ).CanAccess( product ) == false ) return SaveResult.IncorrectDomain; try { AutoMap.Map( model, product ); product.UpdateTimeStamp(); db.SaveChanges(); return SaveResult.Success; } catch { return SaveResult.Fail; } }
private SaveResult CreateProductCategory( ProductCategoryModel model, ContentManagementDb db ) { try { ProductCategory productCategory = new ProductCategory(); productCategory.Initialise(); AutoMap.Map( model, productCategory ); productCategory.DomainId = UserSession.Current.DomainId; db.ProductCategories.Add( productCategory ); db.SaveChanges(); return SaveResult.Success; } catch// (Exception ex) { return SaveResult.Fail; } }
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; } }
private SaveResult CreateProduct( ProductModel model, ContentManagementDb db ) { try { Product product = db.Products.Create(); product.Initialise(); AutoMap.Map( model, product ); product.DomainId = UserSession.Current.DomainId; db.Products.Add( product ); UpdateProductImages( product, model ); db.SaveChanges(); return SaveResult.Success; } catch// ( Exception ex ) { return SaveResult.Fail; } }
public ProductsListModel( ContentManagementDb db ) { int domainId = UserSession.Current.DomainId; this.Products = db.Products.Where( p => p.DomainId == domainId ).ToList().Select( p => new ProductsListItemModel( p ) ).ToList(); }
public NavigationListModel( int domainId, ContentManagementDb db ) { this.NavItems = db.DomainNavigationItems.Where( d => d.DomainId == domainId ).ToList().Select( d => new NavigationListItemModel( d ) ).ToList(); }
public ActionResult Login( LoginModel model, string returnUrl ) { if ( ModelState.IsValid && WebSecurity.Login( model.UserName, model.Password, persistCookie: model.RememberMe ) ) { int userId = WebSecurity.GetUserId( model.UserName ); ContentManagementDb db = new ContentManagementDb(); UserProfile user = db.Users.FirstOrDefault( u => u.UserId == userId ); UserSession.CreateInstance( user, HttpContext ); return RedirectToLocal( returnUrl ); } // If we got this far, something failed, redisplay form ModelState.AddModelError( "", "The user name or password provided is incorrect." ); return View( model ); }
public Domain CurrentDomain( ContentManagementDb db = null ) { db = db ?? new ContentManagementDb(); return db.Domains.Find( DomainId ); }
public PageListModel( int domainId, ContentManagementDb db ) { this.Pages = db.Pages.Where( p => p.DomainId == domainId ).ToList().Select( p => new PageListItemModel( p ) ).ToList(); }
private SaveResult UpdatePage( Page page, PageModel model, ContentManagementDb db ) { if ( UserSession.Current.IsAdministrator == false ) return SaveResult.AccessDenied; if ( UserSession.Current.CurrentDomain( db ).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 ); page.UpdateTimeStamp(); pageContent.UpdateTimeStamp(); pageContent.LastEditedByUserId = UserSession.Current.UserId; SetPublishStatus( page, pageContent, model.Publish ); db.SaveChanges(); return SaveResult.Success; } catch { return SaveResult.Fail; } }
public UserProfile CurrentUser( ContentManagementDb db = null ) { db = db ?? new ContentManagementDb(); return db.Users.Find( UserId ); }
public List<DomainNavigationItem> GetMenuItems( ContentManagementDb db = null ) { db = db ?? new ContentManagementDb(); Domain domain = CurrentDomain( db ); if ( domain == null ) return new List<DomainNavigationItem>(); IQueryable<DomainNavigationItem> menuItems = db.DomainNavigationItems.Where( d => d.DomainId == DomainId ).WhereActive(); if ( this.IsLoggedIn == false ) { menuItems = menuItems.Where( m => m.LoginRequired == false ); } return menuItems.OrderBy( d => d.Ordinal ).ToList(); }
public UploadsListModel( int domainId, ContentManagementDb db ) { this.Uploads = db.Uploads.Where( s => s.DomainId == domainId ).ToList().Select( s => new UploadsListItemModel( s ) ).ToList(); }
public ProductCategoryModel( int productCategoryId, ContentManagementDb db ) { ProductCategory productCategory = db.ProductCategories.Find( productCategoryId ); AutoMap.Map( productCategory, this ); }