Exemplo n.º 1
0
        public ActionResult EditNews(News news)
        {
            var context = new TourEntities1();

            if (ModelState.IsValid)
            {
                SaveNews(news);
                TempData["message"] = string.Format("{0} has been saved", news.Name);
                return RedirectToAction("Index");
            }
            else
            {
                // there is something wrong with the data values
                return View(news);
            }
        }
Exemplo n.º 2
0
        public void SaveNews(News b)
        {
            var context = new TourEntities1();
            if (b.Id == 0)
            {
                b.Date = DateTime.Now;
                context.News.Add(b);
            }
            else
            {
                News dbEntry = context.News.Find(b.Id);
                if (dbEntry != null)
                {
                    dbEntry.Name = b.Name;
                    dbEntry.Description = b.Description;
                    dbEntry.Date = DateTime.Now;
                }
            }

            context.SaveChanges();
        }
Exemplo n.º 3
0
 public ViewResult CreateNews()
 {
     News model = new News();
     return View("EditNews", model);
 }