Пример #1
0
 public ActionResult Rename(int Id, string NewName)
 {
     using (var database = new DatabaseEntities())
     {
         var category = database.CategoryById(Id);
         category.Name = NewName;
         database.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Пример #2
0
 public ActionResult Index()
 {
     var viewModel = new NestedCategoryDescriptor();
     using (var database = new DatabaseEntities())
     {
         viewModel.Subcategories = new List<NestedCategoryDescriptor>();
         foreach (var category in database.Categories.Where(c => c.Parent == null))
             viewModel.Subcategories.Add(GenerateCategory(category));
     }
     return View(viewModel);
 }
Пример #3
0
 public ActionResult Index(int id)
 {
     ItemViewModel viewModel;
     using (var database = new DatabaseEntities())
     {
         var item = database.ItemById(id);
         if (item != null)
             return HttpNotFound();
         viewModel = new ItemViewModel(item);
     }
     return View(viewModel);
 }
Пример #4
0
 public ActionResult Details(int id)
 {
     var downloads = new DownloadCollection();
     using (var database = new DatabaseEntities())
     {
         var item = database.ItemById(id);
         if (item == null)
             return HttpNotFound();
         downloads.PrimaryItem = new ItemViewModel(item);
         AddDependencies(downloads, item);
     }
     return Json(downloads, JsonRequestBehavior.AllowGet);
 }
Пример #5
0
 public ActionResult Index()
 {
     var viewModel = new WebIndexViewModel();
     using (var database = new DatabaseEntities())
     {
         var user = Membership.GetUser();
         viewModel.Items = new List<Item>(
             from i in database.Items
             where i.User == user.UserName
             select i);
     }
     return View(viewModel);
 }
Пример #6
0
 public ActionResult Delete(int Item)
 {
     // TODO: Move all items under this category to parent category
     using (var database = new DatabaseEntities())
     {
         var category = database.CategoryById(Item);
         if (category != null)
         {
             database.DeleteObject(category);
             database.SaveChanges();
         }
     }
     return RedirectToAction("Index");
 }
Пример #7
0
 public ActionResult Add(AddCategoryViewModel viewModel)
 {
     if (!ModelState.IsValid)
         return View(viewModel);
     var category = new Category
     {
         Name = viewModel.Name,
         Parent = viewModel.Parent
     };
     using (var database = new DatabaseEntities())
     {
         database.AddToCategories(category);
         database.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Пример #8
0
 public ActionResult Add()
 {
     var viewModel = new AddCategoryViewModel();
     int parentId;
     if (Request.QueryString["parent"] != null &&
         int.TryParse(Request.QueryString["parent"], out parentId))
     {
         Category parent;
         using (var database = new DatabaseEntities())
         {
             parent = database.CategoryById(parentId);
         }
         if (parent != null)
         {
             viewModel.Parent = parentId;
             viewModel.ParentName = parent.Name;
         }
     }
     return View(viewModel);
 }
Пример #9
0
        public ActionResult Category(string id)
        {
            var categories = id.Split('/');
            id = categories.Last();
            var viewModel = new CategoryViewModel();
            using (var database = new DatabaseEntities())
            {
                var category = database.CategoryByName(id);
                if (category == null)
                    return HttpNotFound();
                viewModel.Name = category.Name;
                if (category.Featured != null)
                    viewModel.FeaturedItem = new ItemViewModel(category.Featured);

                viewModel.Items = new List<Item>(category.Items.Skip(0).Take(10)); // TODO: Pagination

                viewModel.Subcategories = new List<Category>(category.Children);
                viewModel.ParentCategory = category.ParentCategory;
            }
            return View(viewModel);
        }
Пример #10
0
 public static Item ItemById(this DatabaseEntities database, int id)
 {
     return(database.Items.FirstOrDefault(i => i.Id == id));
 }
Пример #11
0
 public static Category CategoryByName(this DatabaseEntities database, string name)
 {
     return(database.Categories.FirstOrDefault(c => c.Name.ToUpper() == name.ToUpper()));
 }
Пример #12
0
 public static Category CategoryById(this DatabaseEntities database, int id)
 {
     return(database.Categories.FirstOrDefault(c => c.Id == id));
 }