public ActionResult Create()
        {
            NewsTimeViewModel newNewsTime = new NewsTimeViewModel();

            newNewsTime.News      = new News();
            newNewsTime.News.Date = DateTime.Now;
            return(View(newNewsTime));
        }
        public void CreateTest1()
        {
            // Act
            NewsTimeViewModel newNews = new NewsTimeViewModel();

            try
            {
                ViewResult result = controller.Create(newNews) as ViewResult;
                Assert.Fail();
            }
            catch (NullReferenceException)
            {
                Assert.Pass();
            }
        }
        public ActionResult Edit(int id)
        {
            News news = db.News.Find(id);

            if (news == null)
            {
                return(RedirectToAction("Index"));
            }
            NewsTimeViewModel editNews = new NewsTimeViewModel();

            editNews.News    = news;
            editNews.Hour    = news.Date.Hour.ToString();
            editNews.Minutes = news.Date.Minute.ToString();
            return(View(editNews));
        }
 public ActionResult Create(NewsTimeViewModel newNewsTime)
 {
     if (ModelState.IsValid)
     {
         News newNews = newNewsTime.News;
         int  hour, minutes;
         Int32.TryParse(newNewsTime.Hour, out hour);
         Int32.TryParse(newNewsTime.Minutes, out minutes);
         TimeSpan time = new TimeSpan(hour, minutes, 0);
         newNews.Date = newNews.Date + time;
         db.News.Add(newNews);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(newNewsTime));
     }
 }
        public ActionResult Edit(NewsTimeViewModel model)
        {
            try
            {
                var news = db.News.Find(model.News.ID);
                int hour, minutes;
                Int32.TryParse(model.Hour, out hour);
                Int32.TryParse(model.Minutes, out minutes);
                TimeSpan time = new TimeSpan(hour, minutes, 0);
                news.Date  = model.News.Date + time;
                news.Text  = model.News.Text;
                news.Title = model.News.Title;
                UpdateModel(news);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = model.News.ID }));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Edit Failure, see inner exception");
            }

            return(View(model));
        }