public ActionResult AddPage(PageModel adPageModel) { if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account"); if (ModelState.IsValid) { var scope = ObjectScopeProvider1.GetNewObjectScope(); var contentPage = new ContentPage { Name = adPageModel.PageTitle, Content = adPageModel.Content, Id = DateTime.Now.Ticks.ToString() }; scope.Transaction.Begin(); scope.Add(contentPage); scope.Transaction.Commit(); try { using (var connection = new SqlConnection("Data Source=208.91.198.196;Initial Catalog=admin_altus_system;Persist Security Info=True;User ID=admin_altus_system;Password=password@123")) { connection.Open(); string qry = "update content_page set [<_content>k___backing_field] = '" + adPageModel.Content + "' where [<_id>k___backing_field]='" + contentPage.Id + "'"; var command = new SqlCommand(qry, connection); command.ExecuteNonQuery(); connection.Close(); } } catch (Exception) { return RedirectToAction("Pages"); } return RedirectToAction("Pages"); } return View(adPageModel); }
public ActionResult EditPage(PageModel pageModel) { if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account"); if (ModelState.IsValid) { var scope = ObjectScopeProvider1.GetNewObjectScope(); var pages = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable() where c.Id != null && c.Id.Equals(pageModel.ID) select c).ToList(); foreach (ContentPage page in pages) { scope.Transaction.Begin(); page.Name = pageModel.PageTitle; page.Content = pageModel.Content; scope.Add(page); scope.Transaction.Commit(); try { using (var connection = new SqlConnection("Data Source=208.91.198.196;Initial Catalog=admin_altus_system;Persist Security Info=True;User ID=admin_altus_system;Password=password@123")) { connection.Open(); string qry = "update content_page set [<_content>k___backing_field] = '" + pageModel.Content + "' where [<_id>k___backing_field]='" + page.Id + "'"; var command = new SqlCommand(qry, connection); command.ExecuteNonQuery(); connection.Close(); } } catch (Exception) { continue; } break; } return RedirectToAction("Pages"); } return View(pageModel); }
public ActionResult EditPage(string pid) { if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account"); if (pid != null) { var scope = ObjectScopeProvider1.GetNewObjectScope(); var pages = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable() where c.Id != null && c.Id.Equals(pid) select c).ToList(); var contentPage = new PageModel(); foreach (ContentPage page in pages) { contentPage.PageTitle = page.Name; contentPage.Content = page.Content; contentPage.ID = page.Id; break; } return View(contentPage); } return RedirectToAction("Pages"); }