Example #1
0
 public void Save()
 {
     using (var adapter = new DataAccessAdapter())
     {
         adapter.SaveEntity(this);
     }
 }
Example #2
0
 public void Delete()
 {
     using (var adapter = new DataAccessAdapter())
     {
         adapter.DeleteEntity(this);
     }
 }
Example #3
0
        public static ProductEntity LoadProductById(int productId)
        {
            var product = new ProductEntity(productId);

            using (var adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(product);
            }

            return product;
        }
        public static bool Login(string username, string password)
        {
            int userCount = 0;
            EntityCollection users = new EntityCollection(new UserEntityFactory());
            IRelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(PredicateFactory.CompareValue(UserFieldIndex.UserId, ComparisonOperator.Equal, username));
            filter.PredicateExpression.AddWithAnd(PredicateFactory.CompareValue(UserFieldIndex.Password, ComparisonOperator.Equal, password));

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                userCount = adapter.GetDbCount(users, filter);
            }

            return (userCount == 1);
        }
Example #5
0
        public static List<ProductEntity> SearchForProductsByName(string name)
        {
            var bucket = new RelationPredicateBucket();
            bucket.PredicateExpression.Add(PredicateFactory.Like(ProductFieldIndex.Name, string.Format("%{0}%", name)));

            var productEntities = new EntityCollection(new ProductEntityFactory());

            using (var adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(productEntities, bucket);
            }

            var products = new List<ProductEntity>(productEntities.Count);
            products.AddRange(productEntities.Cast<ProductEntity>());

            return products;
        }
        public static List<ProductSectionEntity> GetChildSections(int parentId)
        {
            EntityCollection sections = new EntityCollection(new ProductSectionEntityFactory());
            IRelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(PredicateFactory.CompareValue(ProductSectionFieldIndex.ParentSectionId, ComparisonOperator.Equal, parentId));

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(sections, filter);
            }

            List<ProductSectionEntity> sectionList = new List<ProductSectionEntity>(sections.Count);
            foreach (ProductSectionEntity pse in sections)
            {
                sectionList.Add(pse);
            }

            return sectionList;
        }
        public static string[] FindRolesForUser(string username)
        {
            EntityCollection roles = new EntityCollection(new UserRoleLinkEntityFactory());
            IRelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(PredicateFactory.CompareValue(UserRoleLinkFieldIndex.UserId, ComparisonOperator.Equal, username));

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(roles, filter);
            }

            List<string> returnRoles = new List<string>(roles.Items.Count);

            foreach (UserRoleLinkEntity urle in roles)
            {
                returnRoles.Add(urle.RoleName);
            }

            return returnRoles.ToArray();
        }
        public static List<SpecialOfferEntity> GetSpecialOffers(short numberToReturn)
        {
            EntityCollection offers = new EntityCollection(new SpecialOfferEntityFactory());
            IPrefetchPath2 pf = new PrefetchPath2((int)EntityType.SpecialOfferEntity);
            pf.Add(SpecialOfferEntity.PrefetchPathProduct).SubPath.Add(ProductEntity.PrefetchPathProductSection);

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(offers, null, numberToReturn, null, pf);
            }

            offers.SupportsSorting = true;
            offers.Sort((int) SpecialOfferFieldIndex.Number, ListSortDirection.Ascending);

            SpecialOfferEntity [] specialOffers = new SpecialOfferEntity[numberToReturn];

            foreach (SpecialOfferEntity sof in offers)
            {
                specialOffers[sof.Number - 1] = sof;
            }

            return FillMissingOffers(specialOffers);
        }
        private static EntityCollection LoadProductsForSection(IRelationPredicateBucket filter)
        {
            EntityCollection products = new EntityCollection(new ProductEntityFactory());
            ISortExpression sorter  = new SortExpression();
            sorter.Add(SortClauseFactory.Create(ProductFieldIndex.SortIndex, SortOperator.Ascending));

            IPrefetchPath2 pfVariations = new PrefetchPath2((int)EntityType.ProductEntity);
            pfVariations.Add(ProductEntity.PrefetchPathProductVariation);

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(products, filter, 0, sorter, pfVariations);
            }

            return products;
        }