public ActionResult Create(FormCollection form, int brandId, IEnumerable<HttpPostedFileBase> fileUpload, IList<string> fileTitles, string filter) { try { using (var context = new CatalogueContainer()) { var brand = context.Brand.Include("Category").First(b => b.Id == brandId); foreach (var file in fileUpload) { if (file != null) { var product = new Product { Brand = brand }; string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); file.SaveAs(filePath); product.ImageSource = fileName; context.AddToProduct(product); } } context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { Area = "", brand = brand.Name, category=brand.Category.Name, filter = filter }); } } catch { return View(); } }
public ActionResult Create(int id, FormCollection form, string filter) { try { using (var context = new CatalogueContainer()) { var category = context.Category.First(c => c.Id == id); var brand = new Brand { Category = category }; PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr"); foreach (var kvp in cbData) { var attrId = kvp.Key; bool attrValue = kvp.Value; if (attrValue) { var attribute = context.CategoryAttribute.First(c => c.Id == attrId); brand.CategoryAttributes.Add(attribute); } } TryUpdateModel(brand, new[] { "Title", "Name", "SortOrder", "Href", "DescriptionTitle" }); brand.Name = brand.Name.ToLower().Replace(" ", ""); brand.Description = HttpUtility.HtmlDecode(form["Description"]); context.AddToBrand(brand); context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { area = "", category = category.Name, filter=filter }); } } catch { return View(); } }
public ActionResult Create(FormCollection form) { try { using (var context = new CatalogueContainer()) { var project = new Project(); TryUpdateModel(project, new[] { "Name", "Title", "DescriptionTitle", "SortOrder", "SeoDescription", "SeoKeywords" }); project.Description = HttpUtility.HtmlDecode(form["Description"]); project.Name=project.Name.ToLower().Replace(" ", ""); context.AddToProject(project); context.SaveChanges(); return RedirectToAction("Index", "Projects", new { Area = "", project = project.Name }); } } catch { return View(); } }
// // GET: /Admin/Article/Delete/5 public ActionResult Delete(int id) { using (var context = new CatalogueContainer()) { var article = context.Article.First(a => a.Id == id); context.DeleteObject(article); context.SaveChanges(); return RedirectToAction("Index", "Articles", new { area = "" }); } }
public ActionResult Create(FormCollection form) { try { using (var context = new CatalogueContainer()) { var category = new Category(); var attributes = context.CategoryAttribute.ToList(); PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr"); foreach (var kvp in postData) { var attribute = attributes.First(a => a.Id == kvp.Key); if (kvp.Value) { if (!category.CategoryAttributes.Contains(attribute)) category.CategoryAttributes.Add(attribute); } else { if (category.CategoryAttributes.Contains(attribute)) category.CategoryAttributes.Remove(attribute); } } TryUpdateModel(category, new[] { "Name", "Title", "SortOrder", "SeoDescription", "SeoKeywords", "DescriptionTitle" }); category.Description = HttpUtility.HtmlDecode(form["Description"]); category.Name = category.Name.ToLower().Replace(" ", ""); context.AddToCategory(category); context.SaveChanges(); return RedirectToAction("Index", "Category", new { area = "Admin" }); } } catch { return View(); } }
public ActionResult Edit(int id, FormCollection form) { try { using (var context = new CatalogueContainer()) { var attribute = context.CategoryAttribute.First(a => a.Id == id); TryUpdateModel(attribute, new[] { "Title", "Name" }); context.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, FormCollection form) { try { using (var context = new CatalogueContainer()) { var article = context.Article.First(a => a.Id == id); TryUpdateModel(article, new[] { "Title", "Date" }); article.Text = HttpUtility.HtmlDecode(form["Text"]); context.SaveChanges(); return RedirectToAction("Index", "Articles", new { area = "" }); } } catch { return View(); } }
public ActionResult Create(FormCollection form) { try { using (var context = new CatalogueContainer()) { var attribute = new CategoryAttribute(); TryUpdateModel(attribute, new[] { "Title", "Name" }); context.AddToCategoryAttribute(attribute); context.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult AddImage(IEnumerable<HttpPostedFileBase> fileUpload) { using (var context = new CatalogueContainer()) { foreach (var file in fileUpload) { if (file != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); file.SaveAs(filePath); var mpi = new MainPageImage() {ImageSource = fileName}; context.AddToMainPageImage(mpi); context.SaveChanges(); } } return RedirectToAction("Index", "Home", new {area = ""}); } }
public ActionResult Edit(int id, FormCollection form) { try { using (var context = new CatalogueContainer()) { var content = context.Content.First(c => c.Id == id); TryUpdateModel(content, new[] {"Title","DescriptionTitle","SeoDescription","SeoKeywords","SortOrder"}); content.Text = HttpUtility.HtmlDecode(form["Text"]); content.Description = HttpUtility.HtmlDecode(form["Description"]); context.SaveChanges(); if(content.MainPage) return RedirectToAction("Index", "Home", new { area = "", id = "" }); return RedirectToAction("Index", "Home", new {area="", id = content.Name}); } } catch { return View(); } }
public ActionResult AddImage(int projectId, IEnumerable<HttpPostedFileBase> fileUpload) { try { using (var context = new CatalogueContainer()) { var project = context.Project.First(p => p.Id == projectId); foreach (var file in fileUpload) { if (file != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); file.SaveAs(filePath); project.ProjectImages.Add(new ProjectImage { ImageSource = fileName }); context.SaveChanges(); } } return RedirectToAction("Index", "Projects", new { area = "", project = project.Name }); } } catch { return View(); } }
//public ActionResult Edit(int id) //{ // using (var context = new CatalogueContainer()) // { // var product = context.Product.Include("Brand").First(p => p.Id == id); // return View(product); // } //} //[HttpPost] //public ActionResult Edit(int id, FormCollection form, int brandId, int makerId, HttpPostedFileBase fileUpload) //{ // try // { // using (var context = new CatalogueContainer()) // { // var product = context.Product.Include("Brand").First(p => p.Id == id); // if (fileUpload != null) // { // if (!string.IsNullOrEmpty(product.ImageSource)) // { // IOHelper.DeleteFile("~/Content/Images", product.ImageSource); // foreach (var thumbnail in SiteSettings.Thumbnails) // { // IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, product.ImageSource); // } // } // string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName); // string filePath = Server.MapPath("~/Content/Images"); // filePath = Path.Combine(filePath, fileName); // fileUpload.SaveAs(filePath); // product.ImageSource = fileName; // } // context.SaveChanges(); // return RedirectToAction("Index", "Catalogue", new { Area = "", brand = product.Brand.Name }); // } // } // catch // { // return View(); // } //} public ActionResult Delete(int id, int? page, string filter) { using (var context = new CatalogueContainer()) { var product = context.Product.Include("Brand").First(p => p.Id == id); var brandId = product.Brand.Id; var brand = context.Brand.Include("Category").First(b => b.Id == brandId); var brandName = brand.Name; var categoryName = brand.Category.Name; ImageHelper.DeleteImage(product.ImageSource); context.DeleteObject(product); context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { Area = "", brand = brandName, category = categoryName, page = page, filter = filter }); } }
public ActionResult Delete(int id, string filter) { using (var context = new CatalogueContainer()) { var brand = context.Brand.Include("Category").First(b => b.Id == id); string categoryName = brand.Category.Name; brand.CategoryAttributes.Clear(); while (brand.Products.Any()) { var product = brand.Products.First(); ImageHelper.DeleteImage(product.ImageSource); context.DeleteObject(product); } context.DeleteObject(brand); context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { area = "", category = categoryName,filter=filter }); } }
public ActionResult DeleteImage(int id) { using (var context = new CatalogueContainer()) { var image = context.ProjectImage.Include("Project").First(pi => pi.Id == id); var projectName = image.Project.Name; ImageHelper.DeleteImage(image.ImageSource); context.DeleteObject(image); context.SaveChanges(); return RedirectToAction("Index", "Projects", new { area = "", project = projectName }); } }
public ActionResult Delete(int id) { using (var context = new CatalogueContainer()) { var attribute = context.CategoryAttribute.First(a => a.Id == id); attribute.Categories.Clear(); attribute.Brands.Clear(); context.DeleteObject(attribute); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Delete(int id) { try { using (var context = new CatalogueContainer()) { var category = context.Category.Include("Brands").Include("CategoryAttributes").First(c => c.Id == id); if (!category.Brands.Any()) { category.CategoryAttributes.Clear(); context.DeleteObject(category); context.SaveChanges(); } } } catch { } return RedirectToAction("Index"); }
public ActionResult Attributes(int categoryId ,FormCollection form) { using (var context = new CatalogueContainer()) { var category = context.Category.First(c => c.Id == categoryId); category.CategoryAttributes.Clear(); PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr"); foreach (var kvp in cbData) { var attrId = kvp.Key; bool attrValue = kvp.Value; if (attrValue) { var attribute = context.CategoryAttribute.First(c => c.Id == attrId); category.CategoryAttributes.Add(attribute); } } context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult DeleteImage(int id) { using (var context = new CatalogueContainer()) { var image = context.MainPageImage.First(i => i.Id == id); ImageHelper.DeleteImage(image.ImageSource); context.DeleteObject(image); context.SaveChanges(); return RedirectToAction("Index", "Content", new { area = "Admin",id="" }); } }
// // GET: /Admin/Project/Delete/5 public ActionResult Delete(int id) { using (var context = new CatalogueContainer()) { var project = context.Project.Include("ProjectImages").First(p => p.Id == id); while (project.ProjectImages.Any()) { var image = project.ProjectImages.First(); ImageHelper.DeleteImage(image.ImageSource); context.DeleteObject(image); } context.DeleteObject(project); context.SaveChanges(); } return RedirectToAction("Index", "Projects", new { Area = "" }); }