Exemple #1
0
        /// <summary>
        /// Will save a brand new page revision so we can maintain the old page structure for revision history.
        /// Method will generate a new MongoDB ObjectId and UTC datetime for the entity.
        /// </summary>
        /// <param name="page">page to save</param>
        /// <returns>bool</returns>
        public static bool Save(Page page)
        {
            bool SaveSuccessful = true;

            //Create a new object id so we can maintain the revision history of a page, the "PageId" attribute will remain the same.
            page.Id = ObjectId.GenerateNewId().ToString();

            //Timestamp of when the page was saved.
            page.ModifiedDateUTC = DateTime.UtcNow;

            //if we are publishing a page then make sure all pages in DB that exist with same page id are set to not published.
            if (page.Published)
            {
                //set all records with same page id to false before saving new page.

                var UpdateQuery = Query <Page> .EQ(e => e.PageId, page.PageId);

                var UpdateSetStatement = Update <Page> .Set(e => e.Published, false);

                SaveSuccessful = Execute.Update <Page>(COLLECTION_NAME, UpdateQuery, UpdateSetStatement);
            }

            SaveSuccessful = Execute.Save <Page>(COLLECTION_NAME, page);

            //delete versions more than 10
            MongoCollection <Page> Collection = Execute.GetCollection <Page>(COLLECTION_NAME);

            List <Page> PageList = (from e in Collection.AsQueryable <Page>() where e.PageId.Equals(page.PageId) orderby e.ModifiedDateUTC descending select e).Skip(10).ToList();

            List <string> PageIdList = (List <string>)(from e in PageList select e.Id).ToList();

            var DeleteQuery = Query <Page> .In(e => e.Id, PageIdList);

            return(SaveSuccessful && Execute.Delete <Page>(COLLECTION_NAME, DeleteQuery));
        }
        /// <summary>
        /// Add or update an admin user.  Username is unique, password is hashed based on mongo object id.
        /// Will return false if attempting to save with new username of a user that already exists.
        /// </summary>
        /// <param name="adminUser">The new or existing admin user</param>
        /// <returns>bool if successful.</returns>
        public static bool Save(AdminUser adminUser)
        {
            AdminUser AdminUser = LoadByUsername(adminUser.Username);

            //if no users in the database exist with that username, or the only user that exists in the one we are trying to save.
            if (AdminUser == null || string.IsNullOrWhiteSpace(AdminUser.Id) || (AdminUser.Id.Equals(adminUser.Id)))
            {
                //if true we are saving a brand new user
                if (string.IsNullOrWhiteSpace(adminUser.Id))
                {
                    //generate a brand new mongo id
                    adminUser.Id = ObjectId.GenerateNewId().ToString();

                    //hash the password by using the user's mongo id
                    adminUser.Hashed_Password = Hashing.GetSaltedHash(adminUser.Hashed_Password, adminUser.Id.ToString());
                }

                //Timestamp of when the page was saved.
                adminUser.ModifiedDateUTC = DateTime.UtcNow;

                return(Execute.Save <AdminUser>(COLLECTION_NAME, adminUser));
            }

            return(false);
        }
        /// <summary>
        /// Save or update a product.
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public static bool Save(Product product)
        {
            if (product.Id.Equals(string.Empty))
            {
                product.CreatedDateUtc = DateTime.UtcNow;
            }

            return Execute.Save<Product>(COLLECTION_NAME, product);
        }
