Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exams #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
414 changes: 414 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM microsoft/dotnet:2.2-sdk
ARG debug='1'
ENV DEBUG ${debug}
WORKDIR /src
COPY . .
RUN dotnet restore --ignore-failed-sources || :
RUN dotnet restore --ignore-failed-sources --source http://10.33.1.34:8081/repository/nuget-group/ || :
RUN (test $DEBUG -eq 1 && dotnet publish -c Debug -o /app) || (test $DEBUG -eq 0 && dotnet publish -c Release -o /app)

FROM microsoft/dotnet:2.2-aspnetcore-runtime
RUN apt update && apt install -y telnet vim tcpdump iputils-ping
ARG deploy_env='dev'
ARG port='8080'
ARG debug='1'
ENV DEBUG ${debug}
RUN (test $DEBUG -eq 1 && apt update && apt install -y unzip procps && curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg) || :
ARG deploy_env
ENV ASPNETCORE_ENVIRONMENT ${deploy_env}
ENV ASPNETCORE_URLS http://0.0.0.0:${port}
ENV TZ=America/Sao_Paulo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
COPY --from=0 /app .
CMD ["/bin/bash", "-c", "dotnet Exam.UI.dll"]
EXPOSE ${port}
26 changes: 26 additions & 0 deletions Exam.CrossCutting.IoC/Exam.CrossCutting.IoC.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.17" />
<PackageReference Include="MySql.Data.Core" Version="7.0.4-IR-191" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Exam.Data\Exam.Data.csproj" />
<ProjectReference Include="..\Exam.Domain\Exam.Domain.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.Extensions.Http">
<HintPath>..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.http\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Http.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions Exam.CrossCutting.IoC/NativeInjector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Exam.Data.ContextConfig;
using Exam.Domain.Events;
using Exam.Domain.Interfaces.Repositories;
using Exam.Data.Repositories;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.EntityFrameworkCore.Extensions;
using Exam.ExternalServices.ExamRepository;

namespace Exam.CrossCutting.IoC
{
public static class NativeInjector
{
public static void RegisterServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

services.AddScoped<DbContext, DataContext>();

services.AddDbContext<DbContext>(opt => opt.UseMySQL(configuration.GetConnectionString("DefaultConnection")));

services.AddScoped<IDomainNotificationHandler, DomainNotificationHandler>();

services.AddScoped<IClientRepository, ClientRepository>();

services.AddScoped<IScheduleRepository, ScheduleRepository>();

services.AddScoped<IUnitOfWork, UnitOfWork>();

services.AddScoped<IExamsRepository, ExamRepository>();

}
}
}
34 changes: 34 additions & 0 deletions Exam.Data/ContextConfig/DataContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Exam.Domain.Entities;
using Exam.Domain.Interfaces.Repositories;
using Exam.Data.EntityConfig;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Exam.Data.ContextConfig
{
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DbContext> options) : base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new ClientConfiguration());

modelBuilder.ApplyConfiguration(new ScheduleConfiguration());

base.OnModelCreating(modelBuilder);
}

public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return (await base.SaveChangesAsync(true, cancellationToken));
}
}
}

43 changes: 43 additions & 0 deletions Exam.Data/EntityConfig/ClientConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Exam.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;

namespace Exam.Data.EntityConfig
{
public class ClientConfiguration : IEntityTypeConfiguration<Client>
{
public void Configure(EntityTypeBuilder<Client> builder)
{
builder.ToTable("T001_CLNT");

builder.HasKey(x => x.Id);

builder
.Property(x => x.Id)
.HasColumnName("ID_CLNTE")
.IsRequired();

builder
.HasIndex(x => new { x.Cpf})
.IsUnique();

builder
.Property(x => x.Cpf)
.HasColumnName("NUM_CPF")
.HasMaxLength(11)
.IsRequired();

builder
.Property(x => x.DateBirth)
.HasColumnName("DT_DATE");

builder
.Property(x => x.Name)
.HasColumnName("DES_NOME")
.IsRequired();
}
}
}
53 changes: 53 additions & 0 deletions Exam.Data/EntityConfig/ScheduleConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Exam.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;

