예제 #1
0
        public static ServiceAccountDAO ServiceAccountDomainToDAO(this ServiceAccount param)
        {
            ServiceAccountDAO target = new ServiceAccountDAO();

            target.ServiceAccountId   = param.ServiceAccountId;
            target.ServiceAccountName = param.ServiceAccountName;
            target.Source             = param.Source;
            target.MinUpdateTime      = param.MinUpdateTime;
            target.AccountVersion     = param.AccountVersion;

            if (param.Tokens != null)
            {
                target.Tokens = param.Tokens.Select <Token, TokenDAO>(x => x.TokenToTokenDAO()).ToList();
            }
            else
            {
                target.Tokens = null;
            }

            if (param.MappingTemplates != null)
            {
                target.MappingTemplates = param.MappingTemplates.Select <Template, TemplateDAO>(x => x.TemplateToTemplateDAO()).ToList();
            }
            else
            {
                target.MappingTemplates = null;
            }

            return(target);
        }
예제 #2
0
        /// <summary>
        /// Convert Domain Object for serialization
        /// </summary>
        /// <param name="param">Object for converting</param>
        /// <param name="IsDetailsNeed">If Tokens and Mapping Templates needs</param>
        /// <returns></returns>
        public static ServiceAccount ServiceAccountDAOToDomain(this ServiceAccountDAO param, Boolean IsDetailsNeed = false)
        {
            ServiceAccount target = new ServiceAccount();

            target.ServiceAccountId   = param.ServiceAccountId;
            target.ServiceAccountName = param.ServiceAccountName;
            target.Source             = param.Source;
            target.MinUpdateTime      = param.MinUpdateTime;
            target.AccountVersion     = param.AccountVersion;

            if (IsDetailsNeed)
            {
                if (param.Tokens != null)
                {
                    target.Tokens = param.Tokens.Select <TokenDAO, Token>(x => x.TokenDAOToTokenDomain()).ToList();
                }
                else
                {
                    target.Tokens = null;
                }

                if (param.MappingTemplates != null)
                {
                    target.MappingTemplates = param.MappingTemplates.Select <TemplateDAO, Template>(x => x.TemplateDAOToTemplateDomain()).ToList();
                }
                else
                {
                    target.MappingTemplates = null;
                }
            }

            return(target);
        }
        public Boolean CreateNewAccount(Int32 UserID, ServiceAccountDTO newAccount)
        {
            Boolean         succeed        = false;
            ISessionFactory sessionFactory = NhibernateSessionFactory.GetSessionFactory(NhibernateSessionFactory.SessionFactoryConfiguration.Application);

            UserLinkDAO       newUserLink = new UserLinkDAO();
            ServiceAccountDAO target      = newAccount.ServiceAccountDTOToDomain().ServiceAccountDomainToDAO();

            target.AccountVersion   = 0;
            newUserLink.UserOwnerID = UserID;
            newUserLink.Account     = target;
            newUserLink.Owner       = true;
            newUserLink.UserId      = UserID;

            using (ISession session = sessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(newUserLink);
                    transaction.Commit();
                    succeed = transaction.WasCommitted;
                }
            }
            return(succeed);
        }
예제 #4
0
        public static ServiceAccountDAO ServiceAccountDomainToDAO(this ServiceAccount param)
        {
            ServiceAccountDAO target = new ServiceAccountDAO();

            target.ServiceAccountId = param.ServiceAccountId;
            target.ServiceAccountName = param.ServiceAccountName;
            target.Source = param.Source;
            target.MinUpdateTime = param.MinUpdateTime;
            target.AccountVersion = param.AccountVersion;

            if (param.Tokens != null)
            {
                target.Tokens = param.Tokens.Select<Token, TokenDAO>(x => x.TokenToTokenDAO()).ToList();
            }
            else
            {
                target.Tokens = null;
            }

            if (param.MappingTemplates != null)
            {
                target.MappingTemplates = param.MappingTemplates.Select<Template, TemplateDAO>(x => x.TemplateToTemplateDAO()).ToList();
            }
            else
            {
                target.MappingTemplates = null;
            }

            return target;
        }
        public Boolean DeleteAccount(Int32 UserID, ServiceAccountDTO accountToDelete, Boolean DeleteForAllUsers)
        {
            Boolean           succeed               = false;
            ISessionFactory   sessionFactory        = NhibernateSessionFactory.GetSessionFactory(NhibernateSessionFactory.SessionFactoryConfiguration.Application);
            ServiceAccountDAO targetAccountToDelete = accountToDelete.ServiceAccountDTOToDomain().ServiceAccountDomainToDAO();

            using (ISession session = sessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    UserLinkDAO userLink = session.QueryOver <UserLinkDAO>().Where(x => x.Account.ServiceAccountId == accountToDelete.ServiceAccountId).And(x => x.UserId == UserID).SingleOrDefault();
                    if (userLink != null)
                    {
                        try
                        {
                            IList <UserLinkDAO> Links = session.QueryOver <UserLinkDAO>().Where(x => x.Account.ServiceAccountId == accountToDelete.ServiceAccountId).List();

                            if (DeleteForAllUsers)
                            {
                                foreach (var item in Links)
                                {
                                    session.Delete(item);
                                }
                                session.Delete(targetAccountToDelete);
                            }
                            else
                            {
                                if (Links.Count == 1)
                                {
                                    session.Delete(targetAccountToDelete);
                                }
                                session.Delete(userLink);
                            }

                            transaction.Commit();
                            succeed = transaction.WasCommitted;
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            return(succeed);
                        }
                    }
                }
            }
            return(succeed);
        }
        public Boolean SaveOrUdateAccount(ServiceAccountDTO account)
        {
            Boolean         succeed        = false;
            ISessionFactory sessionFactory = NhibernateSessionFactory.GetSessionFactory(NhibernateSessionFactory.SessionFactoryConfiguration.Application);

            ServiceAccountDAO target = account.ServiceAccountDTOToDomain().ServiceAccountDomainToDAO();

            using (ISession session = sessionFactory.OpenSession())
            {
                target.AccountVersion += 1;
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(target);
                    transaction.Commit();
                    succeed = transaction.WasCommitted;
                }
            }
            return(succeed);
        }
