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); }
public static TEntity CreateAndAdd <TEntity>(this EStoreEntities db) where TEntity : class { var stPerm = db.Set <TEntity>().Create(); db.Set <TEntity>().Add(stPerm); return(stPerm); }
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); }
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(); }
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); } }
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); }
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); }
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); }
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); }
public CartService(EStoreEntities entities) : base(entities) { }
public static List <ProductCategoryItem> AllCategoriesFlatten(this EStoreEntities context) { return(AllCategoriesHierarchy(context).Flatten(x => x.ChildCategories).ToList()); }
public static void Detach <TEntity>(this EStoreEntities _db, TEntity entity) where TEntity : class { _db.Entry(entity).State = EntityState.Detached; }
public InternalServiceBase(EStoreEntities entities) : base(entities) { }
public ProductFeedbackService(EStoreEntities entities) : base(entities) { }
public ProductSingleService(EStoreEntities entities) : base(entities) { }
public SupplierInvoiceService(EStoreEntities entities) : base(entities) { }
protected ServiceBase(EStoreEntities entities) { Db = entities; }
public AdminUserService(EStoreEntities entities) : base(entities) { }
public ProductCategoryService(EStoreEntities entities) : base(entities) { }
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; }
public ArticleService(EStoreEntities entities) : base(entities) { }
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(); }
public FileService(EStoreEntities entities) : base(entities) { }
public static void Attach <TEntity>(this EStoreEntities _db, TEntity entity) where TEntity : class { _db.Set <TEntity>().Attach(entity); }
public EntityServiceBase(EStoreEntities entities) : base(entities) { }
public OrderService(EStoreEntities entities) : base(entities) { }