public ActionResult Add(FormCollection form) { using (var context = new StructureContainer()) { var content = new Content { MainPage = false, IsGallery = false }; TryUpdateModel(content, new[] { "Name", "Title", "TitleEng", "PageTitle", "PageTitleEng", "SortOrder", "SeoDescription", "SeoKeywords" }); content.Text = HttpUtility.HtmlDecode(form["Text"]); content.TextEng = HttpUtility.HtmlDecode(form["TextEng"]); context.AddToContent(content); context.SaveChanges(); return RedirectToAction("Index", "Home", new { id = content.Name, area = "" }); } }
// // GET: /Catalogue/ public ActionResult Index(string category, string subCategory, int? filter) { using (var context = new StructureContainer()) { var model = new CatalogueViewModel(context, category, subCategory, filter); if (model.SubCategory == null && model.Category.Products.Count == 0 && model.Category.Children.Count > 0) { var child = model.Category.Children.First(); return RedirectToAction("Index", new { category = model.Category.Name, subCategory = child.Name }); } this.SetSeoContent(model); ViewBag.MainMenu = model.MainMenu; ViewBag.CategoryName = model.Category.Name; if (model.SubCategory != null) ViewBag.SubCategoryName = model.SubCategory.Name; ViewBag.CategoryName = model.Category.Name; ViewBag.Filter = model.CurrentFilterId; if (model.Content != null) ViewBag.ContentName = model.Content.Name; return View(model); } }
public ActionResult Edit(Content model, FormCollection form) { using (var context = new StructureContainer()) { var content = context.Content.First(c => c.Id == model.Id); TryUpdateModel(content, new[] { "Name", "Title", "TitleEng", "PageTitle", "PageTitleEng", "SortOrder", "SeoDescription", "SeoKeywords" }); content.Text = HttpUtility.HtmlDecode(form["Text"]); content.TextEng = HttpUtility.HtmlDecode(form["TextEng"]); context.SaveChanges(); return RedirectToAction("Index", "Home", new { id = content.Name, area = "" }); } }
// // GET: /Admin/ProductAttributes/ public ActionResult Index() { using (var context = new StructureContainer()) { var attributes = context.ProductAttribute.ToList(); return View(attributes); } }
public ActionResult Categories() { using (var context = new StructureContainer()) { var categories = context.Category.Where(c => c.CategoryId == null).ToList(); return PartialView("Categories", categories); } }
public ActionResult Edit(int id) { using (var context = new StructureContainer()) { var content = context.Content.First(c => c.Id == id); return View(content); } }
public ActionResult Edit(int id) { using (var context = new StructureContainer()) { var productAttribute = context.ProductAttribute.First(pa => pa.Id == id); return View(productAttribute); } }
public CatalogueViewModel(StructureContainer context, string categoryName, string subCategoryName, int? filter = null) : base(context, null) { var title = ""; var category = Context.Category .Include("Children") //.Include("ProductAttributes") .First(c => c.Name == categoryName); category.ProductAttributes.Load(); Category = category; var currentCategory = category; CurrentCategory = category; title += (SiteSettings.Language==Language.Ru? category.Title:category.TitleEng); if (!string.IsNullOrEmpty(subCategoryName)) { var subCategory = category.Children.First(c => c.Name == subCategoryName); subCategory.ProductAttributes.Load(); SubCategory = subCategory; currentCategory = subCategory; CurrentCategory = subCategory; title += (SiteSettings.Language==Language.Ru? subCategory.Title:subCategory.TitleEng); } SubcategoriesMenu = new Menu(); foreach (var c in category.Children) { SubcategoriesMenu.Add( new MenuItem { ContentId = c.Id, ContentName = c.Name, IsMainPage = false, Selected = c.Name == subCategoryName, SortOrder = c.SortOrder, Title = SiteSettings.Language==Language.Ru? c.Title:c.TitleEng }); } foreach (var m in MainMenu.Where(m => m.IsGalleryMenuItem)) { m.Selected = true; } CurrentFilterId = filter; //var productAttributes = Context.ProductAttribute.Where(p => !filter.HasValue || p.Id == filter); var products = Context.Product.Include("ProductAttributes").Where(p => p.CategoryId == currentCategory.Id).ToList(); Products = ApplyFilter(products, filter); Title += " - " + title; SeoDescription = currentCategory.SeoDescription; SeoKeywords = currentCategory.SeoKeywords; }
public ActionResult NotFound() { using (var context = new StructureContainer()) { SiteViewModel model = new SiteViewModel(context, null); ViewBag.MainMenu = model.MainMenu; return View(model); } }
public ActionResult Edit(ProductAttribute model, FormCollection form) { using (var context = new StructureContainer()) { var productAttribute = context.ProductAttribute.First(pa => pa.Id == model.Id); TryUpdateModel(productAttribute, new[] { "Title", "TitleEng" }); context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult Create(ProductAttribute model) { using (var context = new StructureContainer()) { var pa = new ProductAttribute(); TryUpdateModel(pa, new[] { "Title", "TitleEng" }); context.AddToProductAttribute(pa); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Index(string id) { using (var context = new StructureContainer()) { var model = new SiteViewModel(context, id ?? ""); this.SetSeoContent(model); ViewBag.MainMenu = model.MainMenu; ViewBag.isHomePage = model.IsHomePage; if (model.Content != null) ViewBag.ContentName = model.Content.Name; return View(model); } }
public ActionResult Create(FormCollection form, int categoryId, HttpPostedFileBase fileUpload) { using (var context = new StructureContainer()) { Product product = new Product(); Category category = context.Category.Include("Parent").First(c => c.Id == categoryId); product.Category = category; var attributes = context.ProductAttribute.ToList(); PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId"); foreach (var kvp in postData) { var attribute = attributes.First(a => a.Id == kvp.Key); if (kvp.Value) { if (!product.ProductAttributes.Contains(attribute)) product.ProductAttributes.Add(attribute); } else { if (product.ProductAttributes.Contains(attribute)) product.ProductAttributes.Remove(attribute); } } TryUpdateModel(product, new[] { "Title", "TitleEng", "Description", "DescriptionEng", "ShowOnMainPage","Discount","DiscountText" }); if (fileUpload != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload); product.ImageSource = fileName; } context.AddToProduct(product); context.SaveChanges(); return category.Parent != null ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name }) : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name }); } }
public ActionResult Add(FormCollection form) { using (var context = new StructureContainer()) { var category = new Category(); if (!string.IsNullOrEmpty(form["parentId"])) { int parentId = Convert.ToInt32(form["parentId"]); var parent = context.Category.First(c => c.Id == parentId); category.Parent = parent; } var attributes = context.ProductAttribute.ToList(); PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "parentId"); foreach (var kvp in postData) { var attribute = attributes.First(a => a.Id == kvp.Key); if (kvp.Value) { if (!category.ProductAttributes.Contains(attribute)) category.ProductAttributes.Add(attribute); } else { if (category.ProductAttributes.Contains(attribute)) category.ProductAttributes.Remove(attribute); } } TryUpdateModel(category, new[] { "Name", "Title", "TitleEng", "SortOrder" }); category.Text = HttpUtility.HtmlDecode(form["Text"]); category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]); context.AddToCategory(category); context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent != null ? category.Parent.Name : category.Name, subCategory = category.Parent != null ? category.Name : null }); } }
public ActionResult Delete(int id) { using (var context = new StructureContainer()) { var productAttribute = context.ProductAttribute .Include("Categories") .Include("Products") .First(pa => pa.Id == id); productAttribute.Products.Clear(); productAttribute.Categories.Clear(); context.DeleteObject(productAttribute); context.SaveChanges(); } return RedirectToAction("Index"); }
// // GET: /Admin/Category/ public ActionResult Add(int? id) { using (var context = new StructureContainer()) { var category = new Category { SortOrder = 0 }; var attributes = context.ProductAttribute.ToList(); ViewBag.Attributes = attributes; ViewData["parentId"] = id; if (id.HasValue) { var parent = context.Category.First(c => c.Id == id); category.Parent = parent; } return View(category); } }
public ActionResult Create(int id) { using (var context = new StructureContainer()) { var category = context.Category.Include("Parent").Include("ProductAttributes").First(c => c.Id == id); ViewBag.CategoryId = category.Id; ViewBag.Attributes = category.ProductAttributes; if (category.Parent != null) { ViewBag.CategoryName = category.Parent.Name; ViewBag.SubCategoryName = category.Name; } else { ViewBag.CategoryName = category.Name; } return View(); } }
public SiteViewModel(StructureContainer context, string contentName) { Title = SiteSettings.Language == Language.Ru ? "Ракурс" : "Rakurs"; Context = context; var contentList = Context.Content.ToList(); FetchMainMenuItems(contentList, contentName); Content content = null; if (!string.IsNullOrEmpty(contentName)) { content = contentList.FirstOrDefault(c => c.Name == contentName); if (content == null) { throw new HttpNotFoundException(); } IsHomePage = content.MainPage; } else if (contentName == "") { content = context.Content.FirstOrDefault(c => c.MainPage); IsHomePage = true; } if (IsHomePage) { GetGalleryFrameItems(); GetDiscountBlockItems(); } Content = content; if (content != null) { Title += " - " + (SiteSettings.Language==Language.Ru? content.PageTitle:content.PageTitleEng); SeoDescription = content.SeoDescription; SeoKeywords = content.SeoKeywords; } }
public ActionResult Delete(int id) { using (var context = new StructureContainer()) { var category = context.Category.Include("Children").Include("Products").First(c => c.Id == id); while (category.Products.Any()) { var product = category.Products.First(); if (!string.IsNullOrEmpty(product.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", product.ImageSource); IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource); product.ProductAttributes.Clear(); context.DeleteObject(product); } } context.SaveChanges(); while (category.Children.Any()) { int catId = category.Children.First().Id; var child = context.Category.Include("Products").Include("ProductAttributes").First(c => c.Id == catId); child.ProductAttributes.Load(); while (child.Products.Any()) { var product = child.Products.First(); if (!string.IsNullOrEmpty(product.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", product.ImageSource); IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource); product.ProductAttributes.Clear(); context.DeleteObject(product); context.SaveChanges(); } } child.Products.Clear(); child.ProductAttributes.Clear(); context.DeleteObject(child); context.SaveChanges(); } category.ProductAttributes.Load(); category.ProductAttributes.Clear(); context.DeleteObject(category); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { Area = "", id = "" }); }
public ActionResult Edit(int id) { using (var context = new StructureContainer()) { var category = context.Category.Include("Parent").Include("ProductAttributes").First(c => c.Id == id); var attributes = context.ProductAttribute.ToList(); ViewBag.Attributes = attributes; return View(category); } }
public ActionResult Delete(int id) { using (var context = new StructureContainer()) { var product = context.Product.Include("Category").First(p => p.Id == id); var categoryId = product.Category.Id; var category = context.Category.Include("Parent").First(c => c.Id == categoryId); if (!string.IsNullOrEmpty(product.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", product.ImageSource); IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource); } product.ProductAttributes.Clear(); context.DeleteObject(product); context.SaveChanges(); return category.Parent != null ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name }) : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name }); } }
public ActionResult Edit(int id) { using (var context = new StructureContainer()) { ViewBag.productId = id; var product = context.Product.Include("ProductAttributes").Include("Category").First(p => p.Id == id); var category = context.Category.Include("Parent").Include("ProductAttributes").First(c => c.Id == product.Category.Id); if (category.Parent != null) { ViewBag.CategoryName = category.Parent.Name; ViewBag.SubCategoryName = category.Name; } else { ViewBag.CategoryName = category.Name; } ViewBag.CategoryId = category.Id; ViewBag.Attributes = category.ProductAttributes; return View(product); } }
public ActionResult CreateMany(FormCollection form, int categoryId, IList<HttpPostedFileBase> fileUpload, IList<string> titleRU, IList<string> titleEN, IList<string> descriptionRU, IList<string> descriptionEN) { using (var context = new StructureContainer()) { Category category = context.Category.Include("Parent").First(c => c.Id == categoryId); var attributes = context.ProductAttribute.ToList(); PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId"); for (int i = 0; i < 10; i++) { if (fileUpload[i] != null) { Product product = new Product {Category = category}; string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload[i].FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload[i]); product.ImageSource = fileName; foreach (var kvp in postData) { var attribute = attributes.First(a => a.Id == kvp.Key); if (kvp.Value) { if (!product.ProductAttributes.Contains(attribute)) product.ProductAttributes.Add(attribute); } else { if (product.ProductAttributes.Contains(attribute)) product.ProductAttributes.Remove(attribute); } } product.Title = titleRU[i]; product.TitleEng = titleEN[i]; product.Description = descriptionRU[i]; product.DescriptionEng = descriptionEN[i]; context.AddToProduct(product); } } context.SaveChanges(); return category.Parent != null ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name }) : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name }); } }
public ActionResult Edit(Category model, FormCollection form) { using (var context = new StructureContainer()) { var category = context.Category.Include("Parent").First(c => c.Id == model.Id); TryUpdateModel(category, new[] { "Name", "Title", "TitleEng", "SortOrder" }); category.Text = HttpUtility.HtmlDecode(form["Text"]); category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]); var attributes = context.ProductAttribute.ToList(); PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "parentId"); foreach (var kvp in postData) { var attribute = attributes.First(a => a.Id == kvp.Key); if (kvp.Value) { if (!category.ProductAttributes.Contains(attribute)) category.ProductAttributes.Add(attribute); } else { if (category.ProductAttributes.Contains(attribute)) category.ProductAttributes.Remove(attribute); } } context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent != null ? category.Parent.Name : category.Name }); } }
public ActionResult Delete(int id) { using (var context = new StructureContainer()) { var content = context.Content.First(c => c.Id == id); context.DeleteObject(content); context.SaveChanges(); return RedirectToAction("Index", "Home", new {area = "", id = ""}); } }