コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            BasicCategory basiccategory = db.Categories.Find(id);

            db.Categories.Remove(basiccategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public IEnumerable <BasicProduct> FindByCategory(BasicCategory cat)
        {
            var cats = GetSubCategories(cat);
            //!!! Include needs System.Data.Entity ns
            var prods = _db.Products.Include(p => p.Categories).AsEnumerable();

            return(FilterByCategories(prods, cats));
        }
コード例 #3
0
ファイル: DefaultCategory.cs プロジェクト: czechdude/Meshop
        private void BuildTree(BasicCategory category, List<BasicCategory> root)
        {
            category.Children = new List<BasicCategory>();

            foreach (BasicCategory basicCategory in root.FindAll(c => c.Parent != null && c.Parent.CategoryID == category.CategoryID))
            {
                BuildTree(basicCategory, root);
                category.Children.Add(basicCategory);
            }
        }
コード例 #4
0
 public ActionResult Edit(BasicCategory basiccategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(basiccategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(basiccategory));
 }
コード例 #5
0
ファイル: DefaultCategory.cs プロジェクト: czechdude/Meshop
        private void BuildTree(BasicCategory category, List <BasicCategory> root)
        {
            category.Children = new List <BasicCategory>();


            foreach (BasicCategory basicCategory in root.FindAll(c => c.Parent != null && c.Parent.CategoryID == category.CategoryID))
            {
                BuildTree(basicCategory, root);
                category.Children.Add(basicCategory);
            }
        }
コード例 #6
0
ファイル: DefaultCategory.cs プロジェクト: czechdude/Meshop
        private IEnumerable<BasicCategory> GetSubCategories(BasicCategory cat)
        {
            var list = new List<BasicCategory> ();
            var q = _db.Categories.Include(c => c.Children).Where(c => c.CategoryID == cat.CategoryID).SingleOrDefault();

            if (q != null && q.Children != null)
                foreach (var ch in q.Children)
                {
                    list.Add(ch);
                    list.AddRange(GetSubCategories(ch));
                }
            return list;
        }
コード例 #7
0
        private IEnumerable <BasicCategory> BuildLinearTree(BasicCategory category, List <BasicCategory> root, int level)
        {
            var children = new List <BasicCategory>();


            foreach (BasicCategory basicCategory in root.FindAll(c => c.Parent != null && c.Parent.CategoryID == category.CategoryID))
            {
                basicCategory.Name = new string('-', level) + ' ' + basicCategory.Name;
                children.Add(basicCategory);
                children.AddRange(BuildLinearTree(basicCategory, root, level + 1));
            }

            return(children);
        }
コード例 #8
0
ファイル: DefaultCategory.cs プロジェクト: czechdude/Meshop
        private IEnumerable <BasicCategory> GetSubCategories(BasicCategory cat)
        {
            var list = new List <BasicCategory> ();
            var q    = _db.Categories.Include(c => c.Children).Where(c => c.CategoryID == cat.CategoryID).SingleOrDefault();

            if (q != null && q.Children != null)
            {
                foreach (var ch in q.Children)
                {
                    list.Add(ch);
                    list.AddRange(GetSubCategories(ch));
                }
            }
            return(list);
        }
コード例 #9
0
        private void PopulateCategoriesSelectList(BasicCategory selectedCategory)
        {
            var selCatInt = 0;

            if (selectedCategory != null)
            {
                selCatInt = selectedCategory.CategoryID;
            }

            var stack = new Stack <BasicCategory>(GetLinearCategoryTree());

            stack.Push(new BasicCategory()
            {
                Name = "Root"
            });
            var select = new SelectList(stack, "CategoryID", "Name", selCatInt);

            ViewBag.SelectCategory = select;
        }
コード例 #10
0
        public ActionResult Create(BasicCategory basiccategory, string parentVal)
        {
            try
            {
                if (ModelState.IsValid && parentVal != null)
                {

                    if(Convert.ToInt32(parentVal) > 0)
                        basiccategory.Parent = db.Categories.Find(Convert.ToInt32(parentVal));

                    db.Categories.Add(basiccategory);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (DataException e)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator. (" + e.Message + ")");
            }
            PopulateCategoriesSelectList(basiccategory.Parent);
            return View(basiccategory);
        }
コード例 #11
0
        public ActionResult Create(BasicCategory basiccategory, string parentVal)
        {
            try
            {
                if (ModelState.IsValid && parentVal != null)
                {
                    if (Convert.ToInt32(parentVal) > 0)
                    {
                        basiccategory.Parent = db.Categories.Find(Convert.ToInt32(parentVal));
                    }

                    db.Categories.Add(basiccategory);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException e)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator. (" + e.Message + ")");
            }
            PopulateCategoriesSelectList(basiccategory.Parent);
            return(View(basiccategory));
        }
コード例 #12
0
ファイル: CategoryModel.cs プロジェクト: czechdude/Meshop
 public CategoryModel(BasicCategory c,IEnumerable<BasicProduct> p, IEnumerable<BasicCategory>  cs )
 {
     Categories = cs;
     Category = c;
     Products = p;
 }
コード例 #13
0
        protected override void Seed(DatabaseConnection2 context)
        {
            var settings = new List <Setting>
            {
                new Setting {
                    Description = "Currency", Key = "CURRENCY", Type = "String", Value = "CZK"
                },
                new Setting {
                    Description = "Currency sign", Key = "CURRENCY_SIGN", Type = "String", Value = "Kč"
                },
                new Setting {
                    Description = "Shop name", Key = "SHOP_NAME", Type = "String", Value = "Modular E-commerce"
                }
            };

            settings.ForEach(s => context.Settings.Add(s));
            context.SaveChanges();

            var parentCat = new BasicCategory
            {
                CategoryID = 1,
                Name       = "Pens"
            };
            var parentCat1 = new BasicCategory {
                CategoryID = 5, Name = "Notebooks"
            };
            var parentCat2 = new BasicCategory {
                CategoryID = 6, Name = "Paper Style", Parent = parentCat1
            };

            var categories = new List <BasicCategory>
            {
                parentCat,
                new BasicCategory {
                    CategoryID = 2, Name = "Uniball", Parent = parentCat
                },
                new BasicCategory {
                    CategoryID = 3, Name = "Papers"
                },
                new BasicCategory {
                    CategoryID = 4, Name = "Scissors"
                },
                parentCat1,
                parentCat2,
                new BasicCategory {
                    CategoryID = 7, Name = "Blue Colored", Parent = parentCat2
                },
                new BasicCategory {
                    CategoryID = 8, Name = "Cloth Style", Parent = parentCat1
                }
            };

            categories.ForEach(s => s.Children = new List <BasicCategory>());
            parentCat.Children.Add(categories.Find(c => c.CategoryID == 2));
            parentCat1.Children.Add(categories.Find(c => c.CategoryID == 6));
            parentCat1.Children.Add(categories.Find(c => c.CategoryID == 8));
            parentCat2.Children.Add(categories.Find(c => c.CategoryID == 7));

            categories.ForEach(s => s.Products = new List <BasicProduct>());
            categories.ForEach(s => context.Categories.Add(s));
            context.SaveChanges();


            var p1 = new BasicProduct {
                Name = "Pen Uniball SD-102", Price = 25.50m,
            };

            context.Products.Add(p1);

            categories.Find(s => s.CategoryID == 1).Products.Add(p1);
            categories.Find(s => s.CategoryID == 2).Products.Add(p1);

            var p2 = new BasicProduct {
                Name = "Marker Centropen 8722", Price = 41.70m,
            };

            context.Products.Add(p2);

            categories.Find(s => s.CategoryID == 1).Products.Add(p2);

            var p3 = new BasicProduct {
                Name = "Koh I Noor", Price = 5.50m,
            };

            context.Products.Add(p3);

            categories.Find(s => s.CategoryID == 2).Products.Add(p3);

            context.SaveChanges();

            var c1 = new Customer
            {
                Username  = "******",
                Email     = "*****@*****.**",
                Enabled   = true,
                FirstName = "Petr",
                LastName  = "Diviš",
                Password  = "******",
                Role      = "Admin"
            };

            context.Customers.Add(c1);

            var c2 = new Customer
            {
                Username  = "******",
                Email     = "*****@*****.**",
                Enabled   = true,
                FirstName = "Petr",
                LastName  = "Tester",
                Password  = "******",
                Role      = "Admin"
            };

            context.Customers.Add(c2);


            context.SaveChanges();


            var resources = new List <Resource>
            {
                new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "Hello",
                    resourceValue = "Ahoj"
                },
                new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "en",
                    resourceKey   = "Hello",
                    resourceValue = "Hello"
                },
                new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "About",
                    resourceValue = "O programu"
                },
                new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "en",
                    resourceKey   = "About",
                    resourceValue = "About"
                },
                new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "Name",
                    resourceValue = "Jméno"
                },
                new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "Title",
                    resourceValue = "Název"
                }, new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "Value",
                    resourceValue = "Hodnota"
                }, new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "Review",
                    resourceValue = "Recenze"
                }, new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "Last Name",
                    resourceValue = "Příjmení"
                }, new Resource
                {
                    resourceType  = "Global",
                    cultureCode   = "cs",
                    resourceKey   = "Description",
                    resourceValue = "Popis"
                }
            };

            resources.ForEach(r => context.Resources.Add(r));
            context.SaveChanges();


            Modules.InjectSeed(context);
        }
