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) 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); var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded) if (result.Succeeded)
{ {

View File

@ -6,6 +6,7 @@ using System.Web.Mvc;
using Forum.DataAccessLayer; using Forum.DataAccessLayer;
using Forum.DataAccessLayer.Models; using Forum.DataAccessLayer.Models;
using Forum.ViewModels; using Forum.ViewModels;
using Microsoft.AspNet.Identity;
namespace Forum.Controllers namespace Forum.Controllers
{ {
@ -99,11 +100,14 @@ namespace Forum.Controllers
if (question == null) if (question == null)
return HttpNotFound(); return HttpNotFound();
var user = _dbContext.Users.Find(User.Identity.GetUserId());
var answer = new Answer() var answer = new Answer()
{ {
Content = model.Content, Content = model.Content,
Nick = model.Nick, Nick = model.Nick,
Date = DateTime.Now Date = DateTime.Now,
Professional = user
}; };
question.Answers.Add(answer); question.Answers.Add(answer);

View File

@ -72,13 +72,17 @@ namespace Forum.Models
[Required] [Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)] [DataType(DataType.Password)]
[Display(Name = "Password")] [Display(Name = "Hasło")]
public string Password { get; set; } public string Password { get; set; }
[DataType(DataType.Password)] [DataType(DataType.Password)]
[Display(Name = "Confirm password")] [Display(Name = "Potwierdź hasło")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; } public string ConfirmPassword { get; set; }
[Display(Name = "Imie i nazwisko")]
[Required]
public string FullName { get; set; }
} }
public class ResetPasswordViewModel public class ResetPasswordViewModel

View File

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

View File

@ -15,7 +15,16 @@
{ {
<div class="form-group"> <div class="form-group">
@Html.EditorFor(model => model.Nick, new { htmlAttributes = new { @class = "form-control", placeholder="Nazwa użytkownika" } }) @{
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>
<div class="form-group"> <div class="form-group">

View File

@ -1,4 +1,5 @@
@model Forum.DataAccessLayer.Models.Question @using WebGrease.Css.Extensions
@model Forum.DataAccessLayer.Models.Question
@{ @{
ViewBag.Title = @Model.Title; ViewBag.Title = @Model.Title;
@ -29,10 +30,19 @@
foreach (var answer in Model.Answers) foreach (var answer in Model.Answers)
{ {
<li class="answer-list__single-answer"> <li class="answer-list__single-answer">
<div class="answer-list__answer__info"> <div class="answer-list__answer__info" >
<span class="username">@answer.Nick napisał(a)</span> @{
@answer.Date if (answer.Professional != null)
</div> {
<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"> <div class="answer-list__content">
@answer.Content @answer.Content
</div> </div>