Exemple #4
0
        /// <summary>
        /// Record a page view
        /// </summary>
        /// <param name="pageView"></param>
        /// <returns></returns>
        public static bool SaveNew(PageView pageView, bool allowPageReportRecording, UserSessionInformation userInfo)
        {
            //if reportings in enabled, and the user is not a bot, and it's been at least 2 seconds since their last page view
            if (allowPageReportRecording && !userInfo.IsBot && (DateTime.UtcNow - userInfo.LastDatePageRecordedUTC).TotalSeconds >= 2)
            {
                bool SaveSuccessful = false;

                SaveSuccessful = UpdateLastPageUserWasOn(allowPageReportRecording, userInfo);

                if (pageView.PageOpenedDateUTC.Equals(DateTime.MinValue))
                {
                    pageView.PageOpenedDateUTC = DateTime.UtcNow;
                }

                //record the current page view
                return(Execute.Save <PageView>(COLLECTION_NAME, pageView));
            }

            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Grab the last page the user visted if exists and update the exit time
        /// </summary>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        public static bool UpdateLastPageUserWasOn(bool allowPageReportRecording, UserSessionInformation userInfo)
        {
            if (allowPageReportRecording && !userInfo.IsBot)
            {
                MongoCollection <PageView> Collection = Execute.GetCollection <PageView>(COLLECTION_NAME);

                //grab the last viewed page and set the exit time if exists
                PageView LastPageView = (from e in Collection.AsQueryable <PageView>() where e.SessionId == userInfo.SessionId orderby e.PageOpenedDateUTC descending select e).FirstOrDefault();


                if (LastPageView != null && LastPageView.SessionId.Equals(userInfo.SessionId))
                {
                    //only update if was not set before, the exit time will already be set whenever the tab was closed and the session ends 20 mins later
                    if (LastPageView.PageExitDateUTC.Equals(DateTime.MinValue))
                    {
                        LastPageView.PageExitDateUTC = DateTime.UtcNow;

                        return(Execute.Save <PageView>(COLLECTION_NAME, LastPageView));
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Load an admin user by comparing their username and hashed password.
        /// </summary>
        /// <param name="username">The unique username.</param>
        /// <param name="password">Unhashed password used to compare with password in database.</param>
        /// <returns>A single admin user object.</returns>
        public static AdminUser LoadByAttemptLogin(string username, string password)
        {
            AdminUser AdminUser = LoadByUsername(username);

            //compare username and hashed password
            if (AdminUser.Username.ToUpper().Equals(username.ToUpper()) && AdminUser.Hashed_Password.Equals(Hashing.GetSaltedHash(password, AdminUser.Id.ToString())))
            {
                if (AdminUser.Active)
                {
                    //record the login date
                    DateTime LastLogin = AdminUser.LastLoginDateUTC;

                    AdminUser.LastLoginDateUTC = DateTime.UtcNow;

                    Execute.Save <AdminUser>(COLLECTION_NAME, AdminUser);

                    AdminUser.LastLoginDateUTC = LastLogin;

                    return(AdminUser);
                }
            }

            return(null);
        }
 /// <summary>
 /// Add a new dashboard notification.
 /// </summary>
 /// <param name="notification">The notification to add.</param>
 /// <returns>bool</returns>
 public static bool Save(Notification notification)
 {
     return(Execute.Save <Notification>(COLLECTION_NAME, notification));
 }
Exemple #8
0
 public static bool Save(AdminUserRole adminUserRole)
 {
     return(Execute.Save <AdminUserRole>(COLLECTION_NAME, adminUserRole));
 }
Exemple #9
0
 /// <summary>
 /// Save a navigation link
 /// </summary>
 /// <param name="navigationLink"></param>
 /// <returns></returns>
 public static bool Save(NavigationMenu masterNavigationLink)
 {
     return(Execute.Save <NavigationMenu>(COLLECTION_NAME, masterNavigationLink));
 }
 /// <summary>
 /// Add a new customer order
 /// </summary>
 /// <param name="order">The order to save or update</param>
 /// <returns>bool if successful</returns>
 public static bool Save(PurchaseOrderDetails order)
 {
     return(Execute.Save <PurchaseOrderDetails>(COLLECTION_NAME, order));
 }
Exemple #11
0
 /// <summary>
 /// Save or update a static property with new values
 /// </summary>
 /// <param name="staticProperty"></param>
 /// <returns></returns>
 public static bool Save(StaticProperty staticProperty)
 {
     return(Execute.Save <StaticProperty>(COLLECTION_NAME, staticProperty));
 }
Exemple #12
0
 /// <summary>
 /// save ColorHex to database.
 /// </summary>
 /// <param name="image"></param>
 /// <returns>bool if successfully saved to DB</returns>
 public static bool Save(ColorHex colorHex)
 {
     return(Execute.Save <ColorHex>(COLLECTION_NAME, colorHex));
 }
Exemple #13
0
 /// <summary>
 /// save image to database.
 /// </summary>
 /// <param name="image"></param>
 /// <returns>bool if successfully saved to DB</returns>
 public static bool Save(Image image)
 {
     return(Execute.Save <Image>(COLLECTION_NAME, image));
 }
Exemple #14
0
 /// <summary>
 /// Save or update a setting group
 /// </summary>
 /// <param name="staticProperty"></param>
 /// <returns></returns>
 public static bool Save(SettingGroup settingGroup)
 {
     return(Execute.Save <SettingGroup>(COLLECTION_NAME, settingGroup));
 }