コード例 #14
0
        //
        // GET: /Admin/Categories/Delete/5

        public ActionResult Delete(int id)
        {
            BasicCategory basiccategory = db.Categories.Find(id);

            return(View(basiccategory));
        }
コード例 #15
0
ファイル: DefaultCategory.cs プロジェクト: czechdude/Meshop
 public IEnumerable<BasicCategory> FindSubCategories(BasicCategory cat)
 {
     return GetSubCategories(cat);
 }
コード例 #16
0
        private void PopulateCategoriesSelectList( BasicCategory selectedCategory)
        {
            var selCatInt = 0;

            if (selectedCategory != null) selCatInt = selectedCategory.CategoryID;

            var stack = new Stack<BasicCategory>(GetLinearCategoryTree());
            stack.Push(new BasicCategory(){Name = "Root"});
            var select = new SelectList(stack, "CategoryID", "Name", selCatInt);
            ViewBag.SelectCategory = select;
        }
コード例 #17
0
        private IEnumerable<BasicCategory> BuildLinearTree(BasicCategory category, List<BasicCategory> root, int level)
        {
            var children = new List<BasicCategory>();

            foreach (BasicCategory basicCategory in root.FindAll(c => c.Parent != null && c.Parent.CategoryID == category.CategoryID))
            {
                basicCategory.Name = new string('-',level) + ' ' + basicCategory.Name;
                children.Add(basicCategory);
                children.AddRange(BuildLinearTree(basicCategory, root,level + 1));
            }

            return children;
        }
コード例 #18
0
        //
        // GET: /Admin/Categories/Details/5

        public ViewResult Details(int id)
        {
            BasicCategory basiccategory = db.Categories.Find(id);

            return(View(basiccategory));
        }
コード例 #19
0
ファイル: DefaultCategory.cs プロジェクト: czechdude/Meshop
 public IEnumerable <BasicCategory> FindSubCategories(BasicCategory cat)
 {
     return(GetSubCategories(cat));
 }
コード例 #20
0
 public ActionResult Edit(BasicCategory basiccategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(basiccategory).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(basiccategory);
 }
コード例 #21
0
ファイル: CategoryModel.cs プロジェクト: czechdude/Meshop
 public CategoryModel(BasicCategory c, IEnumerable <BasicProduct> p, IEnumerable <BasicCategory> cs)
 {
     Categories = cs;
     Category   = c;
     Products   = p;
 }