From 0c2a9df2a96931ddbe2b8bd82980b5ac7ae0754c Mon Sep 17 00:00:00 2001 From: Bartosz Chyzy Date: Sat, 1 Dec 2018 23:31:52 +0100 Subject: [PATCH] Inicjalizacja HomeControllera --- .../Forum.DataAccessLayer.Models/Category.cs | 2 +- .../Forum.DataAccessLayer.Models/Question.cs | 2 + .../Forum.DataAccessLayer.csproj | 10 ++ .../201812012216378_Added Title.Designer.cs | 29 ++++ .../Migrations/201812012216378_Added Title.cs | 18 +++ .../201812012216378_Added Title.resx | 126 ++++++++++++++++++ .../Forum/Forum/Controllers/HomeController.cs | 37 +++-- Trunk/Server/Forum/Forum/Forum.csproj | 5 +- .../Forum/Forum/Views/Home/About.cshtml | 7 - .../Forum/Forum/Views/Home/Category.cshtml | 7 + .../Forum/Forum/Views/Home/Contact.cshtml | 17 --- .../Forum/Forum/Views/Home/Index.cshtml | 43 +++--- .../Forum/Forum/Views/Home/Question.cshtml | 7 + 13 files changed, 247 insertions(+), 63 deletions(-) create mode 100644 Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.Designer.cs create mode 100644 Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.cs create mode 100644 Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.resx delete mode 100644 Trunk/Server/Forum/Forum/Views/Home/About.cshtml create mode 100644 Trunk/Server/Forum/Forum/Views/Home/Category.cshtml delete mode 100644 Trunk/Server/Forum/Forum/Views/Home/Contact.cshtml create mode 100644 Trunk/Server/Forum/Forum/Views/Home/Question.cshtml diff --git a/Trunk/Components/Forum.DataAccessLayer.Models/Category.cs b/Trunk/Components/Forum.DataAccessLayer.Models/Category.cs index 183f7c4..d63964c 100644 --- a/Trunk/Components/Forum.DataAccessLayer.Models/Category.cs +++ b/Trunk/Components/Forum.DataAccessLayer.Models/Category.cs @@ -8,7 +8,7 @@ namespace Forum.DataAccessLayer.Models { public class Category { - public int Id { get; set; } + public int Id { get; set; } public string CategoryName { get; set; } diff --git a/Trunk/Components/Forum.DataAccessLayer.Models/Question.cs b/Trunk/Components/Forum.DataAccessLayer.Models/Question.cs index 9152518..e51e1b7 100644 --- a/Trunk/Components/Forum.DataAccessLayer.Models/Question.cs +++ b/Trunk/Components/Forum.DataAccessLayer.Models/Question.cs @@ -15,6 +15,8 @@ namespace Forum.DataAccessLayer.Models public DateTime PostDate { get; set; } + public string Title { get; set; } + public string Content { get; set; } public bool IsClosed { get; set; } diff --git a/Trunk/Server/Forum/Forum.DataAccessLayer/Forum.DataAccessLayer.csproj b/Trunk/Server/Forum/Forum.DataAccessLayer/Forum.DataAccessLayer.csproj index ee39d61..e021c1d 100644 --- a/Trunk/Server/Forum/Forum.DataAccessLayer/Forum.DataAccessLayer.csproj +++ b/Trunk/Server/Forum/Forum.DataAccessLayer/Forum.DataAccessLayer.csproj @@ -90,6 +90,10 @@ 201812012143359_Email validation.cs + + + 201812012216378_Added Title.cs + @@ -118,6 +122,12 @@ 201812012143359_Email validation.cs + + 201812012216378_Added Title.cs + + + + \ No newline at end of file diff --git a/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.Designer.cs b/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.Designer.cs new file mode 100644 index 0000000..a383ff9 --- /dev/null +++ b/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.Designer.cs @@ -0,0 +1,29 @@ +// +namespace Forum.DataAccessLayer.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")] + public sealed partial class AddedTitle : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(AddedTitle)); + + string IMigrationMetadata.Id + { + get { return "201812012216378_Added Title"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.cs b/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.cs new file mode 100644 index 0000000..3d418b2 --- /dev/null +++ b/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.cs @@ -0,0 +1,18 @@ +namespace Forum.DataAccessLayer.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class AddedTitle : DbMigration + { + public override void Up() + { + AddColumn("dbo.Questions", "Title", c => c.String()); + } + + public override void Down() + { + DropColumn("dbo.Questions", "Title"); + } + } +} diff --git a/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.resx b/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.resx new file mode 100644 index 0000000..c53eebf --- /dev/null +++ b/Trunk/Server/Forum/Forum.DataAccessLayer/Migrations/201812012216378_Added Title.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAO1d227kuBF9D5B/EPSUBN5uXzKDidG9C2/b3hgZXzLtWeTNoCW6LYwuvRI1YyPYL8tDPim/EFJXXiVSUqvlTTAvbZE8LBariqwiWfOff/178cNL4FtfYZx4Ubi0j2aHtgVDJ3K9cLO0U/T03Qf7h+9//7vFhRu8WD+X9U5IPdwyTJb2M0Lb0/k8cZ5hAJJZ4DlxlERPaOZEwRy40fz48PAv86OjOcQQNsayrMWnNEReALM/8J+rKHTgFqXAv45c6CfFd1yyzlCtGxDAZAscuLQvozgNZucAgTPHgUnyEbzC2LbOfA9gYtb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vRRdzFpnADdoZrqKeb/+D2R8G2wdvhMTug2GvU+5HzKLWz/JGj092r4NDJs0zYiavOkY0y6Ph7zZJWY414zLRdbZ8bync5H1W2IGdGH5nGJdNmnyfGL9hkhHyMw8TqqpyuPsoyfyc7k3qyeyxFa73LCIx2Rvykvv5j6QQe/efRg+d9EUMmxIHrFOIEHRmG+wmy5bGuyu3kIWoqkJXOFaTSDV0NgCp7qMOXWBM8snNDV5y/2t/WcNGlvaFHdvJiZsJrmBeklaS1qcMtlEhxxDb0Y6lA/8pHGntis5IwiHcb6kIRIkjS0JDdd79ykBLRduRpj9Dlmj9pkkykgGB5Kdhruwg8uOkZy23MYZQXo65s6aSrqsfe5cWm7vTmPXsvd8WOLLfn5O2YRG5SJSBxq41SW/V7W03ccIz3oeqlCl3eDBxd2P0I1YRdphlgRcnvKE71QSKBB6ldRp7laRzKip78JnbOy7qNPctyI9UFPfuRo2dp1Xae5ZnjWD77heTYQO6yJZR+psJXwX9aIpdFEXybpQZ1dR8q+Fd218k/Ns/ynAmNQoYqFgsBrjcpJXEerUcxPP+DUMYxhtVzxW3QFjdpfgaxi20Mokf6fZnyk7Seg1HDvYFZZ+rtB/6DtK3iXNKbW3Qe4wNZcsE5fsSktHFk0v65ZUF2V6OIpGG2TZEh8G4K1zGpLz+fyvc5h4mxqCPGcJocNsmqs6V+FTVO7dOYrKKtxp4DVEwCVvT2LkPQEH4WJyXTH7/1SyK2Dk0uwjdK/C2xRtU4SHDINHn5El4gM09Z+lEmNpXtxuM1EeYgiYTI9cabgNf0w9363ovpScOyogiHNRnEiTuUTkZHrzWiHdRKEmUMG+yie6h8HWx2DJbbgGX2EX2rD4fYQb4LzW98VUIO0TwbJ9ce6BTQyCpMCo2+M/sQy7wcv3/wVowLfeJYcAAA== + + + dbo + + \ No newline at end of file diff --git a/Trunk/Server/Forum/Forum/Controllers/HomeController.cs b/Trunk/Server/Forum/Forum/Controllers/HomeController.cs index 7561f1d..68033ff 100644 --- a/Trunk/Server/Forum/Forum/Controllers/HomeController.cs +++ b/Trunk/Server/Forum/Forum/Controllers/HomeController.cs @@ -1,30 +1,51 @@ using System; using System.Collections.Generic; +using System.Data.Entity; using System.Linq; +using System.Threading.Tasks; using System.Web; using System.Web.Mvc; +using Forum.DataAccessLayer; +using Forum.DataAccessLayer.Models; namespace Forum.Controllers { + [Route("Home")] public class HomeController : Controller - { + { + public HomeController() + { + + _dbContext=new ApplicationDbContext(); + + + } + + private ApplicationDbContext _dbContext; + + [Route("Home")] public ActionResult Index() { - return View(); + var categories = _dbContext.Categories.ToList(); + return View(categories); } - public ActionResult About() + [Route("Home/Category/{name}")] + public async Task Category(string name) { - ViewBag.Message = "Your application description page."; + var category = await _dbContext.Categories.Include(q => q.Questions).FirstOrDefaultAsync(n=>n.CategoryName==name); - return View(); + if (category == null) + return HttpNotFound(); + + return View(category); } - public ActionResult Contact() + public async Task Question(int id) { - ViewBag.Message = "Your contact page."; + var question = await _dbContext.Questions.Include(a=>a.Answers.Select(p=>p.Professional)).FirstOrDefaultAsync(i => i.Id == id); - return View(); + return View(question); } } } \ No newline at end of file diff --git a/Trunk/Server/Forum/Forum/Forum.csproj b/Trunk/Server/Forum/Forum/Forum.csproj index 0fd26fb..127ef1d 100644 --- a/Trunk/Server/Forum/Forum/Forum.csproj +++ b/Trunk/Server/Forum/Forum/Forum.csproj @@ -217,8 +217,6 @@ - - @@ -240,9 +238,12 @@ + + + diff --git a/Trunk/Server/Forum/Forum/Views/Home/About.cshtml b/Trunk/Server/Forum/Forum/Views/Home/About.cshtml deleted file mode 100644 index 4b2d9e8..0000000 --- a/Trunk/Server/Forum/Forum/Views/Home/About.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@{ - ViewBag.Title = "About"; -} -

@ViewBag.Title.

-

@ViewBag.Message

- -

Use this area to provide additional information.

diff --git a/Trunk/Server/Forum/Forum/Views/Home/Category.cshtml b/Trunk/Server/Forum/Forum/Views/Home/Category.cshtml new file mode 100644 index 0000000..b0703d6 --- /dev/null +++ b/Trunk/Server/Forum/Forum/Views/Home/Category.cshtml @@ -0,0 +1,7 @@ +@model Forum.DataAccessLayer.Models.Category + +@{ + ViewBag.Title = Model.CategoryName; +} + +

@Model.CategoryName

diff --git a/Trunk/Server/Forum/Forum/Views/Home/Contact.cshtml b/Trunk/Server/Forum/Forum/Views/Home/Contact.cshtml deleted file mode 100644 index 0f4327e..0000000 --- a/Trunk/Server/Forum/Forum/Views/Home/Contact.cshtml +++ /dev/null @@ -1,17 +0,0 @@ -@{ - ViewBag.Title = "Contact"; -} -

@ViewBag.Title.

-

@ViewBag.Message

- -
- One Microsoft Way
- Redmond, WA 98052-6399
- P: - 425.555.0100 -
- -
- Support: Support@example.com
- Marketing: Marketing@example.com -
\ No newline at end of file diff --git a/Trunk/Server/Forum/Forum/Views/Home/Index.cshtml b/Trunk/Server/Forum/Forum/Views/Home/Index.cshtml index 32e1dd9..f57caf4 100644 --- a/Trunk/Server/Forum/Forum/Views/Home/Index.cshtml +++ b/Trunk/Server/Forum/Forum/Views/Home/Index.cshtml @@ -1,31 +1,18 @@ -@{ - ViewBag.Title = "Home Page"; +@model IEnumerable + +@{ + ViewBag.Title = "Strona Główna"; } -
-

ASP.NET

-

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.

-

Learn more »

-
+
    + + @{ + foreach (var category in Model) + { +
  • + @Html.ActionLink(category.CategoryName,"Category","Home",new{name=category.CategoryName}) +
  • + } + } +
-
-
-

Getting started

-

- ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that - enables a clean separation of concerns and gives you full control over markup - for enjoyable, agile development. -

-

Learn more »

-
-
-

Get more libraries

-

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

-

Learn more »

-
-
-

Web Hosting

-

You can easily find a web hosting company that offers the right mix of features and price for your applications.

-

Learn more »

-
-
\ No newline at end of file diff --git a/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml b/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml new file mode 100644 index 0000000..1a8d6a6 --- /dev/null +++ b/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml @@ -0,0 +1,7 @@ +@model Forum.DataAccessLayer.Models.Question + +@{ + ViewBag.Title = @Model.Title; +} + +

@Model.Title