Manage Subscriptions - Distinct User

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
mbartens
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 107
Joined: Mon Mar 09, 2015 3:34 am

Manage Subscriptions - Distinct User

Post by mbartens » Thu Jun 04, 2015 5:22 am

I'd like the results on this page to show distinct users with a link to the latest expiring subscription
I can achieve that in SQL using this:

Code: Select all

SELECT *
FROM ac_Subscriptions A
WHERE EXISTS (SELECT B.UserId
         FROM ac_Subscriptions B
        WHERE B.UserId = A.UserId
          AND B.ExpirationDate < A.ExpirationDate)
       
       OR (SELECT COUNT(*) FROM ac_Subscriptions C
       WHERE C.UserId = A.UserId) = 1


How can I do that with the SubscriptionRepository? I'm looking at SubscriptionRepository, BuildSearchCriteria

TIA!
May

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Manage Subscriptions - Distinct User

Post by jmestep » Fri Jun 05, 2015 1:08 am

There is code in the ConLib/MoreCategoryItems.ascx.cs that you can use as a pattern for one approach. It's many lines, but you can see the pattern. You would want to use your sql then return a list type of <User>. Here is the end of the query:

Code: Select all

 ISQLQuery query = NHibernateHelper.CreateSQLQuery(sqlquery);                    
                    query.SetParameter("categoryId", _CategoryId);
                    query.SetParameter("nodeType", CatalogNodeType.Product);
                    query.SetParameter("minOrderBy", minOrderBy);
                    query.SetParameter("maxOrderBy", maxOrderBy);                    
                    query.SetParameter("visibilityId", (byte)CatalogVisibility.Public);
                    query.AddEntity(typeof(CatalogNode));
                    productNodes = query.List<CatalogNode>();
Your code would add
IList<User> users= new List<User>();
instead of
IList<CatalogNode> productNodes = new List<CatalogNode>();
end up using query.AddEntity(typeof(User));
users = query.List<User>();

(I haven't tested this)
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

mbartens
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 107
Joined: Mon Mar 09, 2015 3:34 am

Re: Manage Subscriptions - Distinct User

Post by mbartens » Mon Jun 08, 2015 7:22 am

Thank you. I was really hoping to just modify what was existing (make my own copy) in the SubscriptionRepository.BuildSearchCriteria
The page I'm looking at that outputs the data (Admin/People/Subscriptions/Default.aspx) uses and AbleGridView and a DataSource so I would really have to modify how that page works which I don't want to do.
I'm new to NHibernate so that make it a little harder for me. Isn't there a way that I can modify the Subscription criteria to do this?
May

Post Reply