public ActionResult Makale(int?id) { if (!id.HasValue) { return(RedirectToAction("index", "Home")); } try { calisartikContext db = new calisartikContext(); var query = db.icerikler.SingleOrDefault(w => w.icerikID == id); if (query == null) { return(RedirectToAction("index", "Home")); } MakaleViewModel model = new MakaleViewModel() { icerikID = query.icerikID, Yazar = query.Yazar, Baslik = query.Baslik, BaslikFoto = query.BaslikFoto, Metin = query.Metin, OlusturmaTarihi = query.OlusturmaTarihi, }; model.yorumlar = db.yorumlar.Where(w => w.icerikId == query.icerikID).OrderByDescending(w => w.OlusturmaTarihi).ToList(); return(View(model)); } catch (Exception) { return(RedirectToAction("index", "Home")); } }
public ActionResult Create(MakaleViewModel model) { if (!ModelState.IsValid) { return(View()); } var makale = new Makale() { Baslik = model.Baslik, Ozet = model.Ozet, Icerik = model.Icerik, KategoriId = 1, CreatedDate = DateTime.Now, Like = 0, Dislike = 0, Views = 0, IsActive = model.IsActive, IsDeleted = model.IsDeleted }; _makaleRepository.Add(makale); _makaleRepository.Save(); return(RedirectToAction("Index")); }