コード例 #1
0
 public ActionResult Update(int id,string header,string announce,string content)
 {
     var item = _ctx.Pages.FirstOrDefault(x => x.Id == id);
     if (item != null)
     {
         item.Title = header;
         item.Announce = announce;
         item.Text = content;
         _ctx.Pages.ApplyCurrentValues(item);
         _ctx.SaveChanges();
     }
     else
     {
         item = new Page
         {
             Title = header,
             Announce = announce,
             Text = content,
             PageType = PageTypes.News,
             Created = DateTime.UtcNow,
             Updated = DateTime.UtcNow,
             Published = DateTime.UtcNow,
         };
         _ctx.Pages.AddObject(item);
         _ctx.SaveChanges();
     }
     return RedirectToAction("News", "Management");
 }
コード例 #2
0
        protected VPage ConvertToVPage(Page model)
        {
            var vPage = new VPage
            {
                Announce = model.Announce,
                Updated = model.Updated,
                Published = model.Published,
                Id = model.Id,
                NTitle = model.Title,
                Text = model.Text,
                PageType = model.PageType,
            };

            return vPage;
        }
コード例 #3
0
 public ActionResult Edit(int id, string content)
 {
     var item = _ctx.Pages.FirstOrDefault(x => x.Id == id);
     if (item != null)
     {
         item.Text = content;
         _ctx.Pages.ApplyCurrentValues(item);
         _ctx.SaveChanges();
     }
     else
     {
        var page = new Page
         {
             Text = content,
             PageType = "Help",
             Created = DateTime.UtcNow,
             Published = DateTime.UtcNow,
             Updated = DateTime.UtcNow
         };
         _ctx.Pages.AddObject(page);
         _ctx.SaveChanges();
     }
     return RedirectToAction("Help", "Management");
 }
コード例 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Pages EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPages(Page page)
 {
     base.AddObject("Pages", page);
 }
コード例 #5
0
 /// <summary>
 /// Create a new Page object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="created">Initial value of the Created property.</param>
 /// <param name="updated">Initial value of the Updated property.</param>
 /// <param name="published">Initial value of the Published property.</param>
 /// <param name="homePage">Initial value of the HomePage property.</param>
 /// <param name="isPublished">Initial value of the IsPublished property.</param>
 /// <param name="votes">Initial value of the Votes property.</param>
 public static Page CreatePage(global::System.Int32 id, global::System.DateTime created, global::System.DateTime updated, global::System.DateTime published, global::System.Boolean homePage, global::System.Boolean isPublished, global::System.Int32 votes)
 {
     Page page = new Page();
     page.Id = id;
     page.Created = created;
     page.Updated = updated;
     page.Published = published;
     page.HomePage = homePage;
     page.IsPublished = isPublished;
     page.Votes = votes;
     return page;
 }
コード例 #6
0
        private void SavePage(VPage model)
        {
            Page page;
            var now = DateTime.UtcNow;
            if (model.Id == 0)
            {
                page = new Page();
                page.Created = now;
                page.PageType = model.PageType;
                _ctx.Pages.AddObject(page);
            }
            else
            {
                page = _ctx.Pages.First(t => t.Id == model.Id);
            }

            page.Title = model.NTitle ?? "";
            //page.PageTitle = model.PageTitle ?? "";
            page.Slug = model.Slug ?? "";
            page.Announce = model.Announce ?? "";
            page.Text = model.Text ?? "";
            page.HomePage = model.IsHot;
            page.Updated = now;
            page.Published = model.Published;
            _ctx.SaveChanges();

            model.Id = page.Id;
        }