Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #83 from AppliedIS/feature-submit
Browse files Browse the repository at this point in the history
Feature submit
  • Loading branch information
MrMatt57 committed Oct 26, 2016
2 parents 6d299fb + 5c7e888 commit 82be84b
Show file tree
Hide file tree
Showing 44 changed files with 1,397 additions and 43 deletions.
39 changes: 39 additions & 0 deletions DOL.WHD.Section14c.Api/App_Start/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Linq;
using AutoMapper;
using AutoMapper.Mappers;
using DOL.WHD.Section14c.Domain.Models.Submission;
using DOL.WHD.Section14c.Domain.Models.Submission.Dto;

namespace DOL.WHD.Section14c.Api
{
public static class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.AddConditionalObjectMapper().Where((s, d) => s.Name == d.Name + "Dto");
// many to many relationships
cfg.CreateMap<ApplicationSubmissionDto, ApplicationSubmission>()
.AfterMap(
(src, dest) =>
dest.EstablishmentType =
src.EstablishmentTypeId.Select(
x => new ApplicationSubmissionEstablishmentType {EstablishmentTypeId = x, ApplicationSubmissionId = dest.Id}).ToList())
.AfterMap(
(src, dest) =>
dest.ProvidingFacilitiesDeductionType =
src.ProvidingFacilitiesDeductionTypeId.Select(
x => new ApplicationSubmissionProvidingFacilitiesDeductionType { ProvidingFacilitiesDeductionTypeId = x, ApplicationSubmissionId = dest.Id }).ToList());
cfg.CreateMap<WorkSiteDto, WorkSite>()
.AfterMap(
(src, dest) =>
dest.WorkSiteType =
src.WorkSiteTypeId.Select(
x => new WorkSiteWorkSiteType() { WorkSiteTypeId = x, WorkSiteId = dest.Id }).ToList());
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static void Register()
container.Register<ISaveService, SaveService>(Lifestyle.Scoped);
container.Register<IIdentityService, IdentityService>(Lifestyle.Scoped);
container.Register<IFileRepository>(() => new FileRepository(ConfigurationManager.AppSettings["AttachmentRepositoryRootFolder"]), Lifestyle.Scoped);
container.Register<IApplicationRepository, ApplicationRepository>(Lifestyle.Scoped);
container.Register<IApplicationService, ApplicationService>(Lifestyle.Scoped);

// This is an extension method from the integration package.
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
Expand Down
41 changes: 41 additions & 0 deletions DOL.WHD.Section14c.Api/Controllers/ApplicationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Threading.Tasks;
using System.Web.Http;
using AutoMapper;
using DOL.WHD.Section14c.Business;
using DOL.WHD.Section14c.Domain.Models.Submission;
using DOL.WHD.Section14c.Domain.Models.Submission.Dto;

namespace DOL.WHD.Section14c.Api.Controllers
{
[Authorize]
public class ApplicationController : ApiController
{
private readonly IIdentityService _identityService;
private readonly IApplicationService _applicationService;
public ApplicationController(IIdentityService identityService, IApplicationService applicationService)
{
_identityService = identityService;
_applicationService = applicationService;
}

public async Task<IHttpActionResult> Submit([FromBody]ApplicationSubmissionDto submissionDto)
{
var submission = Mapper.Map<ApplicationSubmission>(submissionDto);
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

// make sure user has rights to the EIN
var hasEINClaim = _identityService.UserHasEINClaim(User, submission.EIN);
if (!hasEINClaim)
{
return Unauthorized();
}

await _applicationService.SubmitApplicationAsync(submission);
return Created("", (object)null);
}
}
}
6 changes: 6 additions & 0 deletions DOL.WHD.Section14c.Api/DOL.WHD.Section14c.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=5.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.5.1.1\lib\net45\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework6.Npgsql, Version=3.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework6.Npgsql.3.1.1\lib\net45\EntityFramework6.Npgsql.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -205,6 +209,7 @@
<ItemGroup>
<Compile Include="App_Start\DependencyResolutionConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\AutoMapperConfiguration.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\Startup.Auth.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
Expand Down Expand Up @@ -237,6 +242,7 @@
<Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\ApplicationController.cs" />
<Compile Include="Controllers\AttachmentController.cs" />
<Compile Include="Controllers\ResponseController.cs" />
<Compile Include="Controllers\SaveController.cs" />
Expand Down
3 changes: 3 additions & 0 deletions DOL.WHD.Section14c.Api/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ protected void Application_Start()

// use camel cased JSON in Web API
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

// Automapper
AutoMapperConfiguration.Configure();
}
}
}
1 change: 1 addition & 0 deletions DOL.WHD.Section14c.Api/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="5.1.1" targetFramework="net452" />
<package id="EntityFramework" version="6.1.3" targetFramework="net461" />
<package id="EntityFramework6.Npgsql" version="3.1.1" targetFramework="net461" />
<package id="Microsoft.AspNet.Cors" version="5.2.3" targetFramework="net452" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IApplicationService.cs" />
<Compile Include="IIdentityService.cs" />
<Compile Include="IResponseService.cs" />
<Compile Include="ISaveService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="IReCaptchaService.cs" />
<Compile Include="Services\ApplicationService.cs" />
<Compile Include="Services\IdentityService.cs" />
<Compile Include="Services\ReCaptchaService.cs" />
<Compile Include="Services\ResponseService.cs" />
Expand Down
10 changes: 10 additions & 0 deletions DOL.WHD.Section14c.Business/IApplicationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using DOL.WHD.Section14c.Domain.Models.Submission;

