public ActionResult CreateCategory() { ViewBag.Categories = repository.Categories().ToList(); ViewBag.CategoryTypes = repository.CategoryTypes.ToList(); Category newitem = new Category(); return PartialView("PartialCreateCategory", newitem); }
public ActionResult CreateCategory(string Title, string Description, int[] selected, int[] selected2,HttpPostedFileBase Image) { Category newcategory = new Category(); newcategory.Title = Title; newcategory.Description = Description; repository.CreateCategory(newcategory, selected, selected2, Image); return RedirectToAction("CategoriesList"); }
public void CreateCategory(Category category, int[] selected, int[] selected2, HttpPostedFileBase image) { Category newcategory = category; //загрузка изображения if (image != null) { newcategory.ImageMimeType = image.ContentType; newcategory.Image = new byte[image.ContentLength]; image.InputStream.Read(newcategory.Image, 0, image.ContentLength); } //загрузка типов категорий newcategory.CategoryTypes.Clear(); if (selected != null){foreach (CategoryType item in CategoryTypes.Where(item => selected.Contains(item.Id))){newcategory.CategoryTypes.Add(item);}} //загрузка родительских категорий newcategory.ParentCategories.Clear(); if (selected2 != null){foreach (Category item in Categories().Where(item => selected2.Contains(item.Id))){newcategory.ParentCategories.Add(item);}} dbcontex.Categories.Add(newcategory); dbcontex.SaveChanges(); }
public void SaveEditedCategory(Category category, int[] selected, int[] selected2, HttpPostedFileBase image) { Category newcategory = FindCategory(category.Id); newcategory.Title = category.Title; newcategory.Description = category.Description; //загрузка изображения if (image != null) { newcategory.ImageMimeType = image.ContentType; newcategory.Image = new byte[image.ContentLength]; image.InputStream.Read(newcategory.Image, 0, image.ContentLength); } newcategory.CategoryTypes.Clear(); if (selected != null){foreach (CategoryType item in CategoryTypes.Where(item => selected.Contains(item.Id))){newcategory.CategoryTypes.Add(item);}} newcategory.ParentCategories.Clear(); if (selected2 != null){foreach (Category item in Categories().Where(item => selected2.Contains(item.Id))){newcategory.ParentCategories.Add(item);}} dbcontex.Entry(newcategory).State = EntityState.Modified; dbcontex.SaveChanges(); }
public void DeleteCategory(Category category) { dbcontex.Categories.Remove(category); dbcontex.SaveChanges(); }
public ActionResult EditCategory(int Id, string Title, string Description, int[] selected, int[] selected2, HttpPostedFileBase Image) { Category newcategory = new Category() { Id=Id,Title=Title,Description = Description}; repository.SaveEditedCategory(newcategory, selected, selected2, Image); return RedirectToAction("CategoriesList"); }