Пример #1
0
        public static List <ProductCategoryItem> AllCategoriesHierarchy(this EStoreEntities context)
        {
            var categoryItems = context.Set <tblProductCategory>()
                                .Include(x => x.tblProductCategory1)
                                .Include(x => x.tblProductCategory2)
                                .Where(x => x.ParentCategoryId == null)
                                .ToList()
                                .Select(x => new ProductCategoryItem
            {
                Id              = x.Id,
                Name            = x.Name,
                ChildCategories = x.tblProductCategory1
                                  .Select(c => new ProductCategoryItem
                {
                    Id                 = c.Id,
                    Name               = c.Name,
                    ParentCategoryId   = c.ParentCategoryId,
                    ParentCategoryName = c.ParentCategoryId != null ? c.tblProductCategory2.Name : "",
                })
                                  .ToList()
            })
                                .ToList();

            return(categoryItems);
        }
Пример #2
0
        public static TEntity CreateAndAdd <TEntity>(this EStoreEntities db) where TEntity : class
        {
            var stPerm = db.Set <TEntity>().Create();

            db.Set <TEntity>().Add(stPerm);
            return(stPerm);
        }
Пример #3
0
        public static ProductItem GetProductItem(this EStoreEntities context, long productId)
        {
            var forSaleState = ProductSingleStateEnum.ForSale.CastTo <int>();

            var item = context.Set <tblProduct>()
                       .Where(x => x.Id == productId)
                       .Select(x => new ProductItem
            {
                Id              = x.Id,
                Descripton      = x.Descripton,
                CategoryId      = x.CategoryId,
                CategoryName    = x.tblProductCategory.Name,
                Name            = x.Name,
                YandexUrl       = x.YandexUrl,
                Specs           = x.Specs,
                Price           = x.tblProductSingles.FirstOrDefault(p => p.State == forSaleState).SellPrice ?? 0,
                IsAvaliable     = x.tblProductSingles.Any(p => p.State == forSaleState),
                MainImage       = x.tblFiles.OrderByDescending(f => f.Position).FirstOrDefault().Path,
                SubCategoryId   = x.tblProductCategory.ParentCategoryId,
                SubCategoryName = x.tblProductCategory.tblProductCategory2.Name,
                ProductImages   = x.tblFiles
                                  .Select(f => new FileItem
                {
                    Id          = f.Id,
                    Description = f.Description,
                    Position    = f.Position ?? 0,
                    Path        = f.Path,
                    ProductId   = f.ProductId
                })
                                  .OrderByDescending(f => f.Position)
                                  .ToList(),
                ProductSingleItems = x.tblProductSingles
                                     .Select(s => new ProductSingleItem
                {
                    Id        = s.Id,
                    ProductId = s.ProductId,
                    BuyPrice  = s.BuyPrice,
                    IsNew     = s.IsNew,
                    OrderId   = s.OrderId,
                    StateId   = s.State,
                    SellPrice = s.SellPrice
                })
                                     .ToList(),
                FeedbackItems = x.tblProductFeedbacks
                                .Select(f => new ProductFeedbackItem
                {
                    Id        = f.Id,
                    ProductId = f.ProductId,
                    UserName  = f.UserName,
                    Minuses   = f.Minuses,
                    Comment   = f.Comment,
                    Stars     = f.Stars,
                    Pluses    = f.Pluses
                })
                                .ToList()
            })
                       .Single();

            return(item);
        }
Пример #4
0
        public static void AddOrCreateEntity <T>(this EStoreEntities db, T entity) where T : class, IdEntity
        {
            var entityState = entity.Id == 0 ? EntityState.Added : EntityState.Modified;

            db.Entry(entity).State = entityState;
            db.SaveChanges();
        }
Пример #5
0
 public static void AttachIfDetached <T>(this EStoreEntities db, T entity)
     where T : class
 {
     if (db.Entry(entity).State == EntityState.Detached)
     {
         db.Set <T>().Attach(entity);
     }
 }