namespace Exam.Data.EntityConfig
{
public class ScheduleConfiguration : IEntityTypeConfiguration<Schedule>
{
public void Configure(EntityTypeBuilder<Schedule> builder)
{
builder.ToTable("T002_SCHL");

builder.HasKey(x => x.Id);

builder
.Property(x => x.Id)
.HasColumnName("ID_SCHL")
.IsRequired();

builder
.Property(x => x.IdExam)
.HasColumnName("ID_EXME")
.IsRequired();

builder
.Property(x => x.Name)
.HasColumnName("NOME_EXME")
.HasMaxLength(11)
.IsRequired();

builder
.Property(x => x.DateSchedule)
.HasColumnName("DT_DATE");

builder
.Property(x => x.Value)
.HasColumnName("NUM_VALOR")
.IsRequired();

builder
.Property(x => x.ClientId)
.HasColumnName("ID_CLNTE")
.IsRequired();

builder.HasOne(x => x.Client)
.WithMany(x => x.Schedules)
.HasForeignKey(x => new { x.ClientId });
}
}
}
19 changes: 19 additions & 0 deletions Exam.Data/Exam.Data.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Exam.Domain\Exam.Domain.csproj" />
<ProjectReference Include="..\Exam.ExternalServices\Exam.ExternalServices.csproj" />
</ItemGroup>

</Project>
48 changes: 48 additions & 0 deletions Exam.Data/Repositories/BaseRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Exam.Domain.Interfaces.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exam.Data.Repositories
{
public class BaseRepository<TEntity> : IRepository<TEntity> where TEntity : class
{
protected DbContext _db;
protected DbSet<TEntity> _dbSet;

public BaseRepository(DbContext context)
{
_db = context;
_dbSet = _db.Set<TEntity>();
}

public void Add(TEntity obj) => _db.Set<TEntity>().Add(obj);

public async Task<TEntity> AddAsync(TEntity obj)
{
await _db.Set<TEntity>().AddAsync(obj);
return obj;
}

public async Task AddRangeAsync(List<TEntity> obj) => await _db.Set<TEntity>().AddRangeAsync(obj);

public virtual TEntity GetById(int id) => _db.Set<TEntity>().Find(id);

public Task<TEntity> GetByIdAsync(int id) => _db.Set<TEntity>().FindAsync(id);

public virtual List<TEntity> GetAll() => _db.Set<TEntity>().ToList();

public void Update(TEntity obj) => _db.Entry(obj).State = EntityState.Modified;

public void Remove(TEntity obj) => _db.Set<TEntity>().Remove(obj);

public void Dispose()
{
_db.Dispose();
GC.SuppressFinalize(true);
}
}
}
31 changes: 31 additions & 0 deletions Exam.Data/Repositories/ClientRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Exam.Domain.Entities;
using Exam.Domain.Interfaces.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exam.Data.Repositories
{
public class ClientRepository : BaseRepository<Client>, IClientRepository
{
public ClientRepository(DbContext context) : base(context)
{
}

public Client GetClientByCpf(string cpf)
{
return _dbSet.Where(x => x.Cpf == cpf).FirstOrDefault();
}

public Client GetAllScheduleByCpf(string cpf) =>
_dbSet.Where(x => x.Cpf == cpf)
.Include(x => x.Schedules).FirstOrDefault();

public Client GetAllScheduleById(int id) =>
_dbSet.Where(x => x.Id == id)
.Include(x => x.Schedules).FirstOrDefault();

}
}
23 changes: 23 additions & 0 deletions Exam.Data/Repositories/ScheduleRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Exam.Domain.Entities;
using Exam.Domain.Interfaces.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exam.Data.Repositories
{
public class ScheduleRepository : BaseRepository<Schedule>, IScheduleRepository
{
public ScheduleRepository(DbContext context) : base(context)
{
}
public Schedule GetByIdExamDate(string idExam,DateTime date)
{
var dateTime = date.ToString("dd/MM/yyyy HH");
return _dbSet.Where(x => x.IdExam == idExam && x.DateSchedule.ToString("dd/MM/yyyy HH") == dateTime).FirstOrDefault();

}
}
}
Loading