diff --git a/Sevomin.Models/Helpers/SevominUserManager.cs b/Sevomin.Models/Helpers/SevominUserManager.cs new file mode 100644 index 0000000..0d9c79d --- /dev/null +++ b/Sevomin.Models/Helpers/SevominUserManager.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNet.Identity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sevomin.Models.Helpers +{ + public class SevominUserManager : UserManager + { + public SevominUserManager(IUserStore store) : base(store) + { + this.UserValidator = new SevominUserValidator(); + } + } +} diff --git a/Sevomin.Models/Helpers/SevominUserStore.cs b/Sevomin.Models/Helpers/SevominUserStore.cs new file mode 100644 index 0000000..dfb3c8c --- /dev/null +++ b/Sevomin.Models/Helpers/SevominUserStore.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.EntityFramework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sevomin.Models.Helpers +{ + public class SevominUserStore : UserStore + { + + } +} diff --git a/Sevomin.Models/Sevomin.Models.csproj b/Sevomin.Models/Sevomin.Models.csproj index 07abf52..6e08045 100644 --- a/Sevomin.Models/Sevomin.Models.csproj +++ b/Sevomin.Models/Sevomin.Models.csproj @@ -64,6 +64,7 @@ + @@ -109,6 +110,7 @@ + diff --git a/Sevomin.Tests/Controllers/Job/NewJob.cs b/Sevomin.Tests/Controllers/Job/NewJob.cs index fcf7bf3..4b4f250 100644 --- a/Sevomin.Tests/Controllers/Job/NewJob.cs +++ b/Sevomin.Tests/Controllers/Job/NewJob.cs @@ -19,24 +19,24 @@ namespace Sevomin.Tests.Controllers.Job } [TestMethod] - public void Returns_View_NewJob_JobController() + public async void Returns_View_NewJob_JobController() { // Arrange JobController cut = GetCUT(); // Act - var result = cut.NewJob() as ViewResult; + var result = (await cut.NewJob()) as ViewResult; // Assert Assert.IsNotNull(result); Assert.AreEqual(string.Empty, result.ViewName); } [TestMethod] - public void Returns_EmptyJobModel_NewJob_JobController() + public async void Returns_EmptyJobModel_NewJob_JobController() { // Arrange JobController cut = GetCUT(); // Act - var result = cut.NewJob() as ViewResult; + var result = (await cut.NewJob()) as ViewResult; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Model); diff --git a/Sevomin.WebFrontend.Controllers/AccountController.cs b/Sevomin.WebFrontend.Controllers/AccountController.cs index 3f2568f..8c02912 100644 --- a/Sevomin.WebFrontend.Controllers/AccountController.cs +++ b/Sevomin.WebFrontend.Controllers/AccountController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Owin.Security; using Sevomin.Models; +using Sevomin.Models.Helpers; using System; using System.Threading.Tasks; using System.Web; @@ -12,17 +13,17 @@ namespace Sevomin.WebFrontend.Controllers public class AccountController : BaseController { public AccountController() - : this(new UserManager(new UserStore(SevominDbContext.Current))) + : this(new SevominUserManager(new UserStore(SevominDbContext.Current))) { } - public AccountController(UserManager userManager) + public AccountController(SevominUserManager userManager) { UserManager = userManager; UserManager.UserValidator = new Sevomin.Models.Helpers.SevominUserValidator(); } - public UserManager UserManager { get; private set; } + public SevominUserManager UserManager { get; private set; } private IAuthenticationManager AuthenticationManager { diff --git a/Sevomin.WebFrontend.Controllers/JobController.cs b/Sevomin.WebFrontend.Controllers/JobController.cs index effa675..68829e3 100644 --- a/Sevomin.WebFrontend.Controllers/JobController.cs +++ b/Sevomin.WebFrontend.Controllers/JobController.cs @@ -6,26 +6,34 @@ using System.Threading.Tasks; using System.Web.Mvc; using Sevomin.Models; using Sevomin.Models.Repositories; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.EntityFramework; +using Sevomin.Models.Helpers; namespace Sevomin.WebFrontend.Controllers { public class JobController : AuthorizedController { IJobRepository _JobRepository; + public SevominUserManager UserManager { get; private set; } public JobController() + : this(JobRepository.Current, new SevominUserManager(new UserStore(SevominDbContext.Current))) { - _JobRepository = JobRepository.Current; } - public JobController(IJobRepository jobRepository) + public JobController(IJobRepository jobRepository, SevominUserManager userManager) { _JobRepository = jobRepository; + UserManager = userManager; } - public ActionResult NewJob() + public async Task NewJob() { - Avalin avalin = (Avalin)User; //???? + User u = await UserManager.FindByNameAsync(User.Identity.Name); + if (u == null) + throw new InvalidOperationException("شما خیلی هنرمندی! به ما هم بگو چجوری!"); + Avalin avalin = (Avalin)u; Job job = _JobRepository.GetEmptyJobFor(avalin); JobViewModel jvm = new JobViewModel(job); return View(jvm);