public IPagedList <OnlineCustomerCart> Search(OnlineCustomerSearchQuery query) { var sessionDataQuery = GetSessionDataQuery(query).Cacheable(); var sessionData = sessionDataQuery.List <SessionDataQueryResult>(); var userCartItemCounts = GetUserCartItemCounts(sessionData); var results = sessionData.Select(result => { var itemQueryResult = userCartItemCounts.FirstOrDefault(x => x.UserGuid == result.UserGuid); return(new OnlineCustomerCart { UserId = result.UserId, UserGuid = result.UserGuid, FirstName = result.FirstName ?? string.Empty, LastName = result.LastName ?? string.Empty, Email = result.Email ?? string.Empty, ItemsCount = itemQueryResult?.Count ?? 0, LastUpdatedOn = result.UpdatedOn }); }); return(results.Where(x => x.ItemsCount > 0).ToPagedList(query.Page, 10)); }
public ViewResult Index(OnlineCustomerSearchQuery searchQuery) { ViewData["results"] = _onlineCustomerService.Search(searchQuery); return(View(searchQuery)); }
private IQueryOver <SessionData, SessionData> GetSessionDataQuery(OnlineCustomerSearchQuery query = null) { User userAlias = null; SessionData sessionDataAlias = null; SessionDataQueryResult sessionDataQueryResult = null; var queryOver = _session.QueryOver(() => sessionDataAlias) .JoinAlias(x => x.User, () => userAlias, JoinType.LeftOuterJoin) .Where(x => x.Key == CartManager.CurrentCartGuid) .SelectList(builder => { builder.Select(() => userAlias.FirstName).WithAlias(() => sessionDataQueryResult.FirstName); builder.Select(() => userAlias.LastName).WithAlias(() => sessionDataQueryResult.LastName); builder.Select(() => userAlias.Email).WithAlias(() => sessionDataQueryResult.UserEmail); builder.Select(data => data.UserGuid).WithAlias(() => sessionDataQueryResult.UserGuid); builder.Select(() => userAlias.Id).WithAlias(() => sessionDataQueryResult.UserId); builder.Select(data => data.UpdatedOn).WithAlias(() => sessionDataQueryResult.UpdatedOn); builder.SelectSubQuery(QueryOver.Of <SessionData>() .Where(x => x.UserGuid == sessionDataAlias.UserGuid && x.Key == CartManager.CurrentOrderEmailKey) .Select(x => x.Data) .Take(1)).WithAlias(() => sessionDataQueryResult.SessionEmail); builder.SelectSubQuery(QueryOver.Of <SessionData>() .Where(x => x.UserGuid == sessionDataAlias.UserGuid && x.Key == CartManager.CurrentShippingAddressKey) .Select(x => x.Data) .Take(1)).WithAlias(() => sessionDataQueryResult.SessionShippingAddress); builder.SelectSubQuery(QueryOver.Of <SessionData>() .Where(x => x.UserGuid == sessionDataAlias.UserGuid && x.Key == CartManager.CurrentBillingAddressKey) .Select(x => x.Data) .Take(1)).WithAlias(() => sessionDataQueryResult.SessionBillingAddress); builder.SelectSubQuery(QueryOver.Of <SessionData>() .Where(x => x.UserGuid == sessionDataAlias.UserGuid && x.Key == CartManager.CurrentBillingAddressSameAsShippingAddressKey) .Select(x => x.Data) .Take(1)).WithAlias(() => sessionDataQueryResult.BillingAddressIsSameAsShipping); return(builder); }); if (query != null && !string.IsNullOrWhiteSpace(query.FirstName)) { queryOver = queryOver.Where(() => userAlias.FirstName.IsInsensitiveLike(query.FirstName)); } if (query != null && !string.IsNullOrWhiteSpace(query.LastName)) { queryOver = queryOver.Where(() => userAlias.LastName.IsInsensitiveLike(query.LastName)); } if (query != null && !string.IsNullOrWhiteSpace(query.Email)) { queryOver = queryOver.Where(() => userAlias.Email.IsInsensitiveLike(query.Email)); } if (query != null && query.IsAbandoned) { queryOver = queryOver.Where(() => userAlias.Email != null); } return(queryOver.TransformUsing(Transformers.AliasToBean <SessionDataQueryResult>())); }