Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Application/App/AppServiceBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Application.Interfaces;
using Domain.Interfaces.Services;
using System;
using System.Collections.Generic;

namespace Application
{
public class AppServiceBase<TEntity> : IAppServiceBase<TEntity> where TEntity : class
{
private readonly IServiceBase<TEntity> _serviceBase;

public AppServiceBase(IServiceBase<TEntity> serviceBase)
{
_serviceBase = serviceBase;
}

public void Add(TEntity obj)
{
_serviceBase.Add(obj);
}

public IEnumerable<TEntity> GetAll()
{
return _serviceBase.GetAll();
}

public TEntity GetById(int id)
{
return _serviceBase.GetById(id);
}

public void Remove(TEntity obj)
{
_serviceBase.Remove(obj);
}

public void Update(TEntity obj)
{
_serviceBase.Update(obj);
}
}
}
17 changes: 17 additions & 0 deletions Application/App/NotaFiscalAppService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Application.Interfaces;
using Domain.Entities;
using Domain.Interfaces.Services;

namespace Application
{
public class NotaFiscalAppService : AppServiceBase<NotaFiscal>, INotaFiscalAppService
{
private readonly INotaFiscalService _notaFiscalService;

public NotaFiscalAppService(INotaFiscalService notaFiscalService)
: base(notaFiscalService)
{
_notaFiscalService = notaFiscalService;
}
}
}
27 changes: 19 additions & 8 deletions Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,33 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=6.2.2.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.2.2\lib\net45\AutoMapper.dll</HintPath>
<Reference Include="AutoMapper, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.2.1\lib\net40\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="AutoMapper.Net4, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.2.1\lib\net40\AutoMapper.Net4.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="App\AppServiceBase.cs" />
<Compile Include="AutoMapper\AutoMapperConfig.cs" />
<Compile Include="AutoMapper\MappingProfile\DomainToViewModelMappingProfile.cs" />
<Compile Include="AutoMapper\MappingProfile\ViewModelToDomainMappingProfile.cs" />
<Compile Include="Interfaces\IAppServiceBase.cs" />
<Compile Include="Interfaces\INotaFiscalAppService.cs" />
<Compile Include="App\NotaFiscalAppService.cs" />
<Compile Include="Model\NotaFiscalViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -56,11 +72,6 @@
<Name>Domain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="App\" />
<Folder Include="AutoMapper\MappingProfile\" />
<Folder Include="Interfaces\" />
<Folder Include="Model\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 4 additions & 2 deletions Application/AutoMapper/AutoMapperConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutoMapper;
using Application.AutoMapper.MappingProfile;
using AutoMapper;

