public ContentResult SetText(int CMSPageID, int ViewID, string text) { var t = db.CMSPageTextDatas.FirstOrDefault(x => x.ViewID == ViewID && x.CMSPageID == CMSPageID); if (t != null) { t.Text = text; db.SubmitChanges(); } else { t = new CMSPageTextData() { ViewID = ViewID, CMSPageID = CMSPageID, LangID = 1, Text = text, Visible = true, OrderNum = db.CMSPageTextDatas.Count() + 1 }; db.CMSPageTextDatas.InsertOnSubmit(t); db.SubmitChanges(); } return(new ContentResult() { Content = "" }); }
public ActionResult Editor(int?pageID, FormCollection collection) { var current = db.CMSPages.FirstOrDefault(x => x.ID == pageID); if (current != null) { current.LoadLangValues(); } if (current == null) { return(RedirectToAction("Editor")); } var targetType = db.PageTypes.First(x => x.TypeName == "TextPage").ID; var pages = CMSPage.FullPageTable.Where(x => x.Type == targetType).OrderBy(x => x.OrderNum).AsEnumerable().ToList (); pages.Insert(0, new CMSPage() { ID = 0, PageName = "Выберите страницу в списке" }); ViewBag.TextPages = new SelectList(pages, "ID", "PageName", pageID ?? 0); CMSPageTextData data; if (current.CMSPageTextDatas.Any(z => z.LangID == AccessHelper.CurrentLang.ID)) { data = current.CMSPageTextDatas.First(z => z.LangID == AccessHelper.CurrentLang.ID); } else { data = new CMSPageTextData() { CMSPage = current, LangID = AccessHelper.CurrentLang.ID }; db.CMSPageTextDatas.InsertOnSubmit(data); } data.Text = (string)collection.ToValueProvider().GetValue("Text").ConvertTo(typeof(string)); db.SubmitChanges(); ModelState.AddModelError("", "Данные успешно сохранены"); return(View(current)); }