Inicjalizacja HomeControllera

This commit is contained in:
Bartosz Chyzy 2018-12-01 23:31:52 +01:00
parent 5613acba1d
commit 0c2a9df2a9
13 changed files with 247 additions and 63 deletions

View File

@ -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; }

View File

@ -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; }

View File

@ -90,6 +90,10 @@
<Compile Include="Migrations\201812012143359_Email validation.Designer.cs">
<DependentUpon>201812012143359_Email validation.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201812012216378_Added Title.cs" />
<Compile Include="Migrations\201812012216378_Added Title.Designer.cs">
<DependentUpon>201812012216378_Added Title.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\MailService.cs" />
@ -118,6 +122,12 @@
<EmbeddedResource Include="Migrations\201812012143359_Email validation.resx">
<DependentUpon>201812012143359_Email validation.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201812012216378_Added Title.resx">
<DependentUpon>201812012216378_Added Title.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Repostories\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,29 @@
// <auto-generated />
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"); }
}
}
}

View File

@ -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");
}
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Target" xml:space="preserve">
<value>H4sIAAAAAAAEAO1d227kuBF9D5B/EPSUBN5uXzKDidG9C2/b3hgZXzLtWeTNoCW6LYwuvRI1YyPYL8tDPim/EFJXXiVSUqvlTTAvbZE8LBariqwiWfOff/178cNL4FtfYZx4Ubi0j2aHtgVDJ3K9cLO0U/T03Qf7h+9//7vFhRu8WD+X9U5IPdwyTJb2M0Lb0/k8cZ5hAJJZ4DlxlERPaOZEwRy40fz48PAv86OjOcQQNsayrMWnNEReALM/8J+rKHTgFqXAv45c6CfFd1yyzlCtGxDAZAscuLQvozgNZucAgTPHgUnyEbzC2LbOfA9gYtbQf7ItEIYRAgiTevo5gWsUR+FmvcUfgH//uoW43hPwE1gM4bSurjuaw2MymnndsIRy0gRFgSHg0UnBnjnfvBOT7Yp9mIEXmNHolYw6Y+LSPguTb4RhfFenKz8m1RQcnuUzM8ubH1hNlQ4qQcHyRP4dWKvUR2kMlyFMUQz8A+suffQ952/w9T76AsNlmPo+TTemHJcxH/Cnuzjawhi9foJPxWiuXNuas+3mfMOqGdUmH+lViE6ObesGdw4efViJBcWVNYpi+BMMYQwQdO8AQjAOCQbMGCv0zvWFGQTL3sjveyz1kg6bQbB6INxdiYPlGWunbV2Dl48w3KDnpY1/2tal9wLd8ksB/Dn0sDLjRihOW/u58Zwvw3dyA756m4yZXHf4zycsObgA+Lb1CfpZpeTZ2+Z6XMjaA1vvMo6CT5FfSTJT/LCO0tghHI/Ude5BvIFIn86/pzDJlVFCY1n4kPeU0ATyZVXPJXVChZJ8mrTFvNbhRs2mB4nN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njWD77heTYQO6yJZR+psJXwX9aIpdFEXybpQZ1dR8q+Fd218k/Ns/ynAmNQoYqFgsBrjcpJXEerUcxPP+DUMYxhtVzxW3QFjdpfgaxi20Mokf6fZnyk7Seg1HDvYFZZ+rtB/6DtK3iXNKbW3Qe4wNZcsE5fsSktHFk0v65ZUF2V6OIpGG2TZEh8G4K1zGpLz+fyvc5h4mxqCPGcJocNsmqs6V+FTVO7dOYrKKtxp4DVEwCVvT2LkPQEH4WJyXTH7/1SyK2Dk0uwjdK/C2xRtU4SHDINHn5El4gM09Z+lEmNpXtxuM1EeYgiYTI9cabgNf0w9363ovpScOyogiHNRnEiTuUTkZHrzWiHdRKEmUMG+yie6h8HWx2DJbbgGX2EX2rD4fYQb4LzW98VUIO0TwbJ9ce6BTQyCpMCo2+M/sQy7wcv3/wVowLfeJYcAAA==</value>
</data>
<data name="DefaultSchema" xml:space="preserve">
<value>dbo</value>
</data>
</root>

View File

@ -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<ActionResult> 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<ActionResult> 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);
}
}
}

View File

@ -217,8 +217,6 @@
<Content Include="Views\_ViewStart.cshtml" />
<Content Include="Views\Shared\Error.cshtml" />
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Home\About.cshtml" />
<Content Include="Views\Home\Contact.cshtml" />
<Content Include="Views\Home\Index.cshtml" />
<Content Include="Views\Account\_ExternalLoginsListPartial.cshtml" />
<Content Include="Views\Account\ConfirmEmail.cshtml" />
@ -240,9 +238,12 @@
<Content Include="Views\Manage\VerifyPhoneNumber.cshtml" />
<Content Include="Views\Shared\Lockout.cshtml" />
<Content Include="Views\Shared\_LoginPartial.cshtml" />
<Content Include="Views\Home\Category.cshtml" />
<Content Include="Views\Home\Question.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="ViewModels\" />
</ItemGroup>
<ItemGroup>
<Content Include="fonts\glyphicons-halflings-regular.woff2" />

View File

@ -1,7 +0,0 @@
@{
ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
<p>Use this area to provide additional information.</p>

View File

@ -0,0 +1,7 @@
@model Forum.DataAccessLayer.Models.Category
@{
ViewBag.Title = Model.CategoryName;
}
<h2>@Model.CategoryName</h2>

View File

@ -1,17 +0,0 @@
@{
ViewBag.Title = "Contact";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
<address>
One Microsoft Way<br />
Redmond, WA 98052-6399<br />
<abbr title="Phone">P:</abbr>
425.555.0100
</address>
<address>
<strong>Support:</strong> <a href="mailto:Support@example.com">Support@example.com</a><br />
<strong>Marketing:</strong> <a href="mailto:Marketing@example.com">Marketing@example.com</a>
</address>

View File

@ -1,31 +1,18 @@
@{
ViewBag.Title = "Home Page";
@model IEnumerable<Forum.DataAccessLayer.Models.Category>
@{
ViewBag.Title = "Strona Główna";
}
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>
<ul>
@{
foreach (var category in Model)
{
<li>
@Html.ActionLink(category.CategoryName,"Category","Home",new{name=category.CategoryName})
</li>
}
}
</ul>
<div class="row">
<div class="col-md-4">
<h2>Getting started</h2>
<p>
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.
</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Web Hosting</h2>
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
</div>
</div>

View File

@ -0,0 +1,7 @@
@model Forum.DataAccessLayer.Models.Question
@{
ViewBag.Title = @Model.Title;
}
<h2>@Model.Title</h2>