Dodano zapisywanie odpowiedzi jako profesionalista

This commit is contained in:
Bartosz Chyży 2018-12-18 13:39:47 +01:00
parent 70bdf02761
commit c1a6d311e0
6 changed files with 110 additions and 77 deletions

View File

@ -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)
{

View File

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

View File

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

View File

@ -17,6 +17,12 @@
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FullName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FullName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">

View File

@ -1,21 +1,30 @@
@model Forum.ViewModels.AddAnswerViewModel
@{
ViewBag.Title = "AddAnswer";
}
<div class="add-answer">
<h2>Dodaj odpowiedź</h2>
@model Forum.ViewModels.AddAnswerViewModel
@{
ViewBag.Title = "AddAnswer";
}
<div class="add-answer">
<h2>Dodaj odpowiedź</h2>
<hr style="border-top: 1px solid #d3d3d3; margin-bottom: 3rem;" />
@using (Html.BeginForm("AddAnswer", "Home", FormMethod.Post))
{
<div class="form-group">
@Html.EditorFor(model => model.Nick, new { htmlAttributes = new { @class = "form-control", placeholder="Nazwa użytkownika" } })
@using (Html.BeginForm("AddAnswer", "Home", FormMethod.Post))
{
<div class="form-group">
@{
if (User.Identity.IsAuthenticated)
{
<label>Odpowiedz jako @User.Identity.Name</label>
}
else
{
@Html.EditorFor(model => model.Nick, new { htmlAttributes = new { @class = "form-control", placeholder = "Nazwa użytkownika" } })
}
}
</div>
<div class="form-group">
@ -24,13 +33,13 @@
</div>
@Html.HiddenFor(model=>model.QuestionId)
<input type="submit" value="Zgłoś odpowiedź" />
}
</div>
@Html.HiddenFor(model=>model.QuestionId)
<input type="submit" value="Zgłoś odpowiedź" />
}
</div>

View File

@ -1,49 +1,59 @@
@model Forum.DataAccessLayer.Models.Question
@{
ViewBag.Title = @Model.Title;
}
<div class="answer-list__question">
<div class="answer-list__info">
<h2>@Model.Title</h2>
@Model.PostDate
</div>
@using WebGrease.Css.Extensions
@model Forum.DataAccessLayer.Models.Question
@{
ViewBag.Title = @Model.Title;
}
<div class="answer-list__question">
<div class="answer-list__info">
<h2>@Model.Title</h2>
@Model.PostDate
</div>
<hr style="border-top: 1px solid #d3d3d3" />
<div class="answer-list__question__content">
@Model.Content
</div>
</div>
<h3 class="answer-list__heading">Odpowiedzi</h3>
<ul class="answer-list__answer">
@{
foreach (var answer in Model.Answers)
{
<li class="answer-list__single-answer">
<div class="answer-list__answer__info">
<span class="username">@answer.Nick napisał(a)</span>
@answer.Date
</div>
<div class="answer-list__content">
@answer.Content
</div>
</li>
}
}
</ul>
<div class="answer-list__add-btn">
<div class="answer-list__question__content">
@Model.Content
</div>
</div>
<h3 class="answer-list__heading">Odpowiedzi</h3>
<ul class="answer-list__answer">
@{
foreach (var answer in Model.Answers)
{
<li class="answer-list__single-answer">
<div class="answer-list__answer__info" >
@{
if (answer.Professional != null)
{
<span class="username">@answer.Professional.FullName napisał(a)</span>
}
else
{
<span class="username">@answer.Nick napisał(a)</span>
}
}
@answer.Date
</div>
<div class="answer-list__content">
@answer.Content
</div>
</li>
}
}
</ul>
<div class="answer-list__add-btn">
@Html.ActionLink("Dodaj odpowiedź", "AddAnswer", new { id = @Model.Id })
</div>
</div>