Primera subida

This commit is contained in:
Alejandro Sarmiento
2024-04-06 03:32:16 +02:00
parent c97b4a8179
commit b672887299
44 changed files with 44426 additions and 0 deletions

25
back.sln Normal file
View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "back", "back\back.csproj", "{355446DE-E306-45F1-9F73-2A81A274F1D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{355446DE-E306-45F1-9F73-2A81A274F1D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{355446DE-E306-45F1-9F73-2A81A274F1D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{355446DE-E306-45F1-9F73-2A81A274F1D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{355446DE-E306-45F1-9F73-2A81A274F1D1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {25A9DC6B-F886-4CDE-9A55-4006FA49EE56}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,26 @@
using back.Entities;
using System.Linq.Expressions;
namespace back.Application.Contracts.Persistence
{
public interface IAsyncRepository<T> where T : BaseEntity
{
Task<IReadOnlyList<T>> GetAllAsync();
Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>>? predicate);
Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>>? predicate = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
string? includeString = null,
bool disableTracking = true);
Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>>? predicate = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
List<Expression<Func<T, object>>>? includes = null,
bool disableTracking = true);
Task<T> GetByIdAsync(int id);
Task<T> AddAsync(T entity);
Task<T> UpdateAsync(T entity);
Task DeleteAsync(T entity);
}
}

View File

@@ -0,0 +1,14 @@
using back.Entities.DTOs.Request;
using back.Entities;
namespace back.Application.Contracts.Services
{
public interface IBaseService<T, A, U> where T : class
{
Task<IEnumerable<T>> GetAll();
Task<T> GetOne(int id);
Task<T> Add(A dto);
Task<bool> Delete(int id);
Task<T> Update(U dto);
}
}

View File

@@ -0,0 +1,10 @@
using back.Entities;
using back.Entities.DTOs.Request;
using back.Infra;
namespace back.Application.Contracts.Services
{
public interface ICasaService : IBaseService<Casa, CasaRequestDto, CasaUpdateRequestDto>
{
}
}

View File

@@ -0,0 +1,9 @@
using back.Entities;
using back.Entities.DTOs.Request;
namespace back.Application.Contracts.Services
{
public interface IDireccionService:IBaseService<Direccion, DireccionRequestDto, DireccionUpdateRequestDto>
{
}
}

View File

@@ -0,0 +1,11 @@
using back.Entities;
using back.Entities.DTOs.Request;
using back.Entities.DTOs.Response;
namespace back.Application.Contracts.Services
{
public interface IPersonaService : IBaseService<Persona, PersonaRequestDto, PersonaUpdateRequestDto>
{
}
}

View File

@@ -0,0 +1,10 @@
using back.Entities.DTOs.Response;
namespace back.Application.Contracts.Services
{
public interface IWantItAllService
{
Task<IWantItAll> GetWithAsyncAwait();
Task<IWantItAll> GetWithTasks();
}
}

View File

@@ -0,0 +1,27 @@
using AutoMapper;
using back.Entities;
using back.Entities.DTOs.Request;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace back.Application.Mappers
{
public class MappingProfile : Profile
{
public MappingProfile()
{
#region Mappings
CreateMap<Casa, CasaRequestDto>();
CreateMap<CasaRequestDto, Casa>();
CreateMap<Casa, CasaWitDirecctionRequestDto>();
CreateMap<CasaWitDirecctionRequestDto, Casa>();
CreateMap<Persona, PersonaRequestDto>();
CreateMap<PersonaRequestDto, Persona>();
CreateMap<Direccion, DireccionRequestDto>();
CreateMap<DireccionRequestDto, Direccion>();
#endregion Mappings
}
}
}

View File

