示例#1
0
        public static async Task <ProductSectionModel> GetProductSectionsAsync(int productId, string userId)
        {
            var db       = ApplicationDbContext.Create();
            var sections = await(from p in db.Products
                                 join pi in db.ProductsItems on p.Id equals pi.ProductId
                                 join i in db.Items on pi.ItemId equals i.Id
                                 join ch in db.Sections on i.SectionId equals ch.Id
                                 where p.Id.Equals(productId)
                                 orderby ch.Id
                                 select new ProductSection
            {
                Id         = ch.Id,
                ItemTypeId = i.ItemTypeId,
                Title      = ch.Title
            }).ToListAsync();
            var result = sections.Distinct(new ProductSectionEqualityComparer()).ToList();
            var model  = new ProductSectionModel
            {
                Sections = result,
                Title    = await(from p in db.Products
                                 where p.Id.Equals(productId)
                                 select p.Title).FirstOrDefaultAsync()
            };

            return(model);
        }
        public static async Task <ProductSectionModel> GetProductSectionsAsync(int productId, string userId)
        {
            var db       = ApplicationDbContext.Create();
            var sections = await(from p in db.Products
                                 join pi in db.ProductItems on p.Id equals pi.ProductId
                                 join i in db.Items on pi.ItemId equals i.Id
                                 join s in db.Sections on i.SectionId equals s.Id
                                 where p.Id.Equals(productId)
                                 orderby s.Title
                                 select new ProductSection
            {
                Id         = s.Id,
                ItemTypeId = i.ItemTypeId,
                Title      = s.Title
            }).ToListAsync();

            foreach (var section in sections)
            {
                section.Items = await GetProductItemRowsAsync(productId, section.Id, section.ItemTypeId, userId);
            }

            var result = sections.Distinct(new ProductSectionEqualityComparer()).ToList();

            // place download section last
            var union = result.Where(r => !r.Title.ToLower().Contains("download"))
                        .Union(result.Where(r => r.Title.ToLower().Contains("download")));

            var model = new ProductSectionModel
            {
                Title    = await(from p in db.Products where p.Id.Equals(productId) select p.Title).FirstOrDefaultAsync(),
                Sections = union
            };

            return(model);
        }
示例#3
0
        public static async Task <ProductSectionModel> GetProductSectionsAsync(int productId, string userId)
        {
            var db = ApplicationDbContext.Create();

            //var sections = await db.Products
            //    .Where(p => p.Id.Equals(productId))
            //    .Join(db.ProductItems,
            //        p => p.Id,
            //        pi => pi.ProductId,
            //        (p, pi) => new { p, pi })
            //    .Join(db.Items,
            //        pi => pi.pi.ItemId,
            //        i => i.Id,
            //        (pi, i) => new { pi, i })
            //    .Join(db.Sections,
            //        i => i.i.SectionId,
            //        s => s.Id,
            //        (i, s) => new ProductSection
            //        {
            //            Id = s.Id,
            //            ItemTypeId = i.i.ItemTypeId,
            //            Title = s.Title
            //        })
            //    .OrderBy(s => s.Title)
            //    .ToListAsync();

            var sections = await(
                from p in db.Products
                join pi in db.ProductItems on p.Id equals pi.ProductId
                join i in db.Items on pi.ItemId equals i.Id
                join s in db.Sections on i.SectionId equals s.Id
                where p.Id.Equals(productId)
                orderby s.Title
                select new ProductSection
            {
                Id         = s.Id,
                ItemTypeId = i.ItemTypeId,
                Title      = s.Title
            }).ToListAsync();

            foreach (var section in sections)
            {
                section.Items = await GetProductItemRowsAsync(productId, section.Id, userId);
            }

            var result = sections.Distinct(new ProductSectionEqualityComparer()).ToList();
            var union  = result.Where(r => !r.Title.ToLower().Contains("download"))
                         .Union(result.Where(r => r.Title.ToLower().Contains("download")));

            var model = new ProductSectionModel
            {
                Sections = union.ToList(),
                Title    = await db.Products.Where(p => p.Id.Equals(productId)).Select(p => p.Title).FirstOrDefaultAsync()
            };


            return(model);
        }
        public ProductSectionForm()
        {
            InitializeComponent();
            IKernel kernel = BootStrapper.Initialize();

            _productSectionService = kernel.GetService(typeof(ProductSectionService)) as ProductSectionService;

            _productSection = new ProductSectionModel();
        }
        private void LoadFormWithData()
        {
            if (_productSectionList == null || _productSectionList.Count <= 0)
            {
                _isAddNewMode = true;
                return;
            }

            _productSection            = _productSectionList[_currentIndex];
            txtProductUnitId.Text      = Convert.ToString(_productSection.Id);
            txtProductSectionName.Text = _productSection.ProductSectionName;
            txtDescription.Text        = _productSection.Description;
            chkIsActive.Checked        = _productSection.IsActive;

            dgvProductSectionList.Rows[_currentIndex].Selected = true;
            dgvProductSectionList.CurrentCell = dgvProductSectionList.Rows[_currentIndex].Cells[0];
            _isChanged    = false;
            _isAddNewMode = false;
        }
示例#6
0
        public static async Task <ProductSectionModel> GetProductSectionAsync(int productId, string userId)
        {
            ProductSectionModel model;

            using (var db = ApplicationDbContext.Create())
            {
                var sections = (await(from product in db.Products
                                      join productItem in db.ProductItems on product.Id equals productItem.ProductId
                                      join item in db.Items on productItem.ItemId equals item.Id
                                      join section in db.Sections on item.SectionId equals section.Id
                                      where product.Id == productId
                                      select new ProductSection
                {
                    SectionId = section.Id,
                    ItemTypeId = item.ItemTypeId,
                    Title = section.Title
                }).ToListAsync()).Distinct().ToArray();

                foreach (var section in sections)
                {
                    section.ProductItemRows =
                        await GetProductItemRowAsync(productId, section.SectionId, section.ItemTypeId, userId, db);
                }

                var ordered = sections.OrderBy(s => s.Title.ToLower().Contains("downloads")).ThenBy(s => s.Title);

                model = new ProductSectionModel
                {
                    ProductSections = ordered,
                    Title           = await db.Products.Where(product => product.Id == productId)
                                      .Select(product => product.Title)
                                      .FirstOrDefaultAsync()
                };
            }

            return(model);
        }