namespace DOL.WHD.Section14c.Business
{
public interface IApplicationService
{
Task<int> SubmitApplicationAsync(ApplicationSubmission submission);
}
}
20 changes: 20 additions & 0 deletions DOL.WHD.Section14c.Business/Services/ApplicationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Threading.Tasks;
using DOL.WHD.Section14c.DataAccess;
using DOL.WHD.Section14c.Domain.Models.Submission;

namespace DOL.WHD.Section14c.Business.Services
{
public class ApplicationService : IApplicationService
{
private readonly IApplicationRepository _applicationRepository;
public ApplicationService(IApplicationRepository applicationRepository)
{
_applicationRepository = applicationRepository;
}

public Task<int> SubmitApplicationAsync(ApplicationSubmission submission)
{
return _applicationRepository.AddAsync(submission);
}
}
}
22 changes: 9 additions & 13 deletions DOL.WHD.Section14c.DataAccess/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<ApplicationSubmission>()
.HasMany(s => s.EstablishmentType)
.WithMany()
.Map(m => m.ToTable("AppSubmissionEstablishmentType"));
modelBuilder.Entity<ApplicationSubmissionEstablishmentType>()
.ToTable("AppSubmissionEstablishmentType")
.HasKey(k => new {k.ApplicationSubmissionId, k.EstablishmentTypeId});

modelBuilder.Entity<ApplicationSubmission>()
.HasMany(s => s.ProvidingFacilitiesDeductionType)
.WithMany()
.Map(m => m.ToTable("AppSubmissionFacilitiesDeductionType"));

modelBuilder.Entity<WorkSite>()
.HasMany(s => s.WorkSiteType)
.WithMany()
.Map(m => m.ToTable("WorkSiteWorkSiteType"));
modelBuilder.Entity<ApplicationSubmissionProvidingFacilitiesDeductionType>()
.ToTable("AppSubmissionFacilitiesDeductionType")
.HasKey(k => new { k.ApplicationSubmissionId, k.ProvidingFacilitiesDeductionTypeId });

modelBuilder.Entity<WorkSiteWorkSiteType>()
.ToTable("WorkSiteWorkSiteType")
.HasKey(k => new { k.WorkSiteId, k.WorkSiteTypeId });
}

public override int SaveChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@
<Compile Include="Migrations\201610261540007_AuditFields.Designer.cs">
<DependentUpon>201610261540007_AuditFields.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201610261825305_KeyUpdates.cs" />
<Compile Include="Migrations\201610261825305_KeyUpdates.Designer.cs">
<DependentUpon>201610261825305_KeyUpdates.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repositories\ApplicationRepository.cs" />
<Compile Include="Repositories\FileRepository.cs" />
<Compile Include="IApplicationRepository.cs" />
<Compile Include="Repositories\ResponseRepository.cs" />
<Compile Include="Repositories\SaveRepository.cs" />
<Compile Include="Validators\Section14cPasswordValidator.cs" />
Expand Down Expand Up @@ -237,6 +243,9 @@
<EmbeddedResource Include="Migrations\201610261540007_AuditFields.resx">
<DependentUpon>201610261540007_AuditFields.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201610261825305_KeyUpdates.resx">
<DependentUpon>201610261825305_KeyUpdates.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
14 changes: 14 additions & 0 deletions DOL.WHD.Section14c.DataAccess/IApplicationRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using DOL.WHD.Section14c.Domain.Models.Submission;

namespace DOL.WHD.Section14c.DataAccess
{
public interface IApplicationRepository : IDisposable
{
IQueryable<ApplicationSubmission> Get();
Task<int> AddAsync(ApplicationSubmission submission);
Task<int> SaveChangesAsync();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 82be84b

Please sign in to comment.