Permalink
Switch branches/tags
Nothing to show
Find file Copy path
71c4285 May 5, 2017
Mark Macneil finishing post
0 contributors

Users who have contributed to this file

48 lines (39 sloc) 1.51 KB
using Microsoft.AspNetCore.Mvc;
using DotNetGigs.ViewModels;
using AutoMapper;
using DotNetGigs.Models.Entities;
using Microsoft.AspNetCore.Identity;
using DotNetGigs.Helpers;
using System.Threading.Tasks;
using DotNetGigs.Data;
namespace DotNetGigs.Controllers
{
[Route("api/[controller]")]
public class AccountsController : Controller
{
private readonly ApplicationDbContext _appDbContext;
private readonly UserManager<AppUser> _userManager;
private readonly IMapper _mapper;
public AccountsController(UserManager<AppUser> userManager,IMapper mapper,ApplicationDbContext appDbContext)
{
_userManager = userManager;
_mapper=mapper;
_appDbContext=appDbContext;
}
// POST api/accounts
[HttpPost]
public async Task<IActionResult> Post([FromBody]RegistrationViewModel model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var userIdentity=_mapper.Map<AppUser>(model);
var result = await _userManager.CreateAsync(userIdentity, model.Password);
if (!result.Succeeded) return new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState));
await _appDbContext.JobSeekers.AddAsync(new JobSeeker{IdentityId=userIdentity.Id, Location=model.Location});
await _appDbContext.SaveChangesAsync();
return new OkObjectResult("Account created");
}
}
}