public ActionResult Add(int id = 0) { if (id > 0) { DailyVerse verse = _repo.Get(id); DailyVerseDto verseDto = new DailyVerseDto { Id = verse.Id, VerseDate = verse.VerseDate, VerseTitle = verse.VerseTitle, Verse = verse.Verse }; return(View(verseDto)); } return(View()); }
public ActionResult Add(DailyVerseDto verseDto) { bool result = false; if (ModelState.IsValid) { DailyVerse verse = new DailyVerse(); verse.VerseDate = verseDto.VerseDate; verse.VerseTitle = verseDto.VerseTitle; verse.Verse = verseDto.Verse; if (verseDto.Id == 0) { result = _repo.Add(verse); if (_repo.Add(verse)) { ViewBag.Message = "Success"; ModelState.Clear(); } } else { verse.Id = verseDto.Id; result = _repo.Update(verse); } if (result) { ViewBag.Message = "Success"; } else { ViewBag.Message = "Unable to save"; } } return(View()); }