public ActionResult Prices(FormCollection form) { using (var context = new ShopContainer()) { var products = context.Product.Include("Brand").Include("Category").ToList(); PostCheckboxesData cbDataNew = form.ProcessPostCheckboxesData("new"); PostCheckboxesData cbDataSpec = form.ProcessPostCheckboxesData("special"); PostCheckboxesData cbDataPublish = form.ProcessPostCheckboxesData("publish"); PostData oldPriceData = form.ProcessPostData("oldprice"); PostData priceData = form.ProcessPostData("price"); foreach (var kvp in cbDataNew) { var productId = kvp.Key; bool productValue = kvp.Value; products.First(p => p.Id == productId).IsNew = productValue; } foreach (var kvp in cbDataSpec) { var productId = kvp.Key; bool productValue = kvp.Value; products.First(p => p.Id == productId).IsSpecialOffer = productValue; } foreach (var kvp in cbDataPublish) { var productId = kvp.Key; bool productValue = kvp.Value; products.First(p => p.Id == productId).Published = productValue; } foreach (var kvp in oldPriceData) { int productId = Convert.ToInt32(kvp.Key); foreach (var value in kvp.Value) { var productValue = Convert.ToDecimal(value.Value); products.First(p => p.Id == productId).OldPrice = productValue; } } foreach (var kvp in priceData) { int productId = Convert.ToInt32(kvp.Key); foreach (var value in kvp.Value) { var productValue = Convert.ToDecimal(value.Value); products.First(p => p.Id == productId).Price = productValue; } } context.SaveChanges(); } return RedirectToAction("Prices"); }
public ActionResult Create(FormCollection form, HttpPostedFileBase uploadFile) { using (var context = new ModelContainer()) { int albumId = Convert.ToInt32(form["AlbumId"]); var album = context.Album.First(a => a.Id == albumId); PostCheckboxesData cbDataCategories = form.ProcessPostCheckboxesData("category"); PostCheckboxesData cbDataElements = form.ProcessPostCheckboxesData("element"); var product = new Product(); TryUpdateModel(product, new[] { "Title", "SortOrder" }); string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); uploadFile.SaveAs(filePath); product.ImageSource = fileName; foreach (var kvp in cbDataCategories) { var categoryId = kvp.Key; bool productValue = kvp.Value; if (productValue) { var category = context.Category.First(c => c.Id == categoryId); product.Categories.Add(category); } } foreach (var kvp in cbDataElements) { var elementId = kvp.Key; var elemrntValue = kvp.Value; if (elemrntValue) { var element = context.Element.First(e => e.Id == elementId); product.Elements.Add(element); } } album.Products.Add(product); context.SaveChanges(); return RedirectToAction("Index", "Albums", new { Area = "", id = album.Name }); } }
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 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 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 Create(FormCollection form) { using (var context = new SiteContainer()) { var category = new Category(); var attributes = context.ProductAttribute.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.ProductAttributes.Contains(attribute)) category.ProductAttributes.Add(attribute); } else { if (category.ProductAttributes.Contains(attribute)) category.ProductAttributes.Remove(attribute); } } TryUpdateModel(category, new[] { "Name", "Title", "SortOrder", "SeoDescription", "SeoKeywords" }); context.AddToCategory(category); context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name }); } }
public ActionResult Attributes(int categoryId, FormCollection form) { try { using (var context = new ShopContainer()) { var category = context.Category.Include("ProductAttributes").First(c => c.Id == categoryId); 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 (!category.ProductAttributes.Contains(attribute)) category.ProductAttributes.Add(attribute); } else { if (category.ProductAttributes.Contains(attribute)) category.ProductAttributes.Remove(attribute); } } context.SaveChanges(); return RedirectToAction("Index"); } } catch { return View(); } }
public ActionResult Attributes(int productId, FormCollection form, string page) { _repository.LangId = CurrentLangId; var product = _repository.GetProduct(productId); PostCheckboxesData attrData = form.ProcessPostCheckboxesData("attr", "productId"); PostData staticAttrData = form.ProcessPostData("tb", "productId"); product.ProductAttributeValues.Clear(); string searchCriteriaAttributes = ""; foreach (var kvp in attrData) { var attributeValueId = kvp.Key; bool attributeValue = kvp.Value; if (attributeValue) { var productAttributeValue = _repository.GetProductAttributeValue(attributeValueId); searchCriteriaAttributes += productAttributeValue.ProductAttributeId + "-" + attributeValueId + ";"; product.ProductAttributeValues.Add(productAttributeValue); } } foreach (var kvp in staticAttrData) { int attributeId = Convert.ToInt32(kvp.Key); foreach (var value in kvp.Value) { string attributeValue = value.Value; var productAttribute = _repository.GetProductAttribute(attributeId); //productAttribute.ProductAttributeStaticValues.Clear(); ProductAttributeStaticValue productAttributeValue = null; productAttributeValue = _repository.GetProductAttributeStaticValue(productAttribute.Id, product.Id); if (string.IsNullOrEmpty(attributeValue)) { if (productAttributeValue != null) _repository.DeleteProductAttributeStaticValue(productAttributeValue.Id); } else { if (productAttributeValue == null) { productAttributeValue = new ProductAttributeStaticValue { Title = attributeValue, ProductAttribute = productAttribute, ProductId = product.Id }; _repository.AddProductAttributeStaticValue(productAttributeValue); } else { productAttributeValue.Title = attributeValue; _repository.SaveProductAttributeStaticValue(productAttributeValue); } } } } product.SearchCriteriaAttributes = searchCriteriaAttributes; _repository.SaveProduct(product); return !string.IsNullOrEmpty(page) ? RedirectToAction("Index", new { page = page }) : RedirectToAction("Index"); }
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 Create(Product model, FormCollection form, HttpPostedFileBase photo) { try { var authors = _context.Authors.ToList(); var author = authors.First(a => a.Id == model.AuthorId); ViewBag.AuthorId = author.Id; ViewBag.Tags = _context.Tags.ToList(); ViewBag.Authors = authors; var product = new Product { Title = model.Title, TitleEn = model.TitleEn, TitleUa = model.TitleUa, Price = model.Price, SortOrder = model.SortOrder, Author = author }; if (photo != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images/product", photo.FileName); string filePath = Server.MapPath("~/Content/Images/product"); string filePathThumb = Server.MapPath("~/Content/Images/product/thumb"); string filePathOrigSize = Server.MapPath("~/Content/Images/product/orig"); filePath = Path.Combine(filePath, fileName); filePathThumb = Path.Combine(filePathThumb, fileName); filePathOrigSize = Path.Combine(filePathOrigSize, fileName); GraphicsHelper.SaveOriginalImage(filePathOrigSize, fileName, photo,2000); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, photo, 1440, 960, ScaleMode.Crop); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePathThumb, fileName, photo, 324, 324, ScaleMode.Crop); product.ImageSrc = fileName; } PostCheckboxesData attrData = form.ProcessPostCheckboxesData("tag"); foreach (var kvp in attrData) { var tagId = kvp.Key; bool tagValue = kvp.Value; //author.Tags.Clear(); if (tagValue) { var tag = _context.Tags.First(t => t.Id == tagId); product.Tags.Add(tag); } } _context.Products.Add(product); _context.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { TempData["errorMessage"] = ex.GetEntityValidationException(); if (string.IsNullOrEmpty((string)TempData["errorMessage"])) { TempData["errorMessage"] = ex.Message; } return View(model); } }
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 Create(Event model, IEnumerable<HttpPostedFileBase> files, IEnumerable<HttpPostedFileBase> filesAnother, FormCollection form) { try { var ev = new Event { Title = model.Title, TitleEn = model.TitleEn, TitleUa = model.TitleUa, TitleDescription = model.TitleDescription, TitleDescriptionEn = model.TitleDescriptionEn, TitleDescriptionUa = model.TitleDescriptionUa, Date = model.Date, HighlightedText = model.HighlightedText, HighlightedTextEn = model.HighlightedTextEn, HighlightedTextUa = model.HighlightedTextUa, LocationAddress = model.LocationAddress, LocationAddressEn = model.LocationAddressEn, LocationAddressUa = model.LocationAddressUa, LocationAddressMapUrl = model.LocationAddressMapUrl, LocationTitle = model.LocationTitle, LocationTitleEn = model.LocationTitleEn, LocationTitleUa = model.LocationTitleUa, TicketOrderType = model.TicketOrderType, PreviewContentType = model.PreviewContentType, ArtGroup = model.ArtGroup, ArtGroupEn = model.ArtGroupEn, ArtGroupUa = model.ArtGroupUa, Action = model.Action, ActionEn = model.ActionEn, ActionUa = model.ActionUa, Location = model.Location, LocationEn = model.LocationEn, LocationUa = model.LocationUa, Duration = model.Duration, Description = model.Description, DescriptionEn = model.DescriptionEn, DescriptionUa = model.DescriptionUa, IntervalQuantity = model.IntervalQuantity, PreviewContentVideoSrc = model.PreviewContentVideoSrc, Price = model.Price }; ev.IsHighlighted = !string.IsNullOrEmpty(ev.HighlightedText); foreach (var file in files) { if (file == null) continue; string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); // h: 283 // w: 400 GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 400, 283, ScaleMode.Crop); var ci = new ContentImage { ImageSrc = fileName }; ev.ContentImages.Add(ci); } foreach (var file in filesAnother) { if (file == null) continue; string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 788, 500, ScaleMode.Crop); var ci = new PreviewContentImage { ImageSrc = fileName }; ev.PreviewContentImages.Add(ci); } PostCheckboxesData attrData = form.ProcessPostCheckboxesData("author"); foreach (var kvp in attrData) { var tagId = kvp.Key; bool tagValue = kvp.Value; //author.Tags.Clear(); if (tagValue) { var author = _context.Authors.First(t => t.Id == tagId); ev.Authors.Add(author); } } _context.Events.Add(ev); _context.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Tags(int productId, FormCollection form) { using (var context = new ShopContainer()) { var product = context.Product.First(p => p.Id == productId); PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId"); product.Tags.Clear(); foreach (KeyValuePair<int, bool> kvp in cbData) { if (kvp.Value) { var tagId = kvp.Key; var tag = context.Tag.First(t => t.Id == tagId); product.Tags.Add(tag); } } context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult Attributes(int productId, FormCollection form) { using (var context = new ShopContainer()) { var product = context.Product.Include("ProductAttributeValues").First(p => p.Id == productId); PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId"); PostData staticAttrData = form.ProcessPostData("tb", "productId"); product.ProductAttributeValues.Clear(); foreach (var kvp in cbData) { var attributeValueId = kvp.Key; bool attributeValue = kvp.Value; if (attributeValue) { var productAttributeValue = context.ProductAttributeValues.First(pv => pv.Id == attributeValueId); product.ProductAttributeValues.Add(productAttributeValue); } } foreach (var kvp in staticAttrData) { int attributeId = Convert.ToInt32(kvp.Key); foreach (var value in kvp.Value) { string attributeValue = value.Value; var productAttribute = context.ProductAttribute.Include("ProductAttributeStaticValues").First(pa => pa.Id == attributeId); //productAttribute.ProductAttributeStaticValues.Clear(); ProductAttributeStaticValues productAttributeValue = null; productAttributeValue = context.ProductAttributeStaticValues.FirstOrDefault( pav => pav.ProductAttribute.Id == productAttribute.Id && pav.Product.Id == product.Id); if (string.IsNullOrEmpty(attributeValue)) { if (productAttributeValue != null) context.DeleteObject(productAttributeValue); } else { if (productAttributeValue == null) { productAttributeValue = new ProductAttributeStaticValues { Value = attributeValue, ProductAttribute = productAttribute }; product.ProductAttributeStaticValues.Add(productAttributeValue); } else { productAttributeValue.Value = attributeValue; } } //productAttribute.ProductAttributeValues.Add(productAttributeValue); } } context.SaveChanges(); 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 Create(Author model, HttpPostedFileBase photo, HttpPostedFileBase avatar, FormCollection form) { try { ViewBag.Tags = _context.Tags.ToList(); var author = new Author { Name = model.Name, }; author.Title = model.Title == null ? "" : HttpUtility.HtmlDecode(model.Title); author.TitleEn = model.TitleEn == null ? "" : HttpUtility.HtmlDecode(model.TitleEn); author.TitleUa = model.TitleUa == null ? "" : HttpUtility.HtmlDecode(model.TitleUa); author.Description = model.Description == null ? "" : HttpUtility.HtmlDecode(model.Description); author.DescriptionEn = model.DescriptionEn == null ? "" : HttpUtility.HtmlDecode(model.DescriptionEn); author.DescriptionUa = model.DescriptionUa == null ? "" : HttpUtility.HtmlDecode(model.DescriptionUa); author.About = model.About == null ? "" : HttpUtility.HtmlDecode(model.About); author.AboutEn = model.AboutEn == null ? "" : HttpUtility.HtmlDecode(model.AboutEn); author.AboutUa = model.AboutUa == null ? "" : HttpUtility.HtmlDecode(model.AboutUa); if (photo != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images/author", photo.FileName); string filePath = Server.MapPath("~/Content/Images/author"); string filePathThumb = Server.MapPath("~/Content/Images/author/thumb"); filePath = Path.Combine(filePath, fileName); filePathThumb = Path.Combine(filePathThumb, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, photo, 670); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, photo, 670, 670, ScaleMode.Crop); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePathThumb, fileName, photo, 324, 324, ScaleMode.Crop); author.Photo = fileName; } if (avatar != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images/author", avatar.FileName); string filePath = Server.MapPath("~/Content/Images/author"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, photo, 670); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, avatar, 150, 150, ScaleMode.Crop); author.Avatar = fileName; } PostCheckboxesData attrData = form.ProcessPostCheckboxesData("tag"); foreach (var kvp in attrData) { var tagId = kvp.Key; bool tagValue = kvp.Value; //author.Tags.Clear(); if (tagValue) { var tag = _context.Tags.First(t => t.Id == tagId); author.Tags.Add(tag); } } _context.Authors.Add(author); _context.SaveChanges(); return RedirectToAction("Index"); } catch(Exception ex) { TempData["errorMessage"] = ex.GetEntityValidationException(); if (string.IsNullOrEmpty((string)TempData["errorMessage"])) { TempData["errorMessage"] = ex.Message; } return View(model); } }
public ActionResult Edit(int id, IEnumerable<HttpPostedFileBase> files, IEnumerable<HttpPostedFileBase> filesAnother, FormCollection form) { try { var ev = _context.Events.First(e => e.Id == id); TryUpdateModel(ev, new[] { "Title", "TitleEn", "TitleUa", "TitleDescription", "TitleDescriptionEn", "TitleDescriptionUa", "Date", "HighlightedText", "HighlightedTextEn", "HighlightedTextUa", "LocationAddress", "LocationAddressEn", "LocationAddressUa", "HighlightedText", "HighlightedTextEn", "HighlightedTextUa", "LocationAddress", "LocationAddressEn", "LocationAddressUa", "LocationAddressMapUrl", "LocationTitle", "LocationTitleEn", "LocationTitleUa", "TicketOrderType", "PreviewContentType", "ArtGroup", "ArtGroupEn", "ArtGroupUa", "Action", "ActionEn", "ActionUa", "Location", "LocationEn", "LocationUa", "Duration", "Description", "DescriptionEn", "DescriptionUa", "IntervalQuantity", "PreviewContentVideoSrc", "Price" }); ev.IsHighlighted = !string.IsNullOrEmpty(ev.HighlightedText); foreach (var file in files) { if (file == null) continue; string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 400, 283,ScaleMode.Crop); var ci = new ContentImage { ImageSrc = fileName }; ev.ContentImages.Add(ci); } foreach (var file in filesAnother) { if (file == null) continue; string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500); GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 788, 500, ScaleMode.Crop); var ci = new PreviewContentImage { ImageSrc = fileName }; ev.PreviewContentImages.Add(ci); } PostCheckboxesData attrData = form.ProcessPostCheckboxesData("author"); ev.Authors.Clear(); foreach (var kvp in attrData) { var tagId = kvp.Key; bool tagValue = kvp.Value; //author.Tags.Clear(); if (tagValue) { var author = _context.Authors.First(t => t.Id == tagId); ev.Authors.Add(author); } } _context.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Details(FormCollection form, int categoryId) { try { var category = _context.Categories.First(c => c.Id == categoryId); PostCheckboxesData attrData = form.ProcessPostCheckboxesData("category", "categoryId"); foreach (var kvp in attrData) { var tagId = kvp.Key; bool tagValue = kvp.Value; var ac = _context.AuthorCategories.First(t => t.Id == tagId); if (tagValue) { if (!category.AuthorCategories.Contains(ac)) category.AuthorCategories.Add(ac); } else { if (category.AuthorCategories.Contains(ac)) { category.AuthorCategories.Remove(ac); } } } PostCheckboxesData tagData = form.ProcessPostCheckboxesData("tag", "categoryId"); foreach (var kvp in tagData) { var tagId = kvp.Key; bool tagValue = kvp.Value; var tag = _context.Tags.First(t => t.Id == tagId); if (tagValue) { if (!category.Tags.Contains(tag)) category.Tags.Add(tag); } else { if (category.Tags.Contains(tag)) { category.Tags.Remove(tag); } } } _context.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { TempData["errorMessage"] = ex.GetEntityValidationException(); if (string.IsNullOrEmpty((string)TempData["errorMessage"])) { TempData["errorMessage"] = ex.Message; } return RedirectToAction("Index"); } }
public ActionResult Edit(FormCollection form, int id, HttpPostedFileBase fileUpload) { using (var context = new SiteContainer()) { var product = context.Product.Include("ProductAttributes").Include("Category").First(p => p.Id == id); var category = context.Category.First(c => c.Id == product.Category.Id); 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", "Description"}); if (fileUpload != null) { if (!string.IsNullOrEmpty(product.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", product.ImageSource); IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", 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", "Catalogue", new { Area = "", id = category.Name }); } }
public ActionResult Attributes(int categoryId, FormCollection form) { _repository.LangId = CurrentLangId; var category = _repository.GetCategory(categoryId); var attributes = _repository.GetProductAttributes().ToList(); foreach (var productAttribute in attributes) { productAttribute.CurrentLang = CurrentLangId; foreach (var value in productAttribute.ProductAttributeValues) { value.CurrentLang = CurrentLangId; } } PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId"); 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); } } _repository.SaveCategory(category); return RedirectToAction("Index"); }