Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 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;
         }
     }
 }
Exemplo n.º 3
0
 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;
 }