private void CreateChildsDefaultContent(long content_root) { bool content_in_sitemap = false; bool content_export_rss = false; bool content_active = true; bool content_main = false; bool content_allow_deleted = true; bool content_allow_redirect = false; bool content_redirect_permanent = false; using (ContentRepository content_repository = new ContentRepository()) { using (TemplateRepository template_repository = new TemplateRepository()) { var current_content = content_repository.GetByID(content_root); var current_template = template_repository.GetByID(current_content.content_template); var child_templates = template_repository.GetByIDs(current_template.template_templates); foreach (var child_template in child_templates) { string content_url = child_template.template_friendly_name; long content_id = content_repository.CreateGlobalID(); string parent_url = current_content.content_url; string new_url = parent_url + "/" + Transliterator.Translite(content_url.Substring(0, (content_url.Length > 100 ? 100 : content_url.Length))); if (content_repository.Exists(new_url, CurrentUser.domain_id)) { new_url = new_url + "-" + content_id.ToString(); } bool content_publish; string user_data = GetUserData(child_template.template_fields, out content_publish); long?template_view = null; if (child_template.template_views != null) { string[] view_ids = child_template.template_views.Split(new char[] { ',' }); if (view_ids.Length > 0) { template_view = Int64.Parse(view_ids[0]); } } content_repository.Create(content_id, content_in_sitemap, content_export_rss, content_active, content_main, content_allow_deleted, child_template.template_friendly_name, template_view, new_url, current_content.content_block, child_template.template_friendly_name, null, null, child_template.template_friendly_name, child_template.template_friendly_name, null, null, content_publish ? (DateTime?)DateTime.Now.Date : (DateTime?)null, content_root, child_template.template_id, content_allow_redirect, content_redirect_permanent, null, child_template.template_friendly_name, null, null, CurrentUser.domain_id, user_data); } } } }
public void Create_Increases_Count_of_Content() { var startCount = db.Contents.Count(); underTest.Create(new Content() { Title = "new content", Author = "new Content", Body = "new Content", TeamId = 1 }); var endCount = db.Contents.Count(); Assert.Equal(startCount + 1, endCount); }
public void Create_Increases_Count_of_Contents() { var startCount = db.Contents.Count(); underTest.Create(new Content() { Title = "new blog entry", Body = "new blog body", Author = "author", PublishDate = DateTime.Now, GenreId = 1 }); var endCount = db.Contents.Count(); Assert.Equal(startCount + 1, endCount); }
public ActionResult Checkout(string name, string phone, string email, string address, string delivery_type, string region, string pd, string payment_type) { if (delivery_type == "Почта России") { region = string.Empty; pd = string.Empty; } IcbcodeCart shopping_cart = new IcbcodeCart(HttpContext); var edinici_izmereniya = IcbcodeContent.Get(new long[] { 33455 }); var proizvoditeli = IcbcodeContent.Get(new long[] { 33454 }); Dictionary <string, string> data = null; if (shopping_cart.Items.Count > 0) { StringBuilder body = new StringBuilder(); body.AppendFormat("Имя: {0}", name); body.AppendLine("<br/>"); body.AppendFormat("Телефон: {0}", phone); body.AppendLine("<br/>"); body.AppendFormat("Email: {0}", email); body.AppendLine("<br/>"); body.AppendFormat("Способ доставки: {0}", delivery_type); body.AppendLine("<br/>"); body.AppendFormat("Город / населенный пункт (IML): {0}", region); body.AppendLine("<br/>"); body.AppendFormat("Код ПД (IML): {0}", pd); body.AppendLine("<br/>"); body.AppendFormat("Адрес доставки: {0}", address); body.AppendLine("<br/>"); body.AppendLine("<br/>"); body.AppendLine("<table style=\"border: 1px solid black;\" cellpadding=\"5\" cellspacing=\"5\">"); body.AppendLine("<tr><td>Наименование</td><td>Производитель</td><td>Арт.</td><td>Цена</td><td>Ко-во</td><td>Итого</td></tr>"); decimal price = 0; foreach (var item in shopping_cart.Items) { price += item.item_price * item.item_count; var product = IcbcodeContent.Get(item.item_id); var unit = edinici_izmereniya.Find(x => x.ID == product.UserDefined.edinica_izmereniya).Name; var manufacturer = proizvoditeli.Find(x => x.ID == product.UserDefined.proizvoditelj).Name; body.AppendLine(string.Format("<tr><td><a href=\"{0}\">{1}</a><td>{6}</td><td>{5}</td></td><td>{2}</td><td>{3}</td><td>{4}</td></tr>", string.Format("{0}/{1}", Request.Url.Host, item.item_url), item.item_name, item.item_price, item.item_count, item.item_price * item.item_count, product.UserDefined.artikul, manufacturer)); } decimal delivery_price = 0; price += delivery_price; body.AppendLine($"<tr><td>Доставка: {delivery_type}<td></td><td></td></td><td>{delivery_price}</td><td>1</td><td>{delivery_price}</td></tr>"); body.AppendLine(string.Format("<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td>{0}</td></tr>", price)); body.AppendLine("</table>"); long order_id; using (ContentRepository content = new ContentRepository()) { order_id = content.CreateGlobalID(); string order_url = "/" + order_id.ToString(); content.Create(order_id, null, string.Format("Заказ #{0}", order_id), 33542, order_url, 33543, null, string.Format("fio = '{0}', adres_dostavki = '{1}', telefon = '{2}', email = '{3}', sposob_oplati = '{4}', oplachen = false, summa_rub = {5}, content_publish = now(), sposob_dostavki = '{6}', gorod_naselennij_punkt_iml = '{7}', kod_pd_iml = '{8}'", name, address, phone, email, payment_type, price.ToString("0.00", CultureInfo.InvariantCulture), delivery_type, region, pd), 15984); foreach (var item in shopping_cart.Items) { var product = IcbcodeContent.Get(item.item_id); var position_id = content.CreateGlobalID(); content.Create(position_id, null, item.item_name, 33535, order_url + "/" + position_id.ToString(), 33543, order_id, string.Format("cena_rub = {0}, kolichestvo = {1}, artikul = '{2}', edinica_izmereniya = {3}, proizvoditelj = {4}", item.item_price.ToString("0.00", CultureInfo.InvariantCulture), item.item_count, product.UserDefined.artikul, product.UserDefined.edinica_izmereniya, product.UserDefined.proizvoditelj), 15984); } } data = new Dictionary <string, string>() { { "amount", price.ToString("0.00", CultureInfo.InvariantCulture) }, { "description", $"Заказ №{order_id}" }, { "merchant", "cfde6441-4fb3-46f5-b085-48beacb1beaf" }, { "order_id", order_id.ToString() }, { "testing", "0" }, { "unix_timestamp", ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString() }, { "callback_url", "https://lemil.ru/utility/check-payment" }, { "cancel_url", "https://lemil.ru/k-sozhaleniyu-vi-otmenili-oplatu" }, { "success_url", $"https://lemil.ru/spasibo-vash-zakaz-oplachen" }, { "fail_url", "https://lemil.ru/platezh-zavershilsya-s-oshibkoj" } }; data.Add("signature", IcbcodeCMS.Areas.CMS.Utilities.SignatureHelper.GetSignature("CCF34CBC5A8A479A1DF6FF86AC6B2C43", data)); IcbcodeUtility.SendEmail(null, null, string.Format($"Заказ #{order_id} с сайта lemil.ru"), body.ToString()); shopping_cart.EmptyCart(); } return(View("Pay", data)); }
public ActionResult Clone(long?domain_id) { Dictionary <long, long> views = new Dictionary <long, long>(); Dictionary <long, long> templates = new Dictionary <long, long>(); Dictionary <long, long> blocks = new Dictionary <long, long>(); Dictionary <long, long> contents = new Dictionary <long, long>(); if (domain_id.HasValue) { using (DomainRepository domain_repository = new DomainRepository()) { var source_domain = domain_repository.GetByID(domain_id.Value); // create domain long new_domain_id = domain_repository.CreateGlobalID(); domain_repository.Create(new_domain_id, string.Format("new-{0}", new_domain_id), string.Empty); // end create domain // create views using (ViewRepository view_repository = new ViewRepository()) { foreach (var view in view_repository.All(source_domain.domain_id)) { long new_view_id = view_repository.CreateGlobalID(); view_repository.Create(new_view_id, view.view_friendly_name, view.view_name, view.view_path, new_domain_id, view.view_order); views.Add(view.view_id, new_view_id); } } // end create views // create templates using (TemplateRepository template_repository = new TemplateRepository()) { foreach (var template in template_repository.All(source_domain.domain_id)) { long new_template_id = template_repository.CreateGlobalID(); string template_views = string.Empty; foreach (var template_view_id in ((string)template.template_views ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { template_views += string.Format("{0},", views[Int64.Parse(template_view_id)]); } template_repository.Create(new_template_id, template.template_friendly_name, template.template_name, template.template_allow_subpartitions, template.template_fields, template_views.Trim(','), template.template_templates, template.template_allow_sort, template.template_order_fields, template.template_create_child, new_domain_id, template.template_order); templates.Add(template.template_id, new_template_id); } foreach (var template in template_repository.All(new_domain_id)) { string template_templates = string.Empty; foreach (var template_template_id in ((string)template.template_templates ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { template_templates += string.Format("{0},", templates[Int64.Parse(template_template_id)]); } template_repository.UpdateRefsTemplates(template.template_id, template_templates.Trim(',')); } } // end create templates // create variables using (VariableRepository variable_repository = new VariableRepository()) { foreach (var variable in variable_repository.All(source_domain.domain_id)) { long new_variable_id = variable_repository.CreateGlobalID(); variable_repository.Create(new_variable_id, variable.var_name, variable.var_friendly_name, variable.var_value, variable.var_type, variable.var_comment, variable.var_group, new_domain_id); } } // end create variables // create blocks using (BlockRepository block_repository = new BlockRepository()) { foreach (var block in block_repository.All(source_domain.domain_id)) { long new_block_id = block_repository.CreateGlobalID(); string block_templates = string.Empty; foreach (var block_template_id in ((string)block.block_templates ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { block_templates += string.Format("{0},", templates[Int64.Parse(block_template_id)]); } block_repository.Create(new_block_id, block.block_name, block.block_friendly_name, block_templates.Trim(','), block.block_content_root, block.block_area, block.block_controller, block.block_action, block.block_allow_sort, block.block_order_fields, block.block_separated, new_domain_id, block.block_order); blocks.Add(block.block_id, new_block_id); } } // end create blocks // create contents using (ContentRepository content_repository = new ContentRepository()) { foreach (var content in content_repository.GetByDomain(source_domain.domain_id)) { // build user data string user_data = string.Empty; using (FieldRepository field_repository = new FieldRepository()) { List <dynamic> fields = field_repository.GetByIDs(content.template_fields); foreach (var item in fields) { if (item.field_group != "Пользовательские") { continue; } var value = ((IDictionary <string, object>)content)[item.field_name]; if (value != null) { switch ((string)item.field_type) { case "string": case "html": value = string.Format("'{0}'", MySql.Data.MySqlClient.MySqlHelper.EscapeString(value)); break; case "boolean": break; case "list": break; case "date": value = string.Format("'{0}'", value.ToString("yyyy-MM-dd")); break; case "decimal": value = value.ToString().Replace(",", "."); break; default: value = value == null ? null : string.Format("'{0}'", value); break; } } user_data += string.Format(",{0} = {1}", item.field_name, (value == null ? "NULL" : value)); } } // end build user data long new_content_id = content_repository.CreateGlobalID(); content_repository.Create(new_content_id, content.content_in_sitemap, content.content_export_rss, content.content_active, content.content_main, content.content_allow_deleted, content.content_name, (content.content_view == null ? null : views[content.content_view]), content.content_url, blocks[content.content_block], content.content_title, content.content_description, content.content_keywords, content.content_h1, content.content_h2, content.content_short_text, content.content_text, content.content_publish, content.content_root, templates[content.content_template], content.content_allow_redirect, content.content_redirect_permanent, content.content_redirect_url, content.content_link, content.content_export_rss_ids, content.content_export_rss_title, new_domain_id, user_data, content.content_order); contents.Add(content.content_id, new_content_id); } foreach (var content in content_repository.GetByDomain(new_domain_id)) { string user_data = string.Empty; using (FieldRepository field_repository = new FieldRepository()) { List <dynamic> fields = field_repository.GetByIDs(content.template_fields); foreach (var item in fields) { if (item.field_group == "Пользовательские") { var value = ((IDictionary <string, object>)content)[item.field_name]; if (value != null) { if (item.field_type == "list") { value = contents.ContainsKey(value) ? contents[value] : value; } else if (item.field_type == "multiplelist") { string values = string.Empty; foreach (var id in (value ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { values += string.Format("{0},", contents.ContainsKey(Int64.Parse(id)) ? contents[Int64.Parse(id)] : Int64.Parse(id)); } value = string.Format("'{0}'", values).Trim(','); } else { continue; } } user_data += string.Format(",{0} = {1}", item.field_name, value ?? "NULL"); } } } content_repository.UpdateRefsRoot(content.content_id, content.content_root == null ? null : contents.ContainsKey(content.content_root) ? contents[content.content_root] : content.content_root, user_data); } } // end create contents // start blocks refs content_root update using (BlockRepository block_repository = new BlockRepository()) { foreach (var block in block_repository.All(new_domain_id)) { if (block.block_content_root == null) { continue; } block_repository.UpdateRefsRoot(block.block_id, contents[block.block_content_root]); } } // end blocks refs content_root update // create files using (FileRepository file_repository = new FileRepository()) { foreach (var file in file_repository.All(source_domain.domain_id)) { if (file.file_ref == null) { continue; } var new_file_id = file_repository.CreateGlobalID(); file_repository.Save(new_file_id, file.file_extension, contents[file.file_ref].ToString(), file.file_desc, (int)file.file_size, file.file_field, (DateTime)file.file_publish, (int)file.file_order, contents[file.file_ref]); try { System.IO.File.Copy( Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", file.file_id, file.file_extension)), Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", new_file_id, file.file_extension)) ); } catch { using (FileRepository database = new FileRepository()) { database.Remove(new_file_id); } } } } // end create files // create images using (ImageRepository image_repository = new ImageRepository()) { foreach (var image in image_repository.All(source_domain.domain_id)) { if (image.image_ref == null) { continue; } var new_image_id = image_repository.CreateGlobalID(); image_repository.Save(new_image_id, image.image_extension, contents[image.image_ref].ToString(), image.image_field, image.image_desc, (int)image.image_order, contents[image.image_ref]); try { System.IO.File.Copy( Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", image.image_id, image.image_extension)), Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", new_image_id, image.image_extension)) ); } catch { using (FileRepository database = new FileRepository()) { database.Remove(new_image_id); } } } } // end create images } } return(RedirectToAction("Index")); }
public static string Do() { var catalog = GetCatalog("http://mikkimama.ru/marketplace/44666.xml"); var partitions = IcbcodeContent.Get(new string[] { "katalog" }, new string[] { "razdel-kataloga" }); var products = IcbcodeContent.Get(new string[] { "katalog" }, new string[] { "poziciya" }); var oldProducts = IcbcodeContent.Get(new string[] { "katalog" }, new string[] { "poziciya" }); List <string> newPartitions = new List <string>(); List <string> newProducts = new List <string>(); List <string> noNames = new List <string>(); using (WebClient web = new WebClient()) { using (ContentRepository content = new ContentRepository()) using (ImageRepository image = new ImageRepository()) { foreach (var offer in catalog.Shop.Offers.Offer) { var partition = partitions.Find(x => x.UserDefined.vneshnij_id != null && x.UserDefined.vneshnij_id.ToString() == offer.CategoryId); if (partition == null) { newPartitions.Add(offer.CategoryId); } else { oldProducts.RemoveAll(x => (long)x.UserDefined.vneshnij_id == Convert.ToInt64(offer.Id)); var product = products.Find(x => x.UserDefined.vneshnij_id != null && (long)x.UserDefined.vneshnij_id == Convert.ToInt64(offer.Id)); if (product == null) { var product_id = content.CreateGlobalID(); if (string.IsNullOrWhiteSpace(offer.Name)) { offer.Name = offer.Url; noNames.Add($"{partition.Url}/{product_id}"); } content.Create(product_id, 16512, offer.Name, 16515, $"{partition.Url}/{product_id}", 33436, partition.ID, $"proizvoditelj = 33457, edinica_izmereniya = 33456, cena_rub = {offer.Price}, artikul = '{offer.VendorCode}', vneshnij_id = {offer.Id}", 15984); newProducts.Add($"{partition.Url}/{product_id}"); foreach (var pic in offer.Picture) { var image_id = image.CreateGlobalID(); string extension = Path.GetExtension(pic); string savePath = Path.Combine(HostingEnvironment.MapPath("~/content/cms/files"), image_id.ToString() + extension); web.DownloadFile(pic, savePath); image.Save(image_id, extension, product_id.ToString(), null, "", 100000, product_id); } } else { // обновляем только цену, удаляем и загружаем заново картинки content.Update($"cena_rub = {offer.Price}, content_active = true", $"content_id = {product.ID}"); image.RemoveByRef(product.ID); foreach (var pic in offer.Picture) { var image_id = image.CreateGlobalID(); string extension = Path.GetExtension(pic); string savePath = Path.Combine(HostingEnvironment.MapPath("~/content/cms/files"), image_id.ToString() + extension); web.DownloadFile(pic, savePath); image.Save(image_id, extension, product.ID.ToString(), null, "", 100000, product.ID); } } } } foreach (var oldProduct in oldProducts) { content.Update($"artikul = '', content_active = false", $"vneshnij_id = '{oldProduct.UserDefined.vneshnij_id}' and content_template = 16515"); } } } StringBuilder result = new StringBuilder(); if (newPartitions.Count > 0) { result.Append("Новые разделы: <br/>"); foreach (string item in newPartitions) { result.Append($"{item}<br/>"); } result.Append("<br/><br/><br/>"); } if (newProducts.Count > 0) { result.Append("Новые товары: <br/>"); foreach (string item in newProducts) { result.Append($"{item}<br/>"); } result.Append("<br/><br/><br/>"); } if (noNames.Count > 0) { result.Append("Товары без имени: <br/>"); foreach (string item in noNames) { result.Append($"{item}<br/>"); } result.Append("<br/><br/><br/>"); } if (oldProducts.Count > 0) { result.Append("Удаленные товары: <br/>"); foreach (var item in oldProducts) { result.Append($"{item.Url}<br/>"); } result.Append("<br/><br/><br/>"); } return(result.ToString()); }
public ActionResult Edit( // base string guid, long?content_id, long content_block, long?content_root, string template_fields, // main string content_name, string content_url, long content_template, long?content_view, string content_link, // settings bool?content_in_sitemap, bool?content_active, bool?content_main, bool?content_allow_deleted, bool?content_allow_redirect, bool?content_redirect_permanent, string content_redirect_url, // seo string content_title, string content_description, string content_keywords, // rss bool?content_export_rss, string content_export_rss_ids, string content_export_rss_title, // content string content_h1, string content_h2, string content_short_text, string content_text, DateTime?content_publish, // images string[] image_desc, long[] image_ids_for_desc, // files string[] file_desc, long[] file_ids_for_desc, // user fields FormCollection user_fileds) { content_in_sitemap = content_in_sitemap ?? false; content_export_rss = content_export_rss ?? false; content_active = content_active ?? true; content_main = content_main ?? false; content_allow_deleted = content_allow_deleted ?? true; content_allow_redirect = content_allow_redirect ?? false; content_redirect_permanent = content_redirect_permanent ?? false; string user_data = string.Empty; int itemCount = 1; using (FieldRepository field_repository = new FieldRepository()) { List <dynamic> fields = field_repository.GetByIDs(template_fields); foreach (var item in fields) { if (item.field_group != "Пользовательские") { continue; } string value = user_fileds[item.field_name]; if (value != null) { switch ((string)item.field_type) { case "string": case "html": case "tags": value = string.Format("'{0}'", MySql.Data.MySqlClient.MySqlHelper.EscapeString(value)); break; case "date": case "datetime": value = string.IsNullOrWhiteSpace(value) ? null : string.Format("'{0}'", value); break; case "boolean": value = value == "true,false" ? "1" : "0"; break; case "decimal": decimal decimal_val; value = value.Replace(",", "."); if (!Decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal_val)) { value = "0"; } break; case "integer": int int_val; if (!Int32.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out int_val)) { value = "0"; } break; case "list": long list_val; if (!Int64.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out list_val)) { value = null; } break; default: value = value == null ? null : string.Format("'{0}'", value); break; } if (item.field_name == "tirazh_sht") { itemCount = Convert.ToInt32(value); } } user_data += string.Format(",{0} = {1}", item.field_name, value ?? "NULL"); } } List <long> other_ids = null; List <string> promocodes = new List <string>(); using (ContentRepository content_repository = new ContentRepository()) { using (ImageRepository image_repository = new ImageRepository()) { using (FileRepository file_repository = new FileRepository()) { if (content_id.HasValue) { var _old = content_repository.GetByID(content_id.Value); content_repository.Update(content_id.Value, content_in_sitemap.Value, content_export_rss.Value, content_active.Value, content_main.Value, content_allow_deleted.Value, content_name, content_view, content_block, content_title, content_description, content_keywords, content_h1, content_h2, content_short_text, content_text, content_publish, content_root, content_template, content_allow_redirect, content_redirect_permanent, content_redirect_url, content_link, content_export_rss_ids, content_export_rss_title, CurrentUser.domain_id, user_data); } else { for (int z = 0; z < itemCount; z++) { if (content_template == 42528) { do { content_name = IcbcodeUtility.GetPromocode().ToLowerInvariant(); }while (IcbcodeContent.Get(new string[] { "promokodi" }, new string[] { "promokod" }, query: $"content_name = '{content_name}'").Count != 0); } content_id = content_repository.CreateGlobalID(); string parent_url = string.Empty; if (content_root.HasValue) { var content = content_repository.GetByID(content_root.Value); parent_url += content.content_url; } string new_url = parent_url + "/" + Transliterator.Translite(content_url.Substring(0, (content_url.Length > 100 ? 100 : content_url.Length))); if (content_repository.Exists(new_url, CurrentUser.domain_id)) { if (content_template == 42528) { new_url = parent_url + "/" + content_id.ToString(); } else { new_url = new_url + "-" + content_id.ToString(); } } promocodes.Add(content_name); content_repository.Create(content_id.Value, content_in_sitemap.Value, content_export_rss.Value, content_active.Value, content_main.Value, content_allow_deleted.Value, content_name, content_view, new_url, content_block, content_title, content_description, content_keywords, content_h1, content_h2, content_short_text, content_text, content_publish, content_root, content_template, content_allow_redirect, content_redirect_permanent, content_redirect_url, content_link, content_export_rss_ids, content_export_rss_title, CurrentUser.domain_id, user_data); using (TemplateRepository template_repository = new TemplateRepository()) { var current_template = template_repository.GetByID(content_template); if (current_template.template_create_child) { CreateChildsDefaultContent(content_id.Value); } } } if (content_template == 42528) { IcbcodeUtility.SendEmail(null, null, $"Промокоды сгенерированы от {DateTime.Now}", string.Join("<br/>", promocodes)); } } image_repository.Update(content_id.Value, guid); if (image_desc != null && image_ids_for_desc != null && image_desc.Length == image_ids_for_desc.Length) { for (int i = 0; i <= image_ids_for_desc.Length - 1; i++) { image_repository.UpdateDescr(image_ids_for_desc[i], image_desc[i]); } } file_repository.Update(content_id.Value, guid); if (file_desc != null && file_ids_for_desc != null && file_desc.Length == file_ids_for_desc.Length) { for (int i = 0; i <= file_ids_for_desc.Length - 1; i++) { file_repository.UpdateDescr(file_ids_for_desc[i], file_desc[i]); } } if (other_ids != null) { foreach (var other_id in other_ids) { file_repository.RemoveByRef(other_id); if (file_ids_for_desc != null && file_ids_for_desc.Length > 0) { CopyFiles(content_id.Value, other_id); } } } } } } return(RedirectToAction("Index", new { block_id = content_block, content_root = content_root })); }
private void _Paste(long?content_id, long id, long block_id) { using (ContentRepository content_repository = new ContentRepository()) { var content = content_repository.GetByID(id); // build user data string user_data = string.Empty; using (FieldRepository field_repository = new FieldRepository()) { List <dynamic> fields = field_repository.GetByIDs(content.template_fields); foreach (var item in fields) { if (item.field_group != "Пользовательские") { continue; } var value = ((IDictionary <string, object>)content)[item.field_name]; if (value != null) { switch ((string)item.field_type) { case "string": case "html": value = string.Format("'{0}'", MySql.Data.MySqlClient.MySqlHelper.EscapeString(value)); break; case "boolean": break; case "list": break; case "date": value = string.Format("'{0}'", value.ToString("yyyy-MM-dd")); break; case "decimal": value = value.ToString().Replace(",", "."); break; default: value = value == null ? null : string.Format("'{0}'", value); break; } } user_data += string.Format(",{0} = {1}", item.field_name, (value == null ? "NULL" : value)); } } // end build user data string parent_url = string.Empty; if (content_id.HasValue) { var r_content = content_repository.GetByID(content_id.Value); parent_url += r_content.content_url; } string new_url = parent_url + "/" + Transliterator.Translite(content.content_name.Substring(0, (content.content_name.Length > 100 ? 100 : content.content_name.Length))); long new_content_id = content_repository.CreateGlobalID(); if (content_repository.Exists(new_url, CurrentUser.user_domain)) { new_url = new_url + "-" + new_content_id.ToString(); } content_repository.Create(new_content_id, content.content_in_sitemap, content.content_export_rss, content.content_active, content.content_main, content.content_allow_deleted, content.content_name, content.content_view, new_url, block_id, content.content_title, content.content_description, content.content_keywords, content.content_h1, content.content_h2, content.content_short_text, content.content_text, content.content_publish, content_id, content.content_template, content.content_allow_redirect, content.content_redirect_permanent, content.content_redirect_url, content.content_link, content.content_export_rss_ids, content.content_export_rss_title, CurrentUser.user_domain, user_data, content.content_order); // create files using (FileRepository file_repository = new FileRepository()) { foreach (var file in file_repository.Get(content.content_id.ToString())) { if (file.file_group == null) { continue; } var new_file_id = file_repository.CreateGlobalID(); file_repository.Save(new_file_id, file.file_extension, new_content_id.ToString(), file.file_desc, (int)file.file_size, file.file_field, file.file_publish, file.file_order); try { System.IO.File.Copy( Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", file.file_id, file.file_extension)), Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", new_file_id, file.file_extension)) ); } catch { using (FileRepository database = new FileRepository()) { database.Remove(new_file_id); } } } } // end create files // create images using (ImageRepository image_repository = new ImageRepository()) { foreach (var image in image_repository.Get(content.content_id.ToString())) { if (image.image_group == null) { continue; } var new_image_id = image_repository.CreateGlobalID(); image_repository.Save(new_image_id, image.image_extension, new_content_id.ToString(), image.image_field, image.image_desc, image.image_order); try { System.IO.File.Copy( Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", image.image_id, image.image_extension)), Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", new_image_id, image.image_extension)) ); } catch { using (FileRepository database = new FileRepository()) { database.Remove(new_image_id); } } } } using (ImageRepository image_repository = new ImageRepository()) { foreach (var image in image_repository.Get(content.content_id.ToString(), "kartinka")) { if (image.image_group == null) { continue; } var new_image_id = image_repository.CreateGlobalID(); image_repository.Save(new_image_id, image.image_extension, new_content_id.ToString(), image.image_field, image.image_desc, image.image_order); try { System.IO.File.Copy( Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", image.image_id, image.image_extension)), Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", new_image_id, image.image_extension)) ); } catch { using (FileRepository database = new FileRepository()) { database.Remove(new_image_id); } } } } // end create images foreach (var c in content_repository.GetsByParent(id)) { _Paste(new_content_id, c.content_id, block_id); } } }