예제 #7
0
        public static IAccountSettings GetAccountByTokenID(Int32 id)
        {
            IAccountSettings targetAccount = null;

            using (ISession session = sessionFactory.OpenSession())
            {
                TokenDAO          token         = session.Get <TokenDAO>(id);
                ServiceAccountDAO accountFromDB = session.Query <ServiceAccountDAO>().Where(x => x.Tokens.Contains(token)).SingleOrDefault();
                if (accountFromDB != null)
                {
                    targetAccount = GetCurrentInstance(accountFromDB.Source);
                    if (targetAccount != null)
                    {
                        ServiceAccount accountDomain = accountFromDB.ServiceAccountDAOToDomain(true);
                        targetAccount = targetAccount.Convert(accountDomain);
                    }
                }
                return(targetAccount);
            }
        }
        public Boolean DeleteMapping(TemplateDTO template)
        {
            Boolean         succeed        = false;
            ISessionFactory sessionFactory = NhibernateSessionFactory.GetSessionFactory(NhibernateSessionFactory.SessionFactoryConfiguration.Application);
            TemplateDAO     target         = template.TemplateDTOToTemplateDomain().TemplateToTemplateDAO();

            using (ISession session = sessionFactory.OpenSession())
            {
                ServiceAccountDAO account = session.Query <ServiceAccountDAO>().Where(acount => acount.MappingTemplates.Contains(target)).SingleOrDefault();
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(target);
                    transaction.Commit();
                    succeed = transaction.WasCommitted;
                    if (succeed)
                    {
                        UpdateAccountVersion(account.ServiceAccountId, account.AccountVersion + 1);
                    }
                }
            }
            return(succeed);
        }
        public Boolean ShareTheSettingAccount(Int32 currentUserID, ServiceAccountDTO accountToShare, String shareUserName, Boolean owner)
        {
            Boolean         succeed        = false;
            ISessionFactory sessionFactory = NhibernateSessionFactory.GetSessionFactory(NhibernateSessionFactory.SessionFactoryConfiguration.Application);

            UserDAO           shareUser;
            UserLinkDAO       newUserLink        = new UserLinkDAO();
            ServiceAccountDAO targetShareAccount = accountToShare.ServiceAccountDTOToDomain().ServiceAccountDomainToDAO();

            newUserLink.Account     = targetShareAccount;
            newUserLink.Owner       = owner;
            newUserLink.UserOwnerID = currentUserID;

            using (ISession session = sessionFactory.OpenSession())
            {
                shareUser = session.QueryOver <UserDAO>().Where(user => user.UserId == shareUserName).SingleOrDefault();
                if (shareUser != null)
                {
                    newUserLink.UserId = shareUser.ID;
                    UserLinkDAO checkLink = session.QueryOver <UserLinkDAO>().Where(link => link.Account.ServiceAccountId == targetShareAccount.ServiceAccountId).And(link => link.UserId == shareUser.ID).SingleOrDefault();
                    if (checkLink == null)
                    {
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            session.Save(newUserLink);
                            transaction.Commit();
                            succeed = transaction.WasCommitted;
                        }
                    }
                    else
                    {
                        return(succeed);
                    }
                }
            }
            return(succeed);
        }