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 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 #3
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 #4
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");
        }