public ActionResult Edit(FormCollection collection) { int NewsId = int.Parse(collection["NewsId"]); NewsDetail nd = new NewsDetail { NEW_TITLE = collection["NewsTitle"], NEW_CONTENT = collection["NewsContent"], }; if (nm.Update(NewsId, nd)) { return RedirectToAction("Index"); } else { ViewData["Error"] = "Can not update news content"; return View(); } }
partial void DeleteNewsDetail(NewsDetail instance);
partial void UpdateNewsDetail(NewsDetail instance);
partial void InsertNewsDetail(NewsDetail instance);
private void detach_NewsDetails(NewsDetail entity) { this.SendPropertyChanging(); entity.LoginDetail = null; }
public string PostNews(string Title, string Content, int OwnerId) { NewsDetail nd = new NewsDetail { NEW_MODIFY_TIME = DateTime.Today, USER_ID = OwnerId, NEW_TITLE = Title, NEW_CONTENT = Content, }; db.NewsDetails.InsertOnSubmit(nd); try{ db.SubmitChanges(); return "OK"; }catch(Exception ex){ return ex.Message; } }
public bool Update(int NewsId, NewsDetail nd) { var update = from nsd in db.NewsDetails where nsd.NEW_ID == NewsId select nsd; if (update.Any()) { update.Single().NEW_CONTENT = nd.NEW_CONTENT; update.Single().NEW_TITLE = nd.NEW_TITLE; try { db.SubmitChanges(); return true; } catch (Exception ex) { return false; } } else { return false; } }