public static void DeleteProduct(CMSDatabase db, int?productID, HttpContext context, out bool successfullyDeleted) { if (!productID.HasValue) { successfullyDeleted = false; return; } ProductPage product = db.ProductPages.FirstOrDefault(pp => pp.ID == productID.Value); if (product == null) { successfullyDeleted = false; return; } IHostingEnvironment env = context.RequestServices.GetRequiredService <IHostingEnvironment>(); string pathToImages = $"{env.GetProductsImagesFolderFullPath()}{product.ID}/"; // Удаляем данные об изображениях из БД string[] images = ImagesManagementFunctions.GetProductImageUrls(product, env); for (int i = 0; i < images.Length; ++i) { Image image = db.Images.FirstOrDefault(img => img.ShortPathHash == OtherFunctions.GetHashFromString(images[i]) && img.ShortPath.Equals(images[i], StringComparison.Ordinal)); if (image != null) { db.Images.Remove(image); } } db.Entry(product).Reference(pp => pp.PreviousPage).Load(); --product.PreviousPage.ProductsCount; db.ProductPages.Remove(product); db.SaveChanges(); // Удаляем папку с изображениями товара if (Directory.Exists(pathToImages)) { Directory.Delete(pathToImages, true); } successfullyDeleted = true; LogManagementFunctions.AddAdminPanelLog( db: db, context: context, info: $"{product.PageName} (ID-{product.ID.ToString()}): {(context.Items["LogLocalization"] as IAdminPanelLogLocalization)?.ProductDeleted}" ); }
public IActionResult ProductImages(int?itemID) { HttpContext.Items["pageID"] = AdminPanelPages.ProductImages; if (!itemID.HasValue) { return(Redirect($"{HttpContext.Request.Path}?pageID={(int)AdminPanelPages.Categories}")); } ProductPage product = db.ProductPages.AsNoTracking().FirstOrDefault(pp => pp.ID == itemID); if (product == null) { return(Redirect($"{HttpContext.Request.Path}?pageID={(int)AdminPanelPages.Categories}")); } IHostingEnvironment env = HttpContext.RequestServices.GetService <IHostingEnvironment>(); string[] productImages = ImagesManagementFunctions.GetProductImageUrls(product, env); HttpContext.Items["ProductPage"] = product; return(View("CategoriesAndProducts/ProductImages", productImages)); }
public static void DeletePage(CMSDatabase db, PageType?pageType, int?itemID, HttpContext context, out bool successfullyDeleted) { if (!pageType.HasValue || !itemID.HasValue) { successfullyDeleted = false; return; } Page page = null; switch (pageType) { case PageType.Usual: page = db.UsualPages.FirstOrDefault(p => p.ID == itemID); break; case PageType.Category: page = db.CategoryPages.FirstOrDefault(p => p.ID == itemID); break; default: successfullyDeleted = false; return; } if (page == null) { successfullyDeleted = false; return; } if (page is UsualPage up) { // Получаем все зависимые страницы List <UsualPage> usualPages = db.UsualPages.Where(p => p.PreviousPageID == up.ID).ToList(); List <CategoryPage> categoryPages = db.CategoryPages.Where(p => p.PreviousPageID == up.ID).ToList(); db.UsualPages.Remove(up); db.SaveChanges(); // Обновляем полученные зависимые страницы foreach (var u_page in usualPages) { u_page.PreviousPageID = up.PreviousPageID; RefreshPageAndDependencies(db, u_page); } foreach (var c_page in categoryPages) { c_page.PreviousPageID = up.PreviousPageID; RefreshPageAndDependencies(db, c_page); } } else if (page is CategoryPage cp) { IHostingEnvironment env = context.RequestServices.GetRequiredService <IHostingEnvironment>(); cp.ProductPages = db.ProductPages.Where(pp => pp.PreviousPageID == cp.ID).ToList(); foreach (var p in cp.ProductPages) { string[] images = ImagesManagementFunctions.GetProductImageUrls(p, env); for (int i = 0; i < images.Length; ++i) { Image image = db.Images.FirstOrDefault(img => img.ShortPathHash == OtherFunctions.GetHashFromString(images[i]) && img.ShortPath.Equals(images[i], StringComparison.Ordinal)); if (image != null) { db.Images.Remove(image); } } string pathToImages = $"{env.GetProductsImagesFolderFullPath()}{p.ID}/"; if (Directory.Exists(pathToImages)) { Directory.Delete(pathToImages, true); } } db.Remove(page); } db.SaveChanges(); successfullyDeleted = true; LogManagementFunctions.AddAdminPanelLog( db: db, context: context, info: $"{page.PageName} (ID-{page.ID.ToString()}): " + (page is UsualPage ? (context.Items["LogLocalization"] as IAdminPanelLogLocalization)?.PageDeleted : (context.Items["LogLocalization"] as IAdminPanelLogLocalization)?.CategoryDeleted) ); }
#pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() { #line 2 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Dictionary <int, int> counters = new Dictionary <int, int>(); #line default #line hidden BeginContext(76, 58, true); WriteLiteral("<div class=\"content-block\">\n\t<div class=\"navigation-menu\">"); EndContext(); BeginContext(136, 72, false); #line 3 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Write(Model != null ? Html.Raw(Model.BreadcrumbsHtml) : Html.Raw(string.Empty)); #line default #line hidden EndContext(); BeginContext(209, 3, true); WriteLiteral(" → "); EndContext(); BeginContext(214, 65, false); #line 3 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Write(Model != null ? Html.Raw(Model.PageName) : Html.Raw(string.Empty)); #line default #line hidden EndContext(); BeginContext(280, 125, true); WriteLiteral("</div>\n\t<div class=\"container\">\n\t\t<div class=\"gallery\">\n\t\t\t<a class=\"selected-image-block\" data-lightbox=\"image\" data-title=\""); EndContext(); BeginContext(407, 65, false); #line 6 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Write(Model != null ? Html.Raw(Model.PageName) : Html.Raw(string.Empty)); #line default #line hidden EndContext(); BeginContext(473, 62, true); WriteLiteral("\"><img id=\"selected-image\"></a>\n\t\t\t<div id=\"image-container\">\n"); EndContext(); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" var env = Context.RequestServices.GetService(typeof(Microsoft.AspNetCore.Hosting.IHostingEnvironment)) as Microsoft.AspNetCore.Hosting.IHostingEnvironment; foreach (var imgUrl in ImagesManagementFunctions.GetProductImageUrls(Model as ProductPage, env, 0)) { #line default #line hidden BeginContext(806, 4, true); WriteLiteral("<div"); EndContext(); BeginWriteAttribute("id", " id=\"", 810, "\"", 908, 2); WriteAttributeValue("", 815, "image-", 815, 6, true); WriteAttributeValue("", 821, new Microsoft.AspNetCore.Mvc.Razor.HelperResult(async(__razor_attribute_value_writer) => { PushWriter(__razor_attribute_value_writer); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" if (!counters.ContainsKey(1)) { counters.Add(1, 0); } #line default #line hidden BeginContext(885, 13, false); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Write(++counters[1]); #line default #line hidden EndContext(); PopWriter(); } ), 821, 87, false); EndWriteAttribute(); BeginContext(909, 1, true); WriteLiteral(">"); EndContext(); BeginContext(910, 77, false); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("image", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "ae13e9542d7b38585970634c3d0f5cace5961edb8259", async() => { } ); __Treynessen_TagHelpers_ImageTagHelper = CreateTagHelper <global::Treynessen.TagHelpers.ImageTagHelper>(); __tagHelperExecutionContext.Add(__Treynessen_TagHelpers_ImageTagHelper); BeginWriteTagHelperAttribute(); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" WriteLiteral(imgUrl); #line default #line hidden __tagHelperStringValueBuffer = EndWriteTagHelperAttribute(); __Treynessen_TagHelpers_ImageTagHelper.Src = __tagHelperStringValueBuffer; __tagHelperExecutionContext.AddTagHelperAttribute("src", __Treynessen_TagHelpers_ImageTagHelper.Src, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" __Treynessen_TagHelpers_ImageTagHelper.MaxWidth = 350; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("max-width", __Treynessen_TagHelpers_ImageTagHelper.MaxWidth, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" __Treynessen_TagHelpers_ImageTagHelper.MaxHeight = 270; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("max-height", __Treynessen_TagHelpers_ImageTagHelper.MaxHeight, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" __Treynessen_TagHelpers_ImageTagHelper.Quality = 95; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("quality", __Treynessen_TagHelpers_ImageTagHelper.Quality, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); if (!__tagHelperExecutionContext.Output.IsContentModified) { await __tagHelperExecutionContext.SetOutputContentAsync(); } Write(__tagHelperExecutionContext.Output); __tagHelperExecutionContext = __tagHelperScopeManager.End(); EndContext(); BeginContext(987, 6, true); WriteLiteral("</div>"); EndContext(); #line 8 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" } #line default #line hidden BeginContext(1005, 79, true); WriteLiteral("\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"info-container\">\n\t\t\t<div class=\"product-name\">"); EndContext(); BeginContext(1086, 65, false); #line 12 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Write(Model != null ? Html.Raw(Model.PageName) : Html.Raw(string.Empty)); #line default #line hidden EndContext(); BeginContext(1152, 47, true); WriteLiteral("</div>\n\t\t\t<div class=\"price\"><span>Цена:</span>"); EndContext(); BeginContext(1201, 336, false); #line 13 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Write(Model is ProductPage && (Model as ProductPage).OldPrice != 0 ? Html.Raw("<span>" + OtherFunctions.PriceFormatting((Model as ProductPage).Price) + "</span><span>" + OtherFunctions.PriceFormatting((Model as ProductPage).OldPrice) + "</span>") : Html.Raw("<span>" + OtherFunctions.PriceFormatting((Model as ProductPage).Price) + "</span>")); #line default #line hidden EndContext(); BeginContext(1538, 411, true); WriteLiteral(@"</div> <div class=""offer"">Если найдете цену ниже, мы предложим более выгодные условия!</div> <div class=""info"">Приходите! У нас огромный ассортимент инструмента, есть другие модели!</div> <div class=""info"">Звоните ежедневно с 11:00 до 17:00 по телефону <a href=""tel:89082905999"">8 9082 905-999</a></div> </div> </div> <div class=""description""> <div class=""tab"">Описание</div> <div class=""text"">" ); EndContext(); BeginContext(1951, 64, false); #line 21 "C:\Users\79622\Desktop\Github\StoreCMS\StoreCMS\Views\Chunks\product_page_content.cshtml" Write(Model != null ? Html.Raw(Model.Content) : Html.Raw(string.Empty)); #line default #line hidden EndContext(); BeginContext(2016, 22, true); WriteLiteral("</div>\n\t</div>\n</div>\n"); EndContext(); }