public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption,
                                                   DateTime userInactiveSinceDate)
        {
            ProfileType? profileType = null;
            if (authenticationOption == ProfileAuthenticationOption.Anonymous)
                profileType = ProfileType.Anonymous;
            else if (authenticationOption == ProfileAuthenticationOption.Authenticated)
                profileType = ProfileType.Authenticated;

            int profilesDeleted = 0;

            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ProfileUserDataStore profileStore = new ProfileUserDataStore(transaction);

                IList<ProfileUser> users = profileStore.FindByFields(ApplicationName, null, userInactiveSinceDate, profileType, PagingInfo.All);

                profilesDeleted = users.Count;

                foreach (ProfileUser user in users)
                {
                    profileStore.Delete(user.Id);
                }

                transaction.Commit();
            }

            return profilesDeleted;
        }
Example #2
0
        public static void ExecuteSqlScript(string script, string connectionName, bool throwExceptions)
        {
            var cfgHelper =
               NHibernateConfigurationManager.ConfigurationHelper;

            var session = cfgHelper.GetCurrentSession(connectionName);
            using (var tran = new TransactionScope(connectionName))
            {
                try
                {
                    var cmd = session.Connection.CreateCommand();
                    cmd.CommandText = script;
                    session.Transaction.Enlist(cmd);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    LoggerFacade.Log.LogException(typeof(SqlExecutor), ex);
                    if (throwExceptions)
                        throw;
                }

                tran.Commit();
            }
        }
        public override void AddUserToProject(out int id, string username, string projectRole, Project project)
        {
            var user = SEOMembershipManager.GetUser(username);
            var projectRoleObj = GetProjectRoleByName(projectRole);

            if (projectRoleObj == null) throw new ProjectRoleNameMustExistException("the project role must exist " + projectRole);
            if (projectRoleObj.IdRoleType != (Int32)RoleType.ProjectRole) throw new ProjectRoleNameMustExistException("the project role must exist " + projectRole);

            using (var tran = new TransactionScope(_connName))
            {
                var projectUser = new ProjectUser
                                      {
                                          Project = project,
                                          ProjectRole = projectRoleObj,
                                          SEOToolsetUser = user,
                                          Enabled = true,
                                          MonitorEmails = false
                                      };

                var ds = DSProjectUser.Create(_connName);

                ds.Insert(projectUser);
                tran.Commit();

                id = projectUser.Id;
            }
        }
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            RoleDataStore roleStore = new RoleDataStore(transaction);

            //Find the roles
            Role[] roles = new Role[roleNames.Length];
            for (int i = 0; i < roleNames.Length; i++)
            {
              //Find the role
              Role role = roleStore.FindByName(ApplicationName, roleNames[i]);
              if (role == null)
            throw new RoleNotFoundException(roleNames[i]);

              roles[i] = role;
            }

            UserInRoleDataStore usersInRolesStore = new UserInRoleDataStore(transaction);
            foreach (string userName in usernames)
            {
              foreach (Role role in roles)
              {
            UserInRole userInRole = new UserInRole(ApplicationName, userName, role.Name);

            usersInRolesStore.Insert(userInRole);
              }
            }

            transaction.Commit();
              }
        }
        public override Article CreateArticle(Category category, string owner,
                                            string name, string title, 
                                            string description, string body)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ArticleDataStore articleStore = new ArticleDataStore(transaction);
                if (articleStore.FindByName(name) != null)
                    throw new ArticleNameAlreadyExistsException(name);

                CategoryDataStore dataStore = new CategoryDataStore(transaction);
                dataStore.Attach(category);

                Article article = new Article(category, name, owner, title, description, body);
                article.Author = owner;

                if (category.AutoApprove)
                    article.Approved = true;

                articleStore.Insert(article);

                transaction.Commit();

                return article;
            }
        }
        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption,
                                                   DateTime userInactiveSinceDate)
        {
            ProfileType? profileType = null;
            if (authenticationOption == ProfileAuthenticationOption.Anonymous)
                profileType = ProfileType.Anonymous;
            else if (authenticationOption == ProfileAuthenticationOption.Authenticated)
                profileType = ProfileType.Authenticated;

            int profilesDeleted;

            using (var transaction = new TransactionScope(_connName))
            {
                var profileStore = DSSEOProfile.Create(_connName);

                IList<SEOProfile> users = profileStore.FindByFields(ApplicationName, null, userInactiveSinceDate,
                                                                    profileType, PagingInfo.All);

                profilesDeleted = users.Count;

                foreach (var user in users)
                {
                    profileStore.Delete(user.Id);
                }

                transaction.Commit();
            }

            return profilesDeleted;
        }
