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
55 changes: 55 additions & 0 deletions Application/App/NotaFiscalApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using Application.Interfaces;
using Application.Model;
using AutoMapper;
using Domain.Entities;
using Domain.Interfaces.Services;

namespace Application.App
{
public class NotaFiscalApp : INotaFiscalApp
{
private readonly INotaFiscalService _notaFiscalService;

public NotaFiscalApp(INotaFiscalService notaFiscalService)
{
this._notaFiscalService = notaFiscalService;
}

public IEnumerable<NotaFiscalVW> FindAll()
{
return Mapper.Map<IEnumerable<NotaFiscalVW>>(this._notaFiscalService.FindAll());
}

public NotaFiscalVW FindById(int id)
{
return Mapper.Map<NotaFiscalVW>(this._notaFiscalService.FindById(id)); ;
}

public NotaFiscalVW FindByNumeroNF(long numNF)
{
return Mapper.Map<NotaFiscalVW>(this._notaFiscalService.FindByNumeroNF(numNF)); ;
}

public void Persist(NotaFiscalVW notaFiscal)
{
NotaFiscal lNotaFiscal = Mapper.Map<NotaFiscal>(notaFiscal);

this._notaFiscalService.Persist(lNotaFiscal);
}


public void Update(NotaFiscalVW notaFiscal)
{
NotaFiscal lNotaFiscal = Mapper.Map<NotaFiscal>(notaFiscal);

this._notaFiscalService.Update(lNotaFiscal);
}

public void Remove(int id)
{
this._notaFiscalService.Remove(id);
}

}
}
12 changes: 6 additions & 6 deletions Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="App\NotaFiscalApp.cs" />
<Compile Include="AutoMapper\AutoMapperConfig.cs" />
<Compile Include="AutoMapper\MappingProfile\DomainToViewModelMappingProfile.cs" />
<Compile Include="AutoMapper\MappingProfile\ViewModelToDomainMappingProfile.cs" />
<Compile Include="Interfaces\INotaFiscalApp.cs" />
<Compile Include="Model\NotaFiscalVW.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -56,11 +61,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>
12 changes: 10 additions & 2 deletions Application/AutoMapper/AutoMapperConfig.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using AutoMapper;
using Application.AutoMapper.MappingProfile;
using AutoMapper;

namespace Application.AutoMapper
{
public static class AutoMapperConfig
{
public static Mapper _mapper;

public static void RegisterMappings()
{
Mapper.Initialize(x =>
{

x.AddProfile<DomainToViewModelMappingProfile>();
x.AddProfile<ViewModelToDomainMappingProfile>();
});
}

public static void Reset() {
Mapper.Reset();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Application.Model;
using AutoMapper;
using Domain.Entities;

namespace Application.AutoMapper.MappingProfile
{
public class DomainToViewModelMappingProfile : Profile
{
public DomainToViewModelMappingProfile() : base("DomainToViewModelMappings")
{
CreateMap<NotaFiscal, NotaFiscalVW>();
}

}
}
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
{
public ViewModelToDomainMappingProfile() : base("ViewModelToDomainMappings")
{
CreateMap<NotaFiscalVW, NotaFiscal>();
}
}
}
20 changes: 20 additions & 0 deletions Application/Interfaces/INotaFiscalApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Application.Model;
using System.Collections.Generic;

namespace Application.Interfaces
{
public interface INotaFiscalApp
{
void Persist(NotaFiscalVW notaFiscal);

NotaFiscalVW FindById(int id);

NotaFiscalVW FindByNumeroNF(long numNF);

IEnumerable<NotaFiscalVW> FindAll();

void Update(NotaFiscalVW notaFiscal);

void Remove(int id);
}
}
14 changes: 14 additions & 0 deletions Application/Model/NotaFiscalVW.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Application.Model
{
public class NotaFiscalVW
{
public int notaFiscalId { get; set; }
public long numeroNf { get; set; }
public decimal valorTotal { get; set; }
public DateTime dataNf { get; set; }
public long cnpjEmissorNf { get; set; }
public long cnpjDestinatarioNf { get; set; }
}
}
11 changes: 7 additions & 4 deletions Data/Context/SystemContext.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@

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

public class SystemContext : DbContext
{
public SystemContext() : base("DevPartner")
{

}

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


protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

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


base.OnModelCreating(modelBuilder);
}

public virtual DbSet<NotaFiscal> NotaFiscal { get; set; }

}
}
2 changes: 1 addition & 1 deletion Data/Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Compile Include="Context\SystemContext.cs" />
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repositories\NotaFiscalRepository.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj">
Expand Down Expand Up @@ -64,7 +65,6 @@
<Folder Include="Context\UnitOfWork\" />
<Folder Include="EntitiesConfig\" />
<Folder Include="Interfaces\" />
<Folder Include="Repositories\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
5 changes: 1 addition & 4 deletions Data/Migrations/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
namespace Data.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;

