Example #1
0
        public ActionResult UpdateCategories(FormCollection form)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            
            if (!string.IsNullOrEmpty(form["updates"]))
            {
                Dictionary<string, string> updates = serializer.Deserialize<Dictionary<string, string>>(form["updates"]);
                using (ShopStorage context = new ShopStorage())
                {
                    foreach(string key in updates.Keys)
                    {
                        int id = int.Parse(key);
                        Category category = context.Categories.Select(c => c).Where(c => c.Id == id).First();
                        category.Name = updates[key];
                    }
                    context.SaveChanges();
                }
            }

            if (!string.IsNullOrEmpty(form["enablities"]))
            {
                Dictionary<string, string> enables = serializer.Deserialize<Dictionary<string, string>>(form["enablities"]);
                using (ShopStorage context = new ShopStorage())
                {
                    foreach (string key in enables.Keys)
                    {
                        int id = int.Parse(key);
                        Category category = context.Categories.Select(c => c).Where(c => c.Id == id).First();
                        category.Enabled = bool.Parse(enables[key]);
                    }
                    context.SaveChanges(true);
                }
            }
            return RedirectToAction("Categories");
        }
Example #2
0
        public ActionResult CategoriesList()
        {
            using (ShopStorage context = new ShopStorage())
            {
                List<Category> mainCategories = (from category in context.Categories.Include("Parent") where category.Enabled == true select category).ToList();
                List<SelectListItem> categoriesList =
                    (from category in mainCategories
                     where category.Parent == null
                     select new SelectListItem
                         {
                             Text = category.Name,
                             Value = category.Id.ToString(),
                             Selected = category.Id == SystemSettings.ParentCategoryId
                         }).ToList();
                ViewData["categoriesList"] = categoriesList;

                List<SelectListItem> subCategoriesList = 
                    (from category in mainCategories where category.Parent!=null && category.Parent.Id == SystemSettings.ParentCategoryId
                     select new SelectListItem 
                     { 
                         Text = category.Name, 
                         Value = category.Id.ToString(),
                         Selected = category.Id == SystemSettings.CategoryId 
                     }).ToList();
                if (subCategoriesList.Count == 0)
                    subCategoriesList.Add(new SelectListItem { Text = "----", Value = int.MinValue.ToString() });
                ViewData["subCategoriesList"] = subCategoriesList;

                return View();
            }
        }
Example #3
0
        public ActionResult Index()
        {
            using (ShopStorage context = new ShopStorage())
            {
                List<Category> categories = (from category in context.Categories where category.Enabled==true select category).ToList();

                return View(categories);
            }
        }
Example #4
0
 public ActionResult CategoriesList(int? id, int level)
 {
     using (ShopStorage context = new ShopStorage())
     {
         List<Category> categories = context.Categories.Select(c => c).ToList();
         if (id == null)
             categories = categories.Select(c => c).Where(c => c.Parent == null).ToList();
         else
             categories = categories.Select(c => c).Where(c => c.Parent != null && c.Parent.Id == id.Value).ToList();
         ViewData["level"] = level;
         if (id != null)
             ViewData["id"] = id.Value;
         return View(categories);
     }
 }
Example #5
0
 public ActionResult InsertCategory(FormCollection form)
 {
     using (ShopStorage context = new ShopStorage())
     {
         int parentId = int.Parse(form["parentId"]);
         Category parent = null;
         if (parentId >= 0)
             parent = context.Categories.Select(c => c).Where(c => c.Id == parentId).First();
         Category category = new Category();
         category.Parent = parent;
         category.Name = form["categoryName"];
         category.Enabled = form["categoryEnabled"].ToLowerInvariant().IndexOf("true") > -1;
         context.AddToCategories(category);
         context.SaveChanges();
     }
     return RedirectToAction("Categories");
 }
Example #6
0
        public ActionResult DeleteCategoryProperty(int id)
        {
            using (ShopStorage context = new ShopStorage())
            {
                CategoryProperties categoryProperty = context.CategoryProperties.Select(c => c).Where(c => c.Id == id).First();
                context.DeleteObject(categoryProperty);
                context.SaveChanges();
            }

            return RedirectToAction("CategoryProperties");
        }
Example #7
0
        public ActionResult InsertCategoryProperty(FormCollection form)
        {
            using (ShopStorage context = new ShopStorage())
            {
                int categoryId = SystemSettings.CategoryId;
                Category category = context.Categories.Select(c => c).Where(c => c.Id == categoryId).First();
                CategoryProperties categoryProperty = new CategoryProperties();
                categoryProperty.Category = category;
                categoryProperty.Name = form["categoryPropertyName"];
                categoryProperty.Unit = form["categoryUnitName"];

                categoryProperty.IsMainProperty = form["isMainProperty"].ToLowerInvariant().IndexOf("true") > -1;
                context.AddToCategoryProperties(categoryProperty);
                context.SaveChanges();
            }
            return RedirectToAction("CategoryProperties");
        }
Example #8
0
        public ActionResult CategoryProperties(string sCategory, string pCategory)
        {
            bool isParentChanged = pCategory != SystemSettings.ParentCategoryId.ToString() && !string.IsNullOrEmpty(sCategory);
            
            if (!string.IsNullOrEmpty(pCategory))
            {
                SystemSettings.ParentCategoryId = int.Parse(pCategory);
            }
            else if (SystemSettings.ParentCategoryId == int.MinValue)
            {
                using (ShopStorage context = new ShopStorage())
                {
                    Category parentCategory = context.Categories.Select(c => c).Where(c => c.Enabled && c.Parent == null).First();
                    SystemSettings.ParentCategoryId = parentCategory.Id;
                }
            }

            if (isParentChanged || SystemSettings.CategoryId == int.MinValue)
            {
                using (ShopStorage context = new ShopStorage())
                {
                    Category category = context.Categories.Select(c => c).Where(c => c.Enabled && c.Parent != null && c.Parent.Id == SystemSettings.ParentCategoryId).First();
                    SystemSettings.CategoryId = category.Id;
                }
            }
            else if (!string.IsNullOrEmpty(sCategory))
            {
                SystemSettings.CategoryId = int.Parse(sCategory);
            }

            return View();
        }
Example #9
0
 public ActionResult CategoryPropertiesList(int? id)
 {
     using (ShopStorage context = new ShopStorage())
     {
         List<CategoryProperties> categoryProperties = (from categoryProperty in context.CategoryProperties where categoryProperty.Category.Id == SystemSettings.CategoryId select categoryProperty).ToList();
         return View(categoryProperties);
     }
 }