Example #7
0
 public static void ExecuteInTransaction(OnTransaction onTransaction, string connectionName)
 {
     using (var t = new TransactionScope(connectionName))
     {
         if (onTransaction != null)
             if (onTransaction(connectionName))
                 t.Commit();
     }
 }
 public override int CreateSubscriptionLevel(string level, Role role, double price)
 {
     var ds = DSSubscriptionLevel.Create(_connName);
     int id;
     using (var tran = new TransactionScope(_connName))
     {
         id = ds.CreateSubscriptionLevel(level, role, price);
         tran.Commit();
     }
     return id;
 }
 public override int CreateSubscriptionProperty(string propertyName)
 {
     var ds = DSSubscriptionProperty.Create(_connName);
     int id;
     using (var tran = new TransactionScope(_connName))
     {
         id = ds.CreateSubscriptionProperty(propertyName);
         tran.Commit();
     }
     return id;
 }
 public override void CreateSubscriptionDetails(int accountId, IDictionary<int, string> propertyValues)
 {
     var ds = DSSubscriptionDetail.Create(_connName);
     using (var tran = new TransactionScope(_connName))
     {
         foreach (var keyValuePair in propertyValues)
         {
              ds.CreateSubscriptionDetail(accountId, keyValuePair.Key, keyValuePair.Value);
         }
         tran.Commit();
     }
 }
        public override Category CreateCategory(string name, string displayName)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore = new CategoryDataStore(transaction);

                Category category = new Category(name, displayName);

                dataStore.Insert(category);

                transaction.Commit();

                return category;
            }
        }