namespace Application.AutoMapper
{
Expand All @@ -8,7 +9,8 @@ public static void RegisterMappings()
{
Mapper.Initialize(x =>
{

x.AddProfile<DomainToViewModelMappingProfile>();
x.AddProfile<ViewModelToDomainMappingProfile>();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Application.Model;
using AutoMapper;
using Domain.Entities;

namespace Application.AutoMapper.MappingProfile
{
public class DomainToViewModelMappingProfile : Profile
{
protected override void Configure()
{
Mapper.CreateMap<NotaFiscalViewModel, NotaFiscal>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Application.Model;
using AutoMapper;
using Domain.Entities;

namespace Application.AutoMapper.MappingProfile
{
public class ViewModelToDomainMappingProfile : Profile
{
protected override void Configure()
{
Mapper.CreateMap<NotaFiscal, NotaFiscalViewModel>();
}
}
}
17 changes: 17 additions & 0 deletions Application/Interfaces/IAppServiceBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace Application.Interfaces
{
public interface IAppServiceBase<TEntity> where TEntity : class
{
void Add(TEntity obj);

TEntity GetById(int id);

IEnumerable<TEntity> GetAll();

void Update(TEntity obj);

void Remove(TEntity obj);
}
}
8 changes: 8 additions & 0 deletions Application/Interfaces/INotaFiscalAppService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Domain.Entities;

namespace Application.Interfaces
{
public interface INotaFiscalAppService : IAppServiceBase<NotaFiscal>
{
}
}
26 changes: 26 additions & 0 deletions Application/Model/NotaFiscalViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.ComponentModel.DataAnnotations;

namespace Application.Model
{
public class NotaFiscalViewModel
{
[Key]
public int Id { get; set; }

[Required(ErrorMessage = "O numero da nota fiscal é obrigatório.")]
public string Numero { get; set; }

[Required(ErrorMessage = "O valor total da nota fiscal é obrigatório.")]
public decimal ValorTotal { get; set; }

[Required(ErrorMessage = "A data da nota fiscal é obrigatória.")]
public DateTime Data { get; set; }

[Required(ErrorMessage = "O CNPJ do emissor da nota fiscal é obrigatório.")]
public string CNPJEmissor { get; set; }

[Required(ErrorMessage = "O CNPJ do destinatário da nota fiscal é obrigatório.")]
public string CNPJDestinatario { get; set; }
}
}
3 changes: 2 additions & 1 deletion Application/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="6.2.2" targetFramework="net452" />
<package id="AutoMapper" version="3.2.1" targetFramework="net452" />
<package id="EntityFramework" version="6.2.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net452" />
</packages>
3 changes: 2 additions & 1 deletion Data/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<configSections>

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
Expand Down
20 changes: 11 additions & 9 deletions Data/Context/SystemContext.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@

namespace Data.Context
namespace Data.Context
{
using System;
using Data.EntitiesConfig;
using Domain.Entities;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Web;

public class SystemContext : DbContext
{
public SystemContext() : base("DefaultConnection")
{
}

public static SystemContext Create()
{
return new SystemContext();
}


protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

base.OnModelCreating(modelBuilder);

modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();


base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new NotaFiscalConfiguration());
}

public DbSet<NotaFiscal> NotasFiscais { get; set; }
}
}
}
24 changes: 20 additions & 4 deletions Data/Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Context\SystemContext.cs" />
<Compile Include="EntitiesConfig\NotaFiscalConfiguration.cs" />
<Compile Include="Migrations\201808041016404_criacaoBaseDeDados.cs" />
<Compile Include="Migrations\201808041016404_criacaoBaseDeDados.Designer.cs">
<DependentUpon>201808041016404_criacaoBaseDeDados.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repositories\NotaFiscalRepository.cs" />
<Compile Include="Repositories\RepositoryBase.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj">
Expand All @@ -41,8 +48,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=6.2.2.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.2.2\lib\net45\AutoMapper.dll</HintPath>
<Reference Include="AutoMapper, Version=7.0.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.7.0.1\lib\net45\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
Expand All @@ -54,6 +62,11 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
Expand All @@ -62,9 +75,12 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Context\UnitOfWork\" />
<Folder Include="EntitiesConfig\" />
<Folder Include="Interfaces\" />
<Folder Include="Repositories\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Migrations\201808041016404_criacaoBaseDeDados.resx">
<DependentUpon>201808041016404_criacaoBaseDeDados.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
40 changes: 40 additions & 0 deletions Data/EntitiesConfig/NotaFiscalConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Domain.Entities;
using System.Data.Entity.ModelConfiguration;

namespace Data.EntitiesConfig
{
public class NotaFiscalConfiguration : EntityTypeConfiguration<NotaFiscal>
{
public NotaFiscalConfiguration()
{
ToTable("Tb_NotasFiscais");

HasKey(c => c.Id)
.Property(c => c.Id)
.HasColumnName("NotaFiscalId");

Property(c => c.Numero)
.IsRequired()
.HasMaxLength(50)
.HasColumnName("NumeroNF");

Property(c => c.ValorTotal)
.IsRequired()
.HasColumnName("ValorTotalNF");

Property(c => c.Data)
.IsRequired()
.HasColumnName("DataNF");

Property(c => c.CNPJEmissor)
.IsRequired()
.HasMaxLength(30)
.HasColumnName("CNPJEmissorNF");

Property(c => c.CNPJDestinatario)
.IsRequired()
.HasMaxLength(30)
.HasColumnName("CNPJDestinatarioNF");
}
}
}
Loading