public CatalogueViewModel(SiteContext context, string category, string product, int? page) : base(context, category == "" ? "" : null) { UpdateMainMenu(category, product); if(!string.IsNullOrEmpty(category)) { Category = context.Category.Include("Products").First(c => c.Name == category); PageTitle += " » " + Category.Title; SeoDescription = Category.SeoDescription; SeoKeywords = Category.SeoKeywords; Title = Category.Title; TitleToCategory = Category.TitleToCategory; TotalProductsCount = Category.Products.Count(); Products = ApplyPaging(Category.Products, page).ToList(); } if(!string.IsNullOrEmpty(product)) { Product = context.Product.Include("Category").Include("ProductItems").First(p => p.Name == product); SeoDescription = Product.SeoDescription; SeoKeywords = Product.SeoKeywords; PageTitle += " » " + Product.Title; Title = Product.Title; } }
public ActionResult Create(int categoryId, FormCollection form, HttpPostedFileBase fileUpload) { using (var context = new SiteContext()) { var category = context.Category.First(c => c.Id == categoryId); var product = new Product{SortOrder = 0}; TryUpdateModel(product, new[] { "Name","Date", "Title",/* "SortOrder",*/ "SeoDescription", "SeoKeywords" }); product.Description = HttpUtility.HtmlDecode(form["Description"]); product.Category = category; 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); fileUpload.SaveAs(filePath); product.ImageSource = fileName; } context.AddToProduct(product); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", category = category.Name, product = product.Name }); } }
public SiteViewModel(SiteContext context, string contentName) { PageTitle = "Студия Евгения Миллера"; var categories = context.Category; Menu = InitializeMainMenu(categories); if (!string.IsNullOrEmpty(contentName)) { Content = context.Content.First(c => c.Name == contentName); } else if (contentName == "") { Content = context.Content.First(c => c.HomePage); IsHomePage = true; } if(Content!=null) { PageTitle += " » " + Content.Title; SeoDescription = Content.SeoDescription; SeoKeywords = Content.SeoKeywords; Title = Content.Title; } if (contentName=="secretlink") { SecretImages = context.SecretImage.ToList(); } }
public ActionResult Edit(int id, FormCollection form, HttpPostedFileBase fileUpload) { using (var context = new SiteContext()) { var product = context.Product.Include("Category").First(p => p.Id == id); TryUpdateModel(product, new[] { "Name", "Date", "Title",/* "SortOrder",*/ "SeoDescription", "SeoKeywords" }); product.Description = HttpUtility.HtmlDecode(form["Description"]); if (fileUpload != null) { if (!string.IsNullOrEmpty(product.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", product.ImageSource); } string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload); fileUpload.SaveAs(filePath); product.ImageSource = fileName; } context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", category = product.Category.Name, product=product.Name }); } }
public ActionResult Edit(int id) { using (var context = new SiteContext()) { var content = context.Content.First(c => c.Id == id); return View(content); } }
public ActionResult Edit(int id) { using (var context = new SiteContext()) { var category = context.Category.First(c => c.Id == id); return View(category); } }
public ActionResult English() { using (var context = new SiteContext()) { var model = new SiteViewModel(context, null); ViewBag.PageTitle = model.PageTitle; ViewBag.isHomePage = false; return View(model); } }
public ActionResult Create(int id) { using (var context = new SiteContext()) { ViewBag.CategoryId = id; ViewBag.CategoryName = context.Category.First(c => c.Id == id).Name; //var max = context.Product.Max(p => p.SortOrder); return View(new Product {/*SortOrder = max + 1,*/Date = DateTime.Now}); } }
public ActionResult Create() { using (var context = new SiteContext()) { int max=0; if(context.Category.Any()) max = context.Category.Max(c => c.SortOrder); return View(new Category {SortOrder = max + 1}); } }
public ActionResult Edit(int id, FormCollection form) { using (var context = new SiteContext()) { var category = context.Category.First(c => c.Id == id); TryUpdateModel(category, new[] { "Name", "Title", "TitleToCategory", "SeoDescription", "SeoKeywords", "SortOrder" }); category.Description = HttpUtility.HtmlDecode(form["Description"]); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", category = category.Name }); } }
public ActionResult SiteContent(string id) { using (var context = new SiteContext()) { var model = new SiteViewModel(context, id); this.SetSeoContent(model); ViewBag.PageTitle = model.PageTitle; ViewBag.isHomePage = false; return View("Content", model); } }
public ActionResult Edit(int id) { using (var context = new SiteContext()) { var product = context.Product.Include("Category").First(p => p.Id == id); //TryUpdateModel(product, new[] { "Name", "Title", "Description", "SortOrder", "SeoDescription", "SeoKeywords" }); //context.SaveChanges(); return View(product); } }
public ActionResult Edit(int id, FormCollection form) { using (var context = new SiteContext()) { var content = context.Content.First(c => c.Id == id); TryUpdateModel(content, new[] {"Title", "SeoDescription", "SeoKeywords"}); content.Text = HttpUtility.HtmlDecode(form["Text"]); context.SaveChanges(); return RedirectToAction("Index","Home",new{area=""}); } }
public ActionResult Delete(int id) { using (var context = new SiteContext()) { var image = context.SecretImage.First(i => i.Id == id); ImageHelper.DeleteImage(image.ImageSource); ImageHelper.DeleteImage(image.PreviewImageSource); context.DeleteObject(image); context.SaveChanges(); return RedirectToAction("SiteContent", "Home", new { id = "secretlink", area = "" }); } }
public ActionResult Edit(int id) { using (var context = new SiteContext()) { var pi = context.ProductItem.Include("Product").First(p => p.Id == id); var productId = pi.Product.Id; var product = context.Product.Include("Category").First(p => p.Id == productId); ViewBag.ProductName = product.Name; ViewBag.CategoryName = product.Category.Name; return View(pi); } }
public ActionResult Delete(int id) { using (var context = new SiteContext()) { var category = context.Category.Include("Products").First(c => c.Id == id); if (!category.Products.Any()) { context.DeleteObject(category); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { area = "" }); } }
public ActionResult Create(int id) { using (var context = new SiteContext()) { ViewBag.ProductId = id; int max=0; if(context.ProductItem.Any()) max = context.ProductItem.Max(p => p.SortOrder); var product = context.Product.Include("Category").First(p => p.Id == id); ViewBag.ProductName = product.Name; ViewBag.CategoryName = product.Category.Name; return View(new ProductItem { SortOrder = max + 1 }); } }
public ActionResult Index(string category, string product, int? page) { using (var context = new SiteContext()) { var model = new CatalogueViewModel(context, category ?? "", product, page); ViewBag.Page = page ?? 0; this.SetSeoContent(model); ViewBag.PageTitle = model.PageTitle; ViewBag.isHomePage = model.IsHomePage; if (model.Content != null) { return View("Content", model); } if(model.Product!=null) { return View("Product", model); } return View(model); } }
public ActionResult Create(FormCollection collection, List<HttpPostedFileBase> mainImage, List<HttpPostedFileBase> previewImage) { try { using (var context = new SiteContext()) { int imagesCount = previewImage.Count(file => file != null); for (int i = 0; i < imagesCount; i++) { SecretImage si = new SecretImage(); string fileName = IOHelper.GetUniqueFileName("~/Content/Images", previewImage[i].FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); previewImage[i].SaveAs(filePath); si.PreviewImageSource = fileName; fileName = IOHelper.GetUniqueFileName("~/Content/Images", mainImage[i].FileName); filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); mainImage[i].SaveAs(filePath); si.ImageSource = fileName; context.AddToSecretImage(si); context.SaveChanges(); } return RedirectToAction("SiteContent", "Home", new { id = "secretlink", area = "" }); } } catch { return View(); } }
public ActionResult Delete(int id) { using (var context = new SiteContext()) { var product = context.Product.Include("Category").Include("ProductItems").First(c => c.Id == id); var categoryName = product.Category.Name; while (product.ProductItems.Any()) { var productItem = product.ProductItems.First(); ImageHelper.DeleteImage(productItem.ImageSource); context.DeleteObject(productItem); } ImageHelper.DeleteImage(product.ImageSource); context.DeleteObject(product); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", category = categoryName }); } }
public ActionResult Delete(int id) { using (var context = new SiteContext()) { var pi = context.ProductItem.Include("Product").First(p => p.Id == id); var productId = pi.Product.Id; var product = context.Product.Include("Category").First(p => p.Id == productId); ImageHelper.DeleteImage(pi.ImageSource); context.DeleteObject(pi); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", category = product.Category.Name, product = product.Name }); } }