Пример #6
0
        public static List <SupplierItem> AllSuppliers(this EStoreEntities context)
        {
            var items = context.Set <tblSupplier>()
                        .Select(x => new SupplierItem
            {
                Name = x.Name,
                Id   = x.Id
            })
                        .OrderBy(x => x.Name)
                        .ToList();

            return(items);
        }
Пример #7
0
 public AppService(EStoreEntities entities) : base(entities)
 {
     Article         = new ArticleService(entities);
     Product         = new ProductService(entities);
     SupplierInvoice = new SupplierInvoiceService(entities);
     InvoicePosition = new SupplierInvoicePositionService(entities);
     File            = new FileService(entities);
     ProductSingle   = new ProductSingleService(entities);
     ProductCategory = new ProductCategoryService(entities);
     AdminUser       = new AdminUserService(entities);
     ProductFeedback = new ProductFeedbackService(entities);
     Cart            = new CartService(entities);
     Order           = new OrderService(entities);
 }
Пример #8
0
        public static List <AdminUserItem> AllAdminUsers(this EStoreEntities context)
        {
            var items = context.Set <tblUser>()
                        .Where(x => x.IsAdmin == true)
                        .Select(x => new AdminUserItem
            {
                Id        = x.Id,
                Email     = x.Email,
                UserName  = x.UserName,
                FirstName = x.FirstName,
                LastName  = x.LastName
            })
                        .ToList();

            return(items);
        }
Пример #9
0
        public static void Delete <T>(this EStoreEntities db, Expression <Func <T, bool> > expression) where T : class
        {
            var items = db.Set <T>().Where(expression);

            db.Set <T>().RemoveRange(items);
        }
Пример #10
0
 public CartService(EStoreEntities entities) : base(entities)
 {
 }
Пример #11
0
 public static List <ProductCategoryItem> AllCategoriesFlatten(this EStoreEntities context)
 {
     return(AllCategoriesHierarchy(context).Flatten(x => x.ChildCategories).ToList());
 }
Пример #12
0
 public static void Detach <TEntity>(this EStoreEntities _db, TEntity entity) where TEntity : class
 {
     _db.Entry(entity).State = EntityState.Detached;
 }
Пример #13
0
 public InternalServiceBase(EStoreEntities entities)
     : base(entities)
 {
 }
Пример #14
0
 public ProductFeedbackService(EStoreEntities entities) : base(entities)
 {
 }
Пример #15
0
 public ProductSingleService(EStoreEntities entities) : base(entities)
 {
 }
Пример #16
0
 public SupplierInvoiceService(EStoreEntities entities) : base(entities)
 {
 }
Пример #17
0
 protected ServiceBase(EStoreEntities entities)
 {
     Db = entities;
 }
Пример #18
0
 public AdminUserService(EStoreEntities entities) : base(entities)
 {
 }
Пример #19
0
 public ProductCategoryService(EStoreEntities entities) : base(entities)
 {
 }
Пример #20
0
 public static void AttachAndAdd <T>(this EStoreEntities db, T entity) where T : class, IdEntity
 {
     db.Set <T>().Attach(entity);
     db.Entry(entity).State = EntityState.Added;
 }
Пример #21
0
 public ArticleService(EStoreEntities entities) : base(entities)
 {
 }
Пример #22
0
 public static void Save <T>(this EStoreEntities db, T entity) where T : class, IdEntity
 {
     db.Set <T>().Attach(entity);
     db.Entry(entity).State = entity.Id == 0 ? EntityState.Added : EntityState.Modified;
     db.SaveChanges();
 }
Пример #23
0
 public FileService(EStoreEntities entities) : base(entities)
 {
 }
Пример #24
0
 public static void Attach <TEntity>(this EStoreEntities _db, TEntity entity) where TEntity : class
 {
     _db.Set <TEntity>().Attach(entity);
 }
Пример #25
0
 public EntityServiceBase(EStoreEntities entities)
     : base(entities)
 {
 }
Пример #26
0
 public OrderService(EStoreEntities entities) : base(entities)
 {
 }