From c31a2eab12d018f3b3325fa3329ca73b8e83177c Mon Sep 17 00:00:00 2001 From: lianpi3 Date: Thu, 1 Aug 2024 15:05:21 +0330 Subject: [PATCH] Revert "display news list and individual" This reverts commit 2002c9fe09ed1eff7fb7ad94e32b3fe9c8e9da69. --- Controllers/newsController.cs | 25 +++++-------------------- Models/newsModel.cs | 19 ------------------- Views/news/Details.cshtml | 12 +++++------- Views/news/Index.cshtml | 33 +++++++++++++-------------------- WebApplication1.csproj | 1 - 5 files changed, 23 insertions(+), 67 deletions(-) delete mode 100644 Models/newsModel.cs diff --git a/Controllers/newsController.cs b/Controllers/newsController.cs index 6be2620..8299bed 100644 --- a/Controllers/newsController.cs +++ b/Controllers/newsController.cs @@ -15,29 +15,14 @@ namespace WebApplication1.Controllers public class newsController : Controller { private newswebappEntities db = new newswebappEntities(); - // GET: news public ActionResult Index() { - var models = (from user in db.users // Access Users DbSet - join news in db.news on user.ID equals news.userID into newsGroup // Join News DbSet - from news in newsGroup.DefaultIfEmpty() // Left outer join - where news != null // Filter based on existence of news record - select new newsModel - { - DisplayName = user != null ? user.displayname : null, - NewsID = news.ID, // Use null-conditional operator for missing news - Title = news.title, - Image = news.image, - category = news.cat, - tag = news.tag, - date = news.publishDate, - views = news.views - }).ToList(); - - - return View(models); + var news = db.news.ToList(); + var users = db.users.ToList(); + var models = new Tuple, List>(news, users); + return View(db.news.ToList()); } // GET: news/Details/5 @@ -53,7 +38,7 @@ namespace WebApplication1.Controllers return HttpNotFound(); } var user = db.users.Find(news.userID); - ViewBag.user = user; + // var model = new Tuple(news,user); return View(news); } diff --git a/Models/newsModel.cs b/Models/newsModel.cs deleted file mode 100644 index 24ff4ff..0000000 --- a/Models/newsModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace WebApplication1.Models -{ - public class newsModel - { - public string DisplayName { get; set; } - public string Title { get; set; } - public int? NewsID { get; set; } - public string Image { get; set; } - public string category { get; set; } - public string tag { get; set; } - public int? views { get; set; } - public DateTime? date { get; set; } - } -} \ No newline at end of file diff --git a/Views/news/Details.cshtml b/Views/news/Details.cshtml index fb6ee66..501c28d 100644 --- a/Views/news/Details.cshtml +++ b/Views/news/Details.cshtml @@ -1,9 +1,7 @@ -@using WebApplication1.Models -@model news +@model WebApplication1.Models.news @{ ViewBag.Title = "Details"; - var _user = ViewBag.user as user; }

Details

@@ -25,8 +23,8 @@
- - + + @Html.DisplayFor(model => model.image)
@@ -70,11 +68,11 @@
- original poster + @Html.DisplayNameFor(model => model.userID)
- @_user.displayname + @Html.DisplayFor(model => model.userID)
diff --git a/Views/news/Index.cshtml b/Views/news/Index.cshtml index 8f2e6fc..1dd3a67 100644 --- a/Views/news/Index.cshtml +++ b/Views/news/Index.cshtml @@ -1,5 +1,4 @@ -@using WebApplication1.Models -@model List +@model IEnumerable @{ ViewBag.Title = "Index"; } @@ -12,22 +11,19 @@ - @@ -35,27 +31,24 @@ @foreach (var item in Model) { - } diff --git a/WebApplication1.csproj b/WebApplication1.csproj index 65f9c8a..c8c5b71 100644 --- a/WebApplication1.csproj +++ b/WebApplication1.csproj @@ -152,7 +152,6 @@ Model1.tt -
- Title + @Html.DisplayNameFor(model => model.title) - Category + @Html.DisplayNameFor(model => model.cat) - Tag + @Html.DisplayNameFor(model => model.publishDate) - Publisher + @Html.DisplayNameFor(model => model.userID) - Published On - - views + @Html.DisplayNameFor(model => model.views)
- @Html.DisplayFor(modelItem => item.Title) + @Html.DisplayFor(modelItem => item.title) - @Html.DisplayFor(modelItem => item.category) + @Html.DisplayFor(modelItem => item.cat) - @Html.DisplayFor(modelItem => item.tag) + @Html.DisplayFor(modelItem => item.publishDate) - @Html.DisplayFor(modelItem => item.DisplayName) - - @Html.DisplayFor(modelItem => item.date) + @Html.DisplayFor(modelItem => item.userID) @Html.DisplayFor(modelItem => item.views) - @Html.ActionLink("Edit", "Edit", new { id = item.NewsID }) | - @Html.ActionLink("Details", "Details", new { id = item.NewsID }) | - @Html.ActionLink("Delete", "Delete", new { id = item.NewsID }) + @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | + @Html.ActionLink("Details", "Details", new { id=item.ID }) | + @Html.ActionLink("Delete", "Delete", new { id=item.ID })