public ActionResult AddContent(Content content) { DBNLDataContext db = new DBNLDataContext(); db.Contents.InsertOnSubmit(content); db.SubmitChanges(); return RedirectToAction("ListContents"); }
private static void DoMigration(int oldid, int newid) { DBNLDataContext db = new DBNLDataContext(); XDocument doc = XDocument.Load("articles.xml"); foreach (var ele in doc.Root.Elements("table")) { //.Where(p => p.Element("column").Attribute("cid").Value == oldid.ToString()) var cid = ele.Elements("column").Where(a => a.Attribute("name").Value == "cid").Select(a => a.Value).FirstOrDefault(); if (cid != oldid.ToString()) continue; var name = ele.Elements("column").Where(a => a.Attribute("name").Value == "name_vn").Select(a => a.Value).FirstOrDefault(); var content_vn = ele.Elements("column").Where(a => a.Attribute("name").Value == "content_vn").Select(a => a.Value).FirstOrDefault(); var img = ele.Elements("column").Where(a => a.Attribute("name").Value == "img").Select(a => a.Value).FirstOrDefault(); var dated = ele.Elements("column").Where(a => a.Attribute("name").Value == "dated").Select(a => a.Value).FirstOrDefault(); var ids = ele.Elements("column").Where(a => a.Attribute("name").Value == "id").Select(a => a.Value).FirstOrDefault(); int id = int.Parse(ids); //if(id <847) continue; DateTime d = DateTime.ParseExact(dated, "yyyy-MM-dd", null); Content c = new Content() { Title = name, Content1 = HttpUtility.HtmlDecode(content_vn), Picture = img, Status = "Actived", CreatedDate = d, CategoryId = newid, }; c.UpdatedDate = c.CreatedDate; c.UniqueKey = c.Title.ToUrlKey(); c.Content1 = c.Content1.Replace("/fckFiles/image/", "/Resources/Galleries/"); c.Description = c.Content1.TrimmedWord(100); Console.WriteLine(c.Title); c.Picture = c.Picture.Substring(c.Picture.LastIndexOf("/") + 1); db.Contents.InsertOnSubmit(c); db.SubmitChanges(); } }
public ActionResult EditContent(int id, Content content) { DBNLDataContext db = new DBNLDataContext(); Content updContent = db.Contents.Where(p => p.ContentId == id).SingleOrDefault(); updContent.ContentCategory = content.ContentCategory; updContent.Count = content.Count; updContent.CreatedDate = content.CreatedDate; updContent.Status = content.Status; updContent.Title = content.Title; updContent.UpdatedDate = content.UpdatedDate; updContent.IsFeatured = content.IsFeatured; db.SubmitChanges(); return RedirectToAction("ListContents"); }
partial void DeleteContent(Content instance);
partial void UpdateContent(Content instance);
partial void InsertContent(Content instance);
private void detach_Contents(Content entity) { this.SendPropertyChanging(); entity.ContentCategory = null; }
private void attach_Contents(Content entity) { this.SendPropertyChanging(); entity.ContentCategory = this; }