public class ExtendedShopAccountProvider : ShopAccountProvider { //3.4. LOGIN WITH ERP NUMBER /// <summary> /// This method will get Shop Accounts by Account Id. /// </summary> /// <param name="accountId"></param> /// <returns></returns> public virtual IShopAccountCollection GetShopAccountsByAccountId(string accountId) { Guard.ThrowIfEmptyString(accountId, "accountId", "AccountId cannot be empty."); var result = WrapDataAccessException(() => { using (var sm = CreateSessionManager(true)) { var criteria = sm.Session.CreateCriteria(GetRegisteredType<IShopAccount>()); criteria.Add(Expression.Eq("ReferenceId", accountId)); criteria.Add(Expression.Eq("Activated", true)); criteria.Add(Expression.Eq("ShopAccountType", ShopAccountType.Customer)); criteria.Add(Expression.Eq("WebsiteId", Context.WebsiteId)); var countCriteria = CriteriaTransformer.TransformToRowCount(criteria); int totalCount = countCriteria.UniqueResult<int>(); var results = criteria.List<IShopAccount>(); var collection = ObjectFactory.Create<IShopAccountCollection>(); collection.Initialize(results, totalCount); return collection; } }, "Cannot get the list of shop accounts."); return result; }
single
public virtual IShopAccount GetShopAccountByEmail(string email) { Guard.ThrowIfEmptyString(email, "email", "Email cannot be empty."); return WrapDataAccessException(() => { using (var sm = CreateSessionManager(true)) { var criteria = sm.Session.CreateCriteria(GetRegisteredType<IShopAccount>()); criteria.Add(Expression.Eq("Email", email)); criteria.Add(Expression.Eq("WebsiteId", Context.WebsiteId)); return criteria.UniqueResult<IShopAccount>(); } }, "Cannot get shop account by email: Email = {0}, WebsiteId = {1}.", email, Context.WebsiteId); }
Pass String List and get List Object
public virtual IList<IProductEnrichment> GetProductEnrichments(IList<string> productIds) { if (productIds.Count == 0) return new List<IProductEnrichment>(); return WrapDataAccessException(() => { using (var sm = CreateSessionManager(true)) { var criteria = sm.Session.CreateCriteria(GetRegisteredType<IProductEnrichment>()) .Add(Restrictions.Eq("WebsiteId", Context.WebsiteId)); var collection = GetListByPortions(criteria, "ProductId", productIds); return collection.Cast<IProductEnrichment>().ToList(); } }, "Cannot get products enrichments for products with IDs = {0} and website = {1}.", productIds.JoinWith(", "), Context.WebsiteId); }
Get List
/// Ticket 88704: [Kavo] 3.9. PDP – RELATED ITEMS /// <summary> /// Get related product sets /// </summary> /// <returns>List of related product items</returns> public IList<IRelatedProductSet> GetRelatedProductSets() { return WrapDataAccessException(() => { using (var sm = CreateSessionManager(true)) { var criteria = sm.Session.CreateCriteria(GetRegisteredType<IRelatedProductSet>()); criteria.Add(Expression.Eq("WebsiteId", Context.WebsiteId)); return criteria.List<IRelatedProductSet>(); } }, "Cannot get related product sets: WebsiteId = {0}.", Context.WebsiteId); }
Update/Save object
/// Ticket 88704: [Kavo] 3.9. PDP – RELATED ITEMS /// <summary> /// Save/Update related product set /// </summary> /// <param name="relatedProductSet">related product set object</param> public void UpdateRelatedProductSet(IRelatedProductSet relatedProductSet) { WrapDataAccessException(() => { using (var sm = CreateSessionManager(false)) { sm.Session.Merge(relatedProductSet); sm.Commit(); } }, "Cannot update related product sets: Id = {0}, CategoryId = {1}, WebsiteId = {2}.", relatedProductSet.Id, relatedProductSet.CategoryId, relatedProductSet.WebsiteId); }
Filter by table element.
/// Ticket 88704: [Kavo] 3.9. PDP – RELATED ITEMS /// <summary> /// Get related product set /// </summary> /// <param name="categoryId">category id</param> /// <returns>related product set</returns> public IRelatedProductSet GetRelatedProductSetByCategoryId(string categoryId) { return WrapDataAccessException(() => { using (var sm = CreateSessionManager(true)) { var criteria = sm.Session.CreateCriteria(GetRegisteredType<IRelatedProductSet>()); criteria.Add(Expression.Eq("WebsiteId", Context.WebsiteId)); criteria.Add(Expression.Eq("CategoryId", categoryId)); return criteria.UniqueResult<IRelatedProductSet>(); } }, "Cannot get related products set: CategoryId = {0}, WebsiteId = {1}.", categoryId, Context.WebsiteId); }
IN operator
/// Ticket 88704: [Kavo] 3.9. PDP – RELATED ITEMS /// <summary> /// Get related product items by category ids. /// </summary> /// <param name="categoryId">category id</param> /// <returns>related product item</returns> public IList<IRelatedProductSet> GetRelatedProductSetsByCategoryIds(List<string> categoryIds) { if (categoryIds.Count == 0) return new List<IRelatedProductSet>(); return WrapDataAccessException(() => { using (var sm = CreateSessionManager(true)) { var criteria = sm.Session.CreateCriteria(GetRegisteredType<IRelatedProductSet>()) .Add(Restrictions.Eq("WebsiteId", Context.WebsiteId)) .Add(Expression.In("CategoryId", categoryIds)); <---------- return criteria.List<IRelatedProductSet>(); } }, "Cannot get related products set for products with Ids = {0} and website = {1}.", categoryIds.JoinWith(", "), Context.WebsiteId); }