Example #12
0
    private void AddContact(Contact contact)
    {
        //ContactDataStore.Create(WebApp.GetSession("DefaultDB"));

        ConnectionParameters parameters = ConfigurationHelper.Create("DefaultDB");

        using (TransactionScope transaction = new TransactionScope(parameters))
        {
            ContactDataStore dataStore = new ContactDataStore(transaction);

            dataStore.Insert(contact);

            transaction.Commit();
        }
    }
 ///<summary>
 ///If the promotion has times of use, then it is updated
 ///</summary>
 ///<param name="promoCode"></param>
 public override void Consume(string promoCode)
 {
     var ds = DSPromoCode.Create(_connName);
     var promo = ds.FindByCode(promoCode);
     if (!promo.TimesUsed.HasValue || !promo.MaxUse.HasValue)
         return;
     if (promo.TimesUsed.Value >= promo.MaxUse.Value)
         throw new Exceptions.ExceededMaximumUsageException();
     promo.TimesUsed++;
     using (var tran = new TransactionScope(_connName))
     {
         ds.Update(promo);
         tran.Commit();
     }
 }
        public override void AddPermissionToRole(string role, string permission)
        {
            using (var tran = new TransactionScope(_connName))
            {
                var dsPermission = DSPermission.Create(_connName);
                var dsRole = DSRole.Create(_connName);
                var dsRolePermission = DSPermissionRole.Create(_connName);

                dsRolePermission.Insert(new PermissionRole
                                            {
                                                Permission = dsPermission.FindByName(permission),
                                                Role = dsRole.FindByName(role)
                                            });

                tran.Commit();
            }
        }
        public override Item CreateItem(Category category, string owner,
                                        string title, string description,
                                        string url, string urlName, 
                                        DateTime newsDate)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ItemDataStore dataStore = new ItemDataStore(transaction);

                Item item = new Item(category, owner, title, description, url, urlName, newsDate);

                dataStore.Insert(item);

                transaction.Commit();

                return item;
            }
        }
        public override void CreateAccount(Account account)
        {
            using (var tran = new TransactionScope(_connName))
            {
                var ds = DSAccount.Create(_connName);

                if (account.Owner == null)
                {
                    account.Owner = GetTopLevelAccount();
                }

                if (ds.FindByName(account.Name) != null)
                {
                    tran.Rollback();
                    throw new DuplicatedEntityException("Account");
                }

                ds.Insert(account);
                tran.Commit();
            }
        }
 public override int CreateRankingMonitor(int idProject, string loginName, int[] idKeywordLists, out int keywordsTotal)
 {
     var dsKeyword = DSKeyword.Create(_connName);
     var keywords = dsKeyword.FindUniqueByKeywordLists(idKeywordLists);
     keywordsTotal = keywords.Count;
     var keywordAnalysis = new List<KeywordAnalysis>();
     foreach (var keyword in keywords)
     {
         var keywordAnalysisItem = new KeywordAnalysis
                                       {
                                           Keyword = keyword,
                                           Status = "P"
                                       };
         var keyword1 = keyword;
         if (keywordAnalysis.Exists(Item => Item.Keyword == keyword1)) continue;
         keywordAnalysis.Add(keywordAnalysisItem);
     }
     var rankingMonitorRun = new RankingMonitorRun
                                 {
                                     AnalysisType = "M",
                                     ExecutionDate = DateTime.Now,
                                     Project = new Project { Id = idProject },
                                     Status = new Status { Name = "P" },
                                     User = loginName
                                 };
     using (var tran = new TransactionScope(_connName))
     {
         var dsRankingMonitorRun = DSRankingMonitorRun.Create(_connName);
         var dsKeywordAnalysis = DSKeywordAnalysis.Create(_connName);
         dsRankingMonitorRun.Insert(rankingMonitorRun);
         keywordAnalysis.ForEach(KeywordAnalysis =>
                                     {
                                         KeywordAnalysis.RankingMonitorRun = rankingMonitorRun;
                                         dsKeywordAnalysis.Insert(KeywordAnalysis);
                                     });
         tran.Commit();
     }
     return rankingMonitorRun.Id;
 }
        public override void AddCompetitor(out int id, string name, string url, string description, Project project)
        {
            using (var tran = new TransactionScope(_connName))
            {
                var ds = DSCompetitor.Create(_connName);

                var ce = new Competitor();

                if (name != null)
                    ce.Name = name;
                if (url != null)
                    ce.Url = url;
                if (description != null)
                    ce.Description = description;
                if (project != null)
                    ce.Project = project;

                ds.Insert(ce);

                tran.Commit();

                id = ce.Id;
            }
        }
        public override void AddUsersToRole(string[] userNames, string roleName)
        {
            Check.Ensure(!String.IsNullOrEmpty(roleName), "roleName must not be null nor Empty");
            Check.Ensure(userNames.Length > 0, "At least one username must be provided");

            using (var tran = new TransactionScope(_connName))
            {
                var dsUser = DSSEOToolsetUser.Create(_connName);
                var dsRole = DSRole.Create(_connName);

                for (var i = 0; i < userNames.Length; i++)
                {
                    var user = dsUser.FindByName(userNames[i]);

                    if (user != null)
                    {
                        user.UserRole = dsRole.FindByName(roleName);
                    }

                    dsUser.Update(user);
                }
                tran.Commit();
            }
        }
        public override FileAttachment CreateFileAttachment(Article article, string name, string contentType, byte[] contentData)
        {
            FileAttachment attachment = new FileAttachment(article, name, contentType, contentData);

            //Check attachment
            if (attachment != null)
                Attachment.FileHelper.CheckFile(attachment, article.Category.AttachExtensions, article.Category.AttachMaxSize);

            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ArticleDataStore dataStore = new ArticleDataStore(transaction);
                dataStore.Attach(article);

                FileAttachmentDataStore attachmentStore = new FileAttachmentDataStore(transaction);
                attachmentStore.Insert(attachment);

                transaction.Commit();

                return attachment;
            }
        }
        public override void DeleteItem(Item item)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ItemDataStore dataStore = new ItemDataStore(transaction);

                dataStore.Delete(item.Id);

                transaction.Commit();
            }
        }
        public override void UpdateCategory(Category category)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore = new CategoryDataStore(transaction);

                dataStore.Update(category);

                transaction.Commit();
            }
        }
        public override void UpdateFileAttachment(FileAttachment attachment)
        {
            //Check attachment
            if (attachment != null)
                Attachment.FileHelper.CheckFile(attachment, attachment.Article.Category.AttachExtensions, attachment.Article.Category.AttachMaxSize);

            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                FileAttachmentDataStore dataStore = new FileAttachmentDataStore(transaction);

                dataStore.Update(attachment);

                transaction.Commit();
            }
        }
        public override void DeleteFileAttachment(FileAttachment attachment)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                FileAttachmentDataStore dataStore = new FileAttachmentDataStore(transaction);

                dataStore.Delete(attachment.Id);

                transaction.Commit();
            }
        }
        /// <summary>
        /// Update the specified article. Increment the version if required.
        /// </summary>
        /// <param name="article"></param>
        /// <param name="backupVersion">If true the previous article version is saved as a backup in the VersionedArticle and the current version is incremented.</param>
        public override void UpdateArticle(Article article, bool backupVersion)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ArticleDataStore dataStore = new ArticleDataStore(transaction);

                VersionedArticle versionedArticle = null;

                if (backupVersion)
                {
                    //Retrive the previous version (before saving the new instance) and save a versioned row

                    Article prevVersion = dataStore.FindByKey(article.Id);
                    if (prevVersion == null)
                        throw new ArticleNotFoundException(article.Id);

                    versionedArticle = new VersionedArticle(prevVersion);

                    VersionedArticleDataStore versionedStore = new VersionedArticleDataStore(transaction);
                    versionedStore.Insert(versionedArticle);

                    //Increment the current article version
                    article.IncrementVersion();
                }

                //flag the entity to be updated and attach the entity to the db
                // I must use InsertOrUpdateCopy because if backupVersion = true there is already a
                // persistent entity in the session and I must copy the values to this instance. The Update method in this case throw an exception
                article = dataStore.InsertOrUpdateCopy(article);

                transaction.Commit();
            }
        }
        public override void DeleteArticleVersion(VersionedArticle article)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                VersionedArticleDataStore dataStore = new VersionedArticleDataStore(transaction);

                dataStore.Delete(article.Id);

                transaction.Commit();
            }
        }
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            RoleDataStore roleStore = new RoleDataStore(transaction);
            UserInRoleDataStore userInRoleDataStore = new UserInRoleDataStore(transaction);

            //Find role
            Role role = roleStore.FindByName(ApplicationName, roleName);
            if (role == null)
              throw new RoleNotFoundException(roleName);

            IList<UserInRole> listUserInRole = userInRoleDataStore.FindForRole(ApplicationName, roleName);

            if (throwOnPopulatedRole && listUserInRole.Count > 0)
              throw new System.Configuration.Provider.ProviderException("Cannot delete a populated role.");

            foreach (UserInRole ur in listUserInRole)
              userInRoleDataStore.Delete(ur.Id);

            roleStore.Delete(role.Id);

            transaction.Commit();
              }

              return true;
        }
        public override void CreateRole(string roleName)
        {
            //Check required for MSDN
              if (roleName == null || roleName == "")
            throw new System.Configuration.Provider.ProviderException("Role name cannot be empty or null.");
              if (roleName.IndexOf(',') > 0)
            throw new ArgumentException("Role names cannot contain commas.");
              if (RoleExists(roleName))
            throw new System.Configuration.Provider.ProviderException("Role name already exists.");

              using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            RoleDataStore roleStore = new RoleDataStore(transaction);

            roleStore.Insert(new Role(ApplicationName, roleName));

            transaction.Commit();
              }
        }
Example #29
0
        public static void CreateAccountAndUser(Account account, SEOToolsetUser user)
        {
            using (var tran = new TransactionScope(Provider.ConnectionString))
            {
                if (account.CompanyIdCountry.HasValue && account.CompanyIdCountry == -1)
                    account.CompanyIdCountry = null;
                if (user.Country != null && user.Country.Id == -1)
                    user.Country = null;
                Provider.CreateAccount(account);

                user.Account = account;

                MembershipCreateStatus status;

                SEOMembershipManager.CreateUser(user, out status);

                if (status != MembershipCreateStatus.Success)
                    throw new MembershipCreateUserException(status);
                SEORolesManager.AddUserToRole(user.Login, "Administrator");
                tran.Commit();
            }
        }
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            UserInRoleDataStore usersInRolesStore = new UserInRoleDataStore(transaction);

            foreach (string userName in usernames)
            {
              foreach (string roleName in roleNames)
              {
            UserInRole userInRole = usersInRolesStore.Find(ApplicationName, userName, roleName);
            if (userInRole == null)
              throw new UserInRoleNotFoundException(userName, roleName);

            usersInRolesStore.Delete(userInRole.Id);
              }
            }

            transaction.Commit();
              }
        }