public ActionResult Edit(News news) { if (ModelState.IsValid) { news.Text = HttpUtility.UrlDecode(news.Text, System.Text.Encoding.Default); news.EditDate = DateTime.Now; news.EditUser = User.Identity.Name; if (NewsRepository.Edit(news)) return RedirectToAction("Index"); else return View(news); } return View(news); }
public static bool Edit(News news) { using (NewsEntities db = new NewsEntities()) { try { db.Entry(news).State = System.Data.EntityState.Modified; db.SaveChanges(); return true; } catch (Exception) { return false; } } }
public static bool Create(News news) { using (NewsEntities db = new NewsEntities()) { try { int len = 45; if (news.Text.Length <= len) news.TextMain = news.Text.Remove(len) + " ..."; else news.TextMain = news.Text; db.News.Add(news); db.SaveChanges(); db.Dispose(); } catch (Exception) { return false; } } return true; }