Browse Source

jobcontroller small fixes

confirmation-email
Milad Karbasizadeh 11 years ago
parent
commit
38195e5e60
6 changed files with 54 additions and 11 deletions
  1. +17
    -0
      Sevomin.Models/Helpers/SevominUserManager.cs
  2. +15
    -0
      Sevomin.Models/Helpers/SevominUserStore.cs
  3. +2
    -0
      Sevomin.Models/Sevomin.Models.csproj
  4. +4
    -4
      Sevomin.Tests/Controllers/Job/NewJob.cs
  5. +4
    -3
      Sevomin.WebFrontend.Controllers/AccountController.cs
  6. +12
    -4
      Sevomin.WebFrontend.Controllers/JobController.cs

+ 17
- 0
Sevomin.Models/Helpers/SevominUserManager.cs View File

@ -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<User>
{
public SevominUserManager(IUserStore<User> store) : base(store)
{
this.UserValidator = new SevominUserValidator();
}
}
}

+ 15
- 0
Sevomin.Models/Helpers/SevominUserStore.cs View File

@ -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<User>
{
}
}

+ 2
- 0
Sevomin.Models/Sevomin.Models.csproj View File

@ -64,6 +64,7 @@
<Compile Include="Avalin.cs" />
<Compile Include="Dovomin.cs" />
<Compile Include="Helpers\EmailValidationAttribute.cs" />
<Compile Include="Helpers\SevominUserStore.cs" />
<Compile Include="Helpers\SevominUserValidator.cs" />
<Compile Include="Job.cs" />
<Compile Include="JobParameter.cs" />
@ -109,6 +110,7 @@
<Compile Include="Repositories\IRepository.cs" />
<Compile Include="Repositories\JobRepository.cs" />
<Compile Include="Repositories\ParameterRepository.cs" />
<Compile Include="Helpers\SevominUserManager.cs" />
<Compile Include="SignupViewModel.cs" />
<Compile Include="User.cs" />
<Compile Include="UsersDbContext.cs" />


+ 4
- 4
Sevomin.Tests/Controllers/Job/NewJob.cs View File

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


+ 4
- 3
Sevomin.WebFrontend.Controllers/AccountController.cs View File

@ -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<User>(new UserStore<User>(SevominDbContext.Current)))
: this(new SevominUserManager(new UserStore<User>(SevominDbContext.Current)))
{
}
public AccountController(UserManager<User> userManager)
public AccountController(SevominUserManager userManager)
{
UserManager = userManager;
UserManager.UserValidator = new Sevomin.Models.Helpers.SevominUserValidator();
}
public UserManager<User> UserManager { get; private set; }
public SevominUserManager UserManager { get; private set; }
private IAuthenticationManager AuthenticationManager
{


+ 12
- 4
Sevomin.WebFrontend.Controllers/JobController.cs View File

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


Loading…
Cancel
Save