예제 #1
0
        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 );
                }
            }
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        /// <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 );
        }
예제 #5
0
        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();
        }
예제 #6
0
        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 );
        }
예제 #7
0
        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 );
        }
예제 #8
0
        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 );
        }
예제 #9
0
        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 );
        }
예제 #10
0
        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 );
        }
예제 #11
0
        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 );
        }
예제 #12
0
        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 );
        }
예제 #13
0
        /* ---------------------------------------------------------------------------------------------------------- */

        #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));
        }
예제 #14
0
        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;
            }
        }
예제 #15
0
        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;
            }
        }
예제 #16
0
        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;
            }
        }
예제 #17
0
        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;
            }
        }
예제 #18
0
        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;
            }
        }
예제 #19
0
 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();
 }
예제 #20
0
 public NavigationListModel( int domainId, ContentManagementDb db )
 {
     this.NavItems = db.DomainNavigationItems.Where( d => d.DomainId == domainId ).ToList().Select( d => new NavigationListItemModel( d ) ).ToList();
 }
예제 #21
0
        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 );
        }
예제 #22
0
        public Domain CurrentDomain( ContentManagementDb db = null )
        {
            db = db ?? new ContentManagementDb();

            return db.Domains.Find( DomainId );
        }
예제 #23
0
 public PageListModel( int domainId, ContentManagementDb db )
 {
     this.Pages = db.Pages.Where( p => p.DomainId == domainId ).ToList().Select( p => new PageListItemModel( p ) ).ToList();
 }
예제 #24
0
        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;
            }
        }
예제 #25
0
        public UserProfile CurrentUser( ContentManagementDb db = null )
        {
            db = db ?? new ContentManagementDb();

            return db.Users.Find( UserId );
        }
예제 #26
0
        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();
        }
예제 #27
0
 public UploadsListModel( int domainId, ContentManagementDb db )
 {
     this.Uploads = db.Uploads.Where( s => s.DomainId == domainId ).ToList().Select( s => new UploadsListItemModel( s ) ).ToList();
 }
예제 #28
0
        public ProductCategoryModel( int productCategoryId, ContentManagementDb db )
        {
            ProductCategory productCategory = db.ProductCategories.Find( productCategoryId );

            AutoMap.Map( productCategory, this );
        }