From c1a6d311e05f057899f6667d34247558b8cd3085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Chy=C5=BCy?= Date: Tue, 18 Dec 2018 13:39:47 +0100 Subject: [PATCH] Dodano zapisywanie odpowiedzi jako profesionalista --- .../Forum/Controllers/AccountController.cs | 2 +- .../Forum/Forum/Controllers/HomeController.cs | 6 +- .../Forum/Forum/Models/AccountViewModels.cs | 8 +- .../Forum/Forum/Views/Account/Register.cshtml | 6 ++ .../Forum/Forum/Views/Home/AddAnswer.cshtml | 63 ++++++----- .../Forum/Forum/Views/Home/Question.cshtml | 102 ++++++++++-------- 6 files changed, 110 insertions(+), 77 deletions(-) diff --git a/Trunk/Server/Forum/Forum/Controllers/AccountController.cs b/Trunk/Server/Forum/Forum/Controllers/AccountController.cs index a1d232b..1d438b5 100644 --- a/Trunk/Server/Forum/Forum/Controllers/AccountController.cs +++ b/Trunk/Server/Forum/Forum/Controllers/AccountController.cs @@ -151,7 +151,7 @@ namespace Forum.Controllers { if (ModelState.IsValid) { - var user = new ProfessionalUser() { UserName = model.Email, Email = model.Email }; + var user = new ProfessionalUser() { UserName = model.Email, Email = model.Email,FullName = model.FullName}; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { diff --git a/Trunk/Server/Forum/Forum/Controllers/HomeController.cs b/Trunk/Server/Forum/Forum/Controllers/HomeController.cs index 8574efb..826ca02 100644 --- a/Trunk/Server/Forum/Forum/Controllers/HomeController.cs +++ b/Trunk/Server/Forum/Forum/Controllers/HomeController.cs @@ -6,6 +6,7 @@ using System.Web.Mvc; using Forum.DataAccessLayer; using Forum.DataAccessLayer.Models; using Forum.ViewModels; +using Microsoft.AspNet.Identity; namespace Forum.Controllers { @@ -99,11 +100,14 @@ namespace Forum.Controllers if (question == null) return HttpNotFound(); + var user = _dbContext.Users.Find(User.Identity.GetUserId()); + var answer = new Answer() { Content = model.Content, Nick = model.Nick, - Date = DateTime.Now + Date = DateTime.Now, + Professional = user }; question.Answers.Add(answer); diff --git a/Trunk/Server/Forum/Forum/Models/AccountViewModels.cs b/Trunk/Server/Forum/Forum/Models/AccountViewModels.cs index a8aa5f2..294ec2d 100644 --- a/Trunk/Server/Forum/Forum/Models/AccountViewModels.cs +++ b/Trunk/Server/Forum/Forum/Models/AccountViewModels.cs @@ -72,13 +72,17 @@ namespace Forum.Models [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] - [Display(Name = "Password")] + [Display(Name = "Hasło")] public string Password { get; set; } [DataType(DataType.Password)] - [Display(Name = "Confirm password")] + [Display(Name = "Potwierdź hasło")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; } + + [Display(Name = "Imie i nazwisko")] + [Required] + public string FullName { get; set; } } public class ResetPasswordViewModel diff --git a/Trunk/Server/Forum/Forum/Views/Account/Register.cshtml b/Trunk/Server/Forum/Forum/Views/Account/Register.cshtml index 82b8ff0..da03ca8 100644 --- a/Trunk/Server/Forum/Forum/Views/Account/Register.cshtml +++ b/Trunk/Server/Forum/Forum/Views/Account/Register.cshtml @@ -17,6 +17,12 @@ @Html.TextBoxFor(m => m.Email, new { @class = "form-control" }) +
+ @Html.LabelFor(m => m.FullName, new { @class = "col-md-2 control-label" }) +
+ @Html.TextBoxFor(m => m.FullName, new { @class = "form-control" }) +
+
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
diff --git a/Trunk/Server/Forum/Forum/Views/Home/AddAnswer.cshtml b/Trunk/Server/Forum/Forum/Views/Home/AddAnswer.cshtml index d1a71aa..73b0be8 100644 --- a/Trunk/Server/Forum/Forum/Views/Home/AddAnswer.cshtml +++ b/Trunk/Server/Forum/Forum/Views/Home/AddAnswer.cshtml @@ -1,21 +1,30 @@ -@model Forum.ViewModels.AddAnswerViewModel -@{ - ViewBag.Title = "AddAnswer"; -} - - -
- -

Dodaj odpowiedź

- +@model Forum.ViewModels.AddAnswerViewModel +@{ + ViewBag.Title = "AddAnswer"; +} + + +
+ +

Dodaj odpowiedź

+
- - -@using (Html.BeginForm("AddAnswer", "Home", FormMethod.Post)) -{ - -
- @Html.EditorFor(model => model.Nick, new { htmlAttributes = new { @class = "form-control", placeholder="Nazwa użytkownika" } }) + + +@using (Html.BeginForm("AddAnswer", "Home", FormMethod.Post)) +{ + +
+ @{ + if (User.Identity.IsAuthenticated) + { + + } + else + { + @Html.EditorFor(model => model.Nick, new { htmlAttributes = new { @class = "form-control", placeholder = "Nazwa użytkownika" } }) + } + }
@@ -24,13 +33,13 @@
- - - - - @Html.HiddenFor(model=>model.QuestionId) - - -} - -
+ + + + + @Html.HiddenFor(model=>model.QuestionId) + + +} + +
diff --git a/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml b/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml index 080fecd..657c4b1 100644 --- a/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml +++ b/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml @@ -1,49 +1,59 @@ -@model Forum.DataAccessLayer.Models.Question - -@{ - ViewBag.Title = @Model.Title; -} - - -
- - -
-

@Model.Title

-@Model.PostDate - -
+@using WebGrease.Css.Extensions +@model Forum.DataAccessLayer.Models.Question + +@{ + ViewBag.Title = @Model.Title; +} + + +
+ + +
+

@Model.Title

+@Model.PostDate + +

- - -
- @Model.Content -
- -
- - -

Odpowiedzi

-
    - @{ - foreach (var answer in Model.Answers) - { -
  • -
    - @answer.Nick napisał(a) - @answer.Date -
    -
    - @answer.Content -
    -
  • - } - } -
- -
+ + +
+ @Model.Content +
+ +
+ + +

Odpowiedzi

+
    + @{ + foreach (var answer in Model.Answers) + { +
  • +
    + @{ + if (answer.Professional != null) + { + @answer.Professional.FullName napisał(a) + } + else + { + @answer.Nick napisał(a) + } + } + @answer.Date +
    +
    + @answer.Content +
    +
  • + } + } +
+ +
@Html.ActionLink("Dodaj odpowiedź", "AddAnswer", new { id = @Model.Id }) - -
- + +
+