public ActionResult Edit(long?view_id, string view_friendly_name, string view_name, string view_path) { using (ViewRepository view_repository = new ViewRepository()) { if (view_id.HasValue) { view_repository.Update(view_id.Value, view_friendly_name, view_name, view_path, CurrentUser.user_domain); } else { view_id = view_repository.CreateGlobalID(); string new_view_name = Transliterator.Translite(view_friendly_name); if (view_repository.Exists(new_view_name, CurrentUser.user_domain)) { new_view_name = new_view_name + "-" + view_id.ToString(); } view_repository.Create(view_id.Value, view_friendly_name, new_view_name, view_path, CurrentUser.user_domain); } } return(RedirectToAction("Index")); }
public ActionResult Edit(long?template_id, string template_friendly_name, string template_name, bool template_allow_subpartitions, string[] template_fields, string[] template_views, long?[] template_templates, bool template_allow_sort, string template_order_fields, bool template_create_child) { using (TemplateRepository template_repository = new TemplateRepository()) { if (template_id.HasValue) { template_repository.Update(template_id.Value, template_friendly_name, template_name, template_allow_subpartitions, (template_fields == null ? string.Empty : string.Join(",", template_fields)), (template_views == null ? string.Empty : string.Join(",", template_views)), (template_templates == null ? string.Empty : string.Join(",", template_templates)), template_allow_sort, template_order_fields, template_create_child, CurrentUser.user_domain); } else { template_id = template_repository.CreateGlobalID(); string new_template_name = Transliterator.Translite(template_friendly_name); if (template_repository.Exists(new_template_name, CurrentUser.user_domain)) { new_template_name = new_template_name + "-" + template_id.ToString(); } template_repository.Create(template_id.Value, template_friendly_name, new_template_name, template_allow_subpartitions, (template_fields == null ? string.Empty : string.Join(",", template_fields)), (template_views == null ? string.Empty : string.Join(",", template_views)), (template_templates == null ? string.Empty : string.Join(",", template_templates)), template_allow_sort, template_order_fields, template_create_child, CurrentUser.user_domain); } } return(RedirectToAction("Index")); }
public ActionResult Edit(long?block_id, string block_name, string block_friendly_name, long?[] block_templates, long?block_content_root, string block_area, string block_controller, string block_action, bool block_allow_sort, string block_order_fields) { using (BlockRepository block_repository = new BlockRepository()) { if (block_id.HasValue) { block_repository.Update(block_id.Value, block_name, block_friendly_name, (block_templates == null ? string.Empty : string.Join(",", block_templates)), block_content_root, block_area, block_controller, block_action, block_allow_sort, block_order_fields, CurrentUser.user_domain); } else { block_id = block_repository.CreateGlobalID(); string new_block_name = Transliterator.Translite(block_friendly_name); if (block_repository.Exists(new_block_name, CurrentUser.user_domain)) { new_block_name = new_block_name + "-" + block_id.ToString(); } block_repository.Create(block_id.Value, new_block_name, block_friendly_name, (block_templates == null ? string.Empty : string.Join(",", block_templates)), block_content_root, block_area, block_controller, block_action, block_allow_sort, block_order_fields, false, CurrentUser.user_domain); } } return(RedirectToAction("Index")); }
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 ActionResult AddSeparate() { string block_friendly_name = "Разделитель"; using (BlockRepository block_repository = new BlockRepository()) { long block_id = block_repository.CreateGlobalID(); string new_block_name = Transliterator.Translite(block_friendly_name); if (block_repository.Exists(new_block_name, CurrentUser.user_domain)) { new_block_name = new_block_name + "-" + block_id.ToString(); } block_repository.Create(block_id, new_block_name, block_friendly_name, string.Empty, null, null, null, null, false, string.Empty, true, CurrentUser.user_domain); } return(RedirectToAction("Index")); }
public ActionResult Edit(long?field_id, string field_name, string field_friendly_name, string field_type, string field_description, long?filed_content_root, string filed_template_name, bool?field_is_filter, bool?field_inside_domain, long?filed_tags_limit, string field_rel_field) { field_is_filter = field_is_filter ?? false; field_inside_domain = field_inside_domain ?? true; string column_data_type; switch (field_type) { case "string": case "html": case "multiplelist": case "tags": column_data_type = "TEXT"; break; case "decimal": column_data_type = "DECIMAL(10,2)"; break; case "integer": column_data_type = "INT"; break; case "boolean": column_data_type = "BOOL"; break; case "date": column_data_type = "DATE"; break; case "datetime": column_data_type = "DATETIME"; break; case "list": column_data_type = "BIGINT"; break; default: column_data_type = "TEXT"; break; } field_name = Transliterator.Translite(string.IsNullOrWhiteSpace(field_name) ? field_friendly_name : field_name, '_'); using (FieldRepository field_repository = new FieldRepository()) { using (ContentRepository content_repository = new ContentRepository()) { if (field_id.HasValue) { var old_field = field_repository.GetByID(field_id.Value); if (!old_field.field_system) { if (field_name != old_field.field_name && field_repository.Exists(field_name)) { field_name = field_name + "_" + field_id.Value.ToString(); } content_repository.EditColumn(old_field.field_name, field_name, column_data_type); } field_repository.Update(field_id.Value, field_name, field_friendly_name, field_type, field_description, filed_content_root, string.IsNullOrWhiteSpace(filed_template_name) ? null : filed_template_name, field_is_filter.Value, field_inside_domain.Value, filed_tags_limit, field_rel_field); } else { field_id = field_repository.CreateGlobalID(); if (field_repository.Exists(field_name)) { field_name = field_name + "_" + field_id.ToString(); } content_repository.AddColumn(field_name, column_data_type); field_repository.Create(field_name, field_friendly_name, field_type, field_description, "Пользовательские", filed_content_root, string.IsNullOrWhiteSpace(filed_template_name) ? null : filed_template_name, field_is_filter.Value, field_inside_domain.Value, filed_tags_limit, field_rel_field); } } } return(RedirectToAction("Index")); }
public ActionResult Edit(long?var_id, string var_name, string var_friendly_name, string var_value, string var_type, string var_comment, string var_group, FormCollection form) { // bool file_is_change = false; foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName] as HttpPostedFileBase; if (file.ContentLength == 0 || file.FileName == "blob" || file.FileName == "var_value") { continue; } file_is_change = true; // save in db long file_id; string file_desc = file.FileName; int file_size = file.ContentLength; string file_extension = Path.GetExtension(file.FileName); using (FileRepository database = new FileRepository()) { file_id = database.CreateGlobalID(); database.Save(file_id, file_extension, null, file.FileName, file.ContentLength, string.Empty); } // save in file system try { file.SaveAs(Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", file_id, file_extension))); var_value = string.Format("/content/cms/files/{0}{1}", file_id, file_extension); } catch { using (FileRepository database = new FileRepository()) { database.Remove(file_id); } } } // var_group = var_group.Replace(",", string.Empty); using (VariableRepository variable_repository = new VariableRepository()) { if (var_id.HasValue) { var v = variable_repository.GetByID(var_id.Value); variable_repository.Update(var_id.Value, var_name, var_friendly_name, (file_is_change && v.var_type == "Файл" ? var_value : (v.var_type == "Файл" ? v.var_value : var_value)), var_comment, var_group, CurrentUser.user_domain); } else { var_id = variable_repository.CreateGlobalID(); string new_var_name = Transliterator.Translite(var_friendly_name); if (variable_repository.Exists(new_var_name, CurrentUser.user_domain)) { new_var_name = new_var_name + "-" + var_id.ToString(); } variable_repository.Create(var_id.Value, new_var_name, var_friendly_name, var_value, var_type, var_comment, var_group, CurrentUser.user_domain); } } return(RedirectToAction("Index")); }
public ActionResult Index() { string domain = Request.Url.Host; string url = Request.Url.LocalPath; dynamic content = null; using (ContentRepository content_repository = new ContentRepository()) { content = url == "/" ? content_repository.GetActiveMain(domain) : content_repository.GetActiveByUrl(url.TrimEnd('/'), domain); } if (content == null) { throw new HttpException(404, "Not found"); } else { string redirect_url = string.IsNullOrWhiteSpace(content.content_redirect_url) ? Url.Content("~/") : content.content_redirect_url; string view_path = content.view_path; if (content.content_allow_redirect) { return(content.content_redirect_permanent ? RedirectPermanent(redirect_url) : Redirect(redirect_url)); } else if (content.content_export_rss) { var feed = new SyndicationFeed { Title = new TextSyndicationContent(content.content_export_rss_title), Description = new TextSyndicationContent(content.content_export_rss_title), BaseUri = new Uri(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, content.content_url)), Id = Transliterator.Translite(content.content_export_rss_title, '_'), LastUpdatedTime = DateTime.Now, Items = new List <SyndicationItem>() }; List <SyndicationItem> items = new List <SyndicationItem>(); using (ContentRepository content_repository = new ContentRepository()) { long totals; foreach (var item in content_repository.GetActive(null, ModelUtility.GetLongArray(content.content_export_rss_ids), null, "content_last_update desc", 1, 30, out totals, null, null, domain)) { var syndItem = new SyndicationItem { Title = new TextSyndicationContent(item.content_link ?? item.content_h1), Content = new TextSyndicationContent(IcbcodeUtility.GetPlainText(item.content_short_text)), Id = item.content_id.ToString(), LastUpdatedTime = item.content_publish ?? item.content_last_update }; syndItem.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, item.content_url)))); items.Add(syndItem); } } feed.Items = items; return(new RssActionResult() { Feed = feed }); } else { if (string.IsNullOrWhiteSpace(view_path)) { throw new HttpException(404, "Not found"); } return(View(view_path, IcbcodeContent.Convert(content, 1, 1))); } } }
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); } } }