internal sealed class Configuration : DbMigrationsConfiguration<Data.Context.SystemContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationsEnabled = true;
}

protected override void Seed(Data.Context.SystemContext context)
Expand Down
54 changes: 54 additions & 0 deletions Data/Repositories/NotaFiscalRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Data.Context;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

using Domain.Entities;
using Domain.Interfaces.Repository;

namespace Data.Repositories
{
public class NotaFiscalRepository : INotaFiscalRepository
{
private SystemContext _context = new SystemContext();

public void Persist(NotaFiscal notaFiscal)
{
_context.NotaFiscal.Add(notaFiscal);
_context.SaveChanges();
}

public NotaFiscal FindById(int id)
{
return _context.NotaFiscal.Find(id);
}

public NotaFiscal FindByNumeroNF(long numNF) {
return _context.NotaFiscal
.Where(nf=> nf.numeroNf == numNF)
.FirstOrDefault<NotaFiscal>();
}

public IEnumerable<NotaFiscal> FindAll()
{
IEnumerable<NotaFiscal> NotasFiscais = _context.NotaFiscal;
return NotasFiscais;
}

public void Update(NotaFiscal notaFiscal)
{
_context.Entry(notaFiscal).State = EntityState.Modified;
_context.SaveChanges();
}

public void Remove(int id)
{
NotaFiscal lNotaFiscal = new NotaFiscal() { notaFiscalId = id };
_context.NotaFiscal.Attach(lNotaFiscal);
_context.Entry(lNotaFiscal).State = EntityState.Deleted;
_context.SaveChanges();

}

}
}
8 changes: 4 additions & 4 deletions Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Entities\NotaFiscal.cs" />
<Compile Include="Interfaces\Repository\INotaFiscalRepository.cs" />
<Compile Include="Interfaces\Services\INotaFiscalService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\NotaFiscalService.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Entities\" />
<Folder Include="Enum\" />
<Folder Include="Interfaces\Repository\" />
<Folder Include="Interfaces\Services\" />
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
20 changes: 20 additions & 0 deletions Domain/Entities/NotaFiscal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.Entities
{
public class NotaFiscal
{
[Key]
public int notaFiscalId {get;set;}

[Index("IX_NumeroNf", 1, IsUnique = true)]
public long numeroNf {get;set;}
public decimal valorTotal {get;set;}
public DateTime dataNf {get;set;}
public long cnpjEmissorNf {get;set;}
public long cnpjDestinatarioNf {get;set;}

}
}
20 changes: 20 additions & 0 deletions Domain/Interfaces/Repository/INotaFiscalRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Domain.Entities;
using System.Collections.Generic;

namespace Domain.Interfaces.Repository
{
public interface INotaFiscalRepository
{
void Persist(NotaFiscal notaFiscal);

IEnumerable<NotaFiscal> FindAll();

NotaFiscal FindById(int id);

NotaFiscal FindByNumeroNF(long numNF);

void Update(NotaFiscal notaFiscal);

void Remove(int id);
}
}
20 changes: 20 additions & 0 deletions Domain/Interfaces/Services/INotaFiscalService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Domain.Entities;
using System.Collections.Generic;

namespace Domain.Interfaces.Services
{
public interface INotaFiscalService
{
void Persist(NotaFiscal notaFiscal);

IEnumerable<NotaFiscal> FindAll();

NotaFiscal FindById(int id);

NotaFiscal FindByNumeroNF(long numNF);

void Update(NotaFiscal notaFiscal);

void Remove(int id);
}
}
Loading