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; }
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); }
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 ServiceAccountDTO GetUserAccountsByUserIDAndAccountId(Int32 userId, Int32 seviceAccountId) { ServiceAccountDTO UserAccountsDTO; ISessionFactory sessionFactory = NhibernateSessionFactory.GetSessionFactory(NhibernateSessionFactory.SessionFactoryConfiguration.Application); using (ISession session = sessionFactory.OpenSession()) { UserLinkDAO userLink = session.QueryOver <UserLinkDAO>().Where(x => x.UserId == userId).And(x => x.Account.ServiceAccountId == seviceAccountId).SingleOrDefault(); if (userLink != null) { ServiceAccount account = userLink.Account.ServiceAccountDAOToDomain(IsDetailsNeed: true); UserAccountsDTO = account.ServiceAccountDomainToDTO(); } else { UserAccountsDTO = null; } return(UserAccountsDTO); } }
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); }
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; }