@@ -0,0 +1,31 @@
using AutoMapper;
using back.Entities.DTOs.Request;
using back.Entities;
using back.Infra;
using back.Application.Contracts.Persistence;
namespace back.Application.Services
{
public class CasaService : GenericService<Casa, CasaRequestDto, CasaUpdateRequestDto>
{
private readonly IMapper _mapper;
private readonly DireccionService dService;
private readonly IAsyncRepository<Casa> repo;
public CasaService(IMapper mapper, IAsyncRepository<Casa> _repo, DireccionService dService) : base(mapper, _repo)
{
_mapper = mapper;
this.dService = dService;
repo = _repo;
}
public async override Task<Casa> Add(CasaRequestDto dto)
{
var direccion = _mapper.Map<Direccion>(dto.Direction);
var d = await dService.AddOne(direccion);
var casa = _mapper.Map<Casa>(dto);
casa.Direccion = d;
return await repo.AddAsync(casa);
}
}
}

View File

@@ -0,0 +1,23 @@
using AutoMapper;
using back.Entities.DTOs.Request;
using back.Entities;
using back.Infra;
using back.Application.Contracts.Persistence;
namespace back.Application.Services
{
public class DireccionService : GenericService<Direccion, DireccionRequestDto, DireccionUpdateRequestDto>
{
private readonly IAsyncRepository<Direccion> repo;
public DireccionService(IMapper mapper, IAsyncRepository<Direccion> _repo) : base(mapper, _repo)
{
repo = _repo;
}
public async Task<Direccion> AddOne(Direccion direccion)
{
await repo.AddAsync(direccion);
return direccion;
}
}
}

View File

@@ -0,0 +1,54 @@
using AutoMapper;
using back.Application.Contracts.Persistence;
using back.Application.Contracts.Services;
using back.Entities;
using back.Infra;
namespace back.Application.Services
{
public class GenericService<T, A, U> : IBaseService<T, A, U> where T : BaseEntity
{
private readonly IMapper mapper;
private readonly IAsyncRepository<T> repo;
public GenericService(IMapper mapper, IAsyncRepository<T> repo)
{
this.mapper = mapper;
this.repo = repo;
}
public virtual async Task<T> Add(A dto)
{
T entity = mapper.Map<T>(dto);
return await repo.AddAsync(entity);
}
public virtual async Task<bool> Delete(int id)
{
T entityExists = await repo.GetByIdAsync(id);
if(entityExists == null)
{
return false;
}
await repo.DeleteAsync(entityExists);
return true;
}
public virtual async Task<IEnumerable<T>> GetAll()
{
return await repo.GetAllAsync();
}
public virtual async Task<T> GetOne(int id)
{
return await repo.GetByIdAsync(id);
}
public virtual async Task<T> Update(U dto)
{
T entity = mapper.Map<T>(dto);
await repo.UpdateAsync(entity);
return entity;
}
}
}

View File

@@ -0,0 +1,22 @@
using AutoMapper;
using back.Application.Contracts.Persistence;
using back.Application.Contracts.Services;
using back.Entities;
using back.Entities.DTOs.Request;
using back.Entities.DTOs.Response;
using back.Infra;
using System.Runtime.CompilerServices;
namespace back.Application.Services
{
public class PersonaService : GenericService<Persona, PersonaRequestDto, PersonaUpdateRequestDto>
{
public PersonaService(IMapper mapper, IAsyncRepository<Persona> repo) : base(mapper, repo)
{
}
}
}

View File

@@ -0,0 +1,57 @@
using back.Entities.DTOs.Response;
using back.Entities;
using back.Application.Contracts.Services;
using back.Application.Contracts.Persistence;
namespace back.Application.Services
{
public class WantItAllService : IWantItAllService
{
private readonly IAsyncRepository<Persona> personaRepo;
private readonly IAsyncRepository<Casa> casaRepo;
private readonly IAsyncRepository<Direccion> direccionRepo;
public WantItAllService(IAsyncRepository<Persona> personaRepo, IAsyncRepository<Casa> casaRepo, IAsyncRepository<Direccion> direccionRepo)
{
this.personaRepo = personaRepo;
this.casaRepo = casaRepo;
this.direccionRepo = direccionRepo;
}
public async Task<IWantItAll> GetWithAsyncAwait()
{
var personas = await personaRepo.GetAllAsync();
var casas = await casaRepo.GetAllAsync();
var direcciones = await direccionRepo.GetAllAsync();
var toReturn = new IWantItAll
{
Personas = personas.ToList(),
Casas = casas.ToList(),
Direcciones = direcciones.ToList(),
};
return toReturn;
}
public async Task<IWantItAll> GetWithTasks()
{
var personas = personaRepo.GetAllAsync();
var casas = casaRepo.GetAllAsync();
var direcciones = direccionRepo.GetAllAsync();
await Task.WhenAll(personas, casas, direcciones);
IReadOnlyList<Persona> personas1 = await personas;
IReadOnlyList<Casa> casas1 = await casas;
IReadOnlyList<Direccion> direccions = await direcciones;
var toReturn = new IWantItAll
{
Personas = personas1.ToList(),
Casas = casas1.ToList(),
Direcciones = direccions.ToList(),
};
return toReturn;
}
}
}

View File

@@ -0,0 +1,52 @@
using back.Application.Services;
using back.Entities.DTOs.Request;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace back.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class CasaController : ControllerBase
{
private readonly CasaService service;
public CasaController(CasaService service)
{
this.service = service;
}
[HttpGet("GetOne/{id}")]
public async Task<IActionResult> GetOne(int id)
{
return Ok(await service.GetOne(id));
}
[HttpGet("GetAll")]
public async Task<IActionResult> GetAll()
{
return Ok(await service.GetAll());
}
[HttpPost("Create")]
public async Task<IActionResult> Create(CasaRequestDto dto)
{
if(dto.Direction == null)
{
return BadRequest("Direccion debe existir");
}
return Ok(await service.Add(dto));
}
[HttpPut("Update")]
public async Task<IActionResult> Update(CasaUpdateRequestDto dto)
{
return Ok(await service.Update(dto));
}
[HttpDelete("Delete/{id}")]
public async Task<IActionResult> Delete(int id)
{
return Ok(service.Delete(id));
}
}
}

View File

@@ -0,0 +1,48 @@
using back.Application.Services;
using back.Entities.DTOs.Request;
using Microsoft.AspNetCore.Mvc;
namespace back.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DireccionController : ControllerBase
{
private readonly DireccionService service;
public DireccionController(DireccionService service)
{
this.service = service;
}
[HttpGet("GetOne/{id}")]
public async Task<IActionResult> GetOne(int id)
{
return Ok(await service.GetOne(id));
}
[HttpGet("GetAll")]
public async Task<IActionResult> GetAll()
{
return Ok(await service.GetAll());
}
//[HttpPost("Create")]
//public async Task<IActionResult> Create(DireccionRequestDto dto)
//{
// return Ok(await service.Add(dto));
//}
[HttpPut("Update")]
public async Task<IActionResult> Update(DireccionUpdateRequestDto dto)
{
return Ok(await service.Update(dto));
}
//[HttpDelete("Delete/{id}")]
//public async Task<IActionResult> Delete(int id)
//{
// return Ok(service.Delete(id));
//}
}
}

View File

@@ -0,0 +1,31 @@
using back.Application.Contracts.Services;
using back.Application.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace back.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class IWantItAllController : ControllerBase
{
private readonly IWantItAllService service;
public IWantItAllController(IWantItAllService _service)
{
service = _service;
}
[HttpGet("GetAllAsyncAwait")]
public async Task<IActionResult> GetAllAsyncAwait()
{
return Ok(await service.GetWithAsyncAwait());
}
[HttpGet("GetAllTasks")]
public async Task<IActionResult> GetAllTasks()
{
return Ok(await service.GetWithTasks());
}
}
}

View File

@@ -0,0 +1,50 @@
using back.Application.Contracts.Services;
using back.Application.Services;
using back.Entities.DTOs.Request;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace back.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class PersonaController : ControllerBase
{
private readonly PersonaService service;
public PersonaController(PersonaService _service)
{
service = _service;
}
[HttpGet("GetOne/{id}")]
public async Task<IActionResult> GetOne(int id)
{
return Ok(await service.GetOne(id));
}
[HttpGet("GetAll")]
public async Task<IActionResult> GetAll()
{
return Ok(await service.GetAll());
}
[HttpPost("Create")]
public async Task<IActionResult> Create(PersonaRequestDto dto)
{
return Ok(await service.Add(dto));
}
[HttpPut("Update")]
public async Task<IActionResult> Update(PersonaUpdateRequestDto dto)
{
return Ok(await service.Update(dto));
}
[HttpDelete("Delete/{id}")]
public async Task<IActionResult> Delete(int id)
{
return Ok(service.Delete(id));
}
}
}

View File

@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace back.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TimeTester : ControllerBase
{
}
}

View File

@@ -0,0 +1,7 @@
namespace back.Entities
{
public class BaseEntity
{
public int Id { get; set; }
}
}

17
back/Entities/Casa.cs Normal file
View File

@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;
namespace back.Entities
{
public class Casa : BaseEntity
{
public string NombreCasa { get; set; } = string.Empty;
public int NumeroHabitaciones { get; set; }
public int PersonaId { get; set; }
[JsonIgnore]
public virtual Persona Persona { get; set; }
public int DireccionId { get; set; }
[JsonIgnore]
public virtual Direccion Direccion { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace back.Entities.DTOs.Request
{
public class CasaRequestDto
{
public int PersonaId { get; set; }
public string NombreCasa { get; set; } = string.Empty;
public int NumeroHabitaciones { get; set; }
public DireccionRequestDto? Direction { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace back.Entities.DTOs.Request
{
public class CasaUpdateRequestDto
{
public int Id { get; set; }
public string NombreCasa { get; set; } = string.Empty;
public int NumeroHabitaciones { get; set; }
public DireccionUpdateRequestDto? Direccion { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace back.Entities.DTOs.Request
{
public class CasaWitDirecctionRequestDto
{
public string NombreCasa { get; set; } = string.Empty;
public int NumeroHabitaciones { get; set; }
public DireccionRequestDto Direction { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace back.Entities.DTOs.Request
{
public class DireccionRequestDto
{
public string Calle { get; set; } = string.Empty;
public int? Numero { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace back.Entities.DTOs.Request
{
public class DireccionUpdateRequestDto
{
public int Id { get; set; }
public string Calle { get; set; } = string.Empty;
public int? Numero { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace back.Entities.DTOs.Request
{
public class PersonaRequestDto
{
public string Name { get; set; } = string.Empty;
public string Surname { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,9 @@
namespace back.Entities.DTOs.Request
{
public class PersonaUpdateRequestDto
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Surname { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,9 @@
namespace back.Entities.DTOs.Response
{
public class IWantItAll
{
public List<Persona> Personas { get; set; }
public List<Casa> Casas { get; set; }
public List<Direccion> Direcciones { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace back.Entities
{
public class Direccion : BaseEntity
{
public string Calle { get; set; } = string.Empty;
public int? Numero { get; set; }
}
}

13
back/Entities/Persona.cs Normal file
View File

@@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace back.Entities
{
public class Persona : BaseEntity
{
public string Name { get; set; } = string.Empty;
public string Surname { get; set; } = string.Empty;
[JsonIgnore]
public virtual ICollection<Casa>? Casas { get; set; }
}
}

View File

@@ -0,0 +1,84 @@
using back.Entities;
using Microsoft.EntityFrameworkCore;
namespace back.Infra
{
public class Application_Db_Context : DbContext
{
public Application_Db_Context(DbContextOptions<Application_Db_Context> opt) : base(opt)
{ }
public virtual DbSet<Persona> Personas { get; set; }
public virtual DbSet<Casa> Casas { get; set; }
public virtual DbSet<Direccion> Direcciones { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
SeedData(modelBuilder); //en Movidas
}
#region Movidas
private static void SeedData(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Persona>().HasData(GenerarPersonas());
modelBuilder.Entity<Casa>().HasData(GenerarCasas());
modelBuilder.Entity<Direccion>().HasData(GenerarDirecciones());
}
private static List<Persona> GenerarPersonas()
{
var personas = new List<Persona>();
for (int i = 1; i <= 1000; i++)
{
personas.Add(new Persona
{
Id = i,
Name = $"Nombre{i}",
Surname = $"Apellido{i}",
});
}
return personas;
}
private static List<Casa> GenerarCasas()
{
var casas = new List<Casa>();
for (int i = 1; i <= 1000; i++)
{
casas.Add(new Casa
{
Id = i,
NombreCasa = $"Casa{i}",
NumeroHabitaciones = new Random().Next(1, 5),
DireccionId = i,
// Asumimos que PersonaId es una propiedad que debería existir para relacionar con Persona
PersonaId = i
});
}
return casas;
}
private static List<Direccion> GenerarDirecciones()
{
var direcciones = new List<Direccion>();
for (int i = 1; i <= 1000; i++)
{
direcciones.Add(new Direccion
{
Id = i,
Calle = $"Calle{i}",
Numero = new Random().Next(1, 100),
});
}
return direcciones;
}
#endregion Movidas
}
}

View File

@@ -0,0 +1,95 @@
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;
using System.Linq;
using back.Entities;
using back.Application.Contracts.Persistence;
using Microsoft.EntityFrameworkCore.Internal;
namespace back.Infra
{
public class BaseRepository<T> : IAsyncRepository<T> where T : BaseEntity
{
protected readonly Application_Db_Context context;
private readonly IDbContextFactory<Application_Db_Context> _dbContextFactory;
public BaseRepository(IDbContextFactory<Application_Db_Context> dbContextFactory, Application_Db_Context _context)
{
context = _context;
_dbContextFactory = dbContextFactory;
}
public virtual async Task<IReadOnlyList<T>> GetAllAsync()
{
using (var context = _dbContextFactory.CreateDbContext())
{
return await context.Set<T>().ToListAsync();
}
}
public virtual async Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>> predicate)
{
return await context.Set<T>().Where(predicate).ToListAsync();
}
public virtual async Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>>? predicate = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
string includeString = null,
bool disableTracking = true)
{
IQueryable<T> query = context.Set<T>();
if (disableTracking) query = query.AsNoTracking();
if (!string.IsNullOrWhiteSpace(includeString)) query = query.Include(includeString);
if (predicate != null) query = query.Where(predicate);
if (orderBy != null)
return await orderBy(query).ToListAsync();
return await query.ToListAsync();
}
public virtual async Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>>? predicate = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
List<Expression<Func<T, object>>>? includes = null,
bool disableTracking = true)
{
IQueryable<T> query = context.Set<T>();
if (disableTracking) query = query.AsNoTracking();
if (includes != null) query = includes.Aggregate(query, (current, include) => current.Include(include));
if (predicate != null) query = query.Where(predicate);
if (orderBy != null)
return await orderBy(query).ToListAsync();
return await query.ToListAsync();
}
public virtual async Task<T> GetByIdAsync(int id)
{
return await context.Set<T>().FindAsync(id);
}
public virtual async Task<T> AddAsync(T entity)
{
context.Set<T>().Add(entity);
await context.SaveChangesAsync();
return entity;
}
public virtual async Task<T> UpdateAsync(T entity)
{
context.Set<T>().Attach(entity);
context.Entry(entity).State = EntityState.Modified;
await context.SaveChangesAsync();
return entity;
}
public virtual async Task DeleteAsync(T entity)
{
context.Set<T>().Remove(entity);
await context.SaveChangesAsync();
}
}
}

View File

@@ -0,0 +1,53 @@
using back.Entities;
using back.Entities.DTOs.Response;
using Microsoft.EntityFrameworkCore;
using Microsoft.Identity.Client;
namespace back.Infra
{
public class CasaRepository : BaseRepository<Casa>
{
private readonly Application_Db_Context context;
private readonly IDbContextFactory<Application_Db_Context> _dbContextFactory;
public CasaRepository(Application_Db_Context _context, IDbContextFactory<Application_Db_Context> dbContextFactory) : base(dbContextFactory, _context)
{
context = _context;
_dbContextFactory = dbContextFactory;
}
public override async Task<Casa> AddAsync(Casa casa)
{
if(casa.Direccion == null)
{
var toReturn = await base.AddAsync(casa);
return toReturn;
}
else
{
await context.Casas.AddAsync(casa);
await context.Direcciones.AddAsync(casa.Direccion);
await context.SaveChangesAsync();
return casa;
}
}
public async Task<IWantItAll> WantItAlls()
{
var personas = Task.Run(async () => { return await context.Personas.ToListAsync(); });
var casas = Task.Run(async () => { return await context.Casas.ToListAsync(); });
var direcciones = Task.Run(async () => { return await context.Direcciones.ToListAsync(); });
await Task.WhenAll(personas, casas, direcciones);
var toReturn = new IWantItAll()
{
Personas = await personas,
Casas = await casas,
Direcciones = await direcciones
};
return toReturn;
}
}
}

View File

@@ -0,0 +1,13 @@
using back.Entities;
using Microsoft.EntityFrameworkCore;
namespace back.Infra
{
public class DireccionRepository : BaseRepository<Direccion>
{
public DireccionRepository(Application_Db_Context _context, IDbContextFactory<Application_Db_Context> _dbContextFactory) : base(_dbContextFactory, _context)
{
}
}
}

View File

@@ -0,0 +1,15 @@
using back.Entities;
using Microsoft.EntityFrameworkCore;
namespace back.Infra
{
public class PersonaRepository : BaseRepository<Persona>
{
public PersonaRepository(Application_Db_Context _context, IDbContextFactory<Application_Db_Context> _dbContextFactory) : base(_dbContextFactory, _context)
{
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

75
back/Program.cs Normal file
View File

@@ -0,0 +1,75 @@
using back.Application.Contracts.Persistence;
using back.Application.Contracts.Services;
using back.Application.Services;
using back.Entities;
using back.Entities.DTOs.Request;
using back.Infra;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly());
builder.Services.AddScoped<IBaseService<Persona, PersonaRequestDto, PersonaUpdateRequestDto>, GenericService<Persona, PersonaRequestDto, PersonaUpdateRequestDto>>();
builder.Services.AddScoped<IBaseService<Casa, CasaRequestDto, CasaUpdateRequestDto>, GenericService<Casa, CasaRequestDto, CasaUpdateRequestDto>>();
builder.Services.AddScoped<IBaseService<Direccion, DireccionRequestDto, DireccionUpdateRequestDto>, GenericService<Direccion, DireccionRequestDto, DireccionUpdateRequestDto>>();
builder.Services.AddScoped<CasaService>();
builder.Services.AddScoped<PersonaService>();
builder.Services.AddScoped<DireccionService>();
builder.Services.AddScoped<IWantItAllService, WantItAllService>();
builder.Services.AddScoped<IAsyncRepository<Persona>, BaseRepository<Persona>>();
builder.Services.AddScoped<IAsyncRepository<Casa>, BaseRepository<Casa>>();
builder.Services.AddScoped<IAsyncRepository<Direccion>, BaseRepository<Direccion>>();
builder.Services.AddScoped<PersonaRepository>();
builder.Services.AddScoped<CasaRepository>();
builder.Services.AddScoped<DireccionRepository>();
var dbConnectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContextFactory<Application_Db_Context>(options =>
{
options.UseSqlServer(dbConnectionString);
});
builder.Services.AddDbContext<Application_Db_Context>(options =>
options.UseSqlServer(dbConnectionString)
.LogTo(Console.WriteLine, new[] { DbLoggerCategory.Database.Command.Name }, Microsoft.Extensions.Logging.LogLevel.Information)
);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:13559",
"sslPort": 44369
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5124",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7009;http://localhost:5124",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

12
back/appsettings.json Normal file
View File

@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=ddns.desatatufuria.com;Initial Catalog=AlexTimeTesterDB;User ID=sa;Password=Sq4008640;TrustServerCertificate=true;"
},
"AllowedHosts": "*"
}

20
back/back.csproj Normal file
View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
</Project>

6
back/back.http Normal file
View File

@@ -0,0 +1,6 @@
@back_HostAddress = http://localhost:5124
GET {{back_HostAddress}}/weatherforecast/
Accept: application/json
###