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

Prueba Técnica c# .Net MVC Dario Nieves #20

Open
wants to merge 3 commits into
base: main
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignorar configuraciones de Visual Studio
.vs/
30 changes: 30 additions & 0 deletions BackEnd/WebApp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
136 changes: 136 additions & 0 deletions BackEnd/WebApp/Controllers/BalanceServiceProvidersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System.Net;
using System.Transactions;
using WebApp.Helpers;
using WebApp.Models;

namespace WebApp.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BalanceServiceProvidersController : ControllerBase
{
private readonly string connectionString = string.Empty;
private readonly IHandleServiceProviders _mapping;

public BalanceServiceProvidersController( IConfiguration configuration, IHandleServiceProviders mapping)
{
_mapping = mapping;
connectionString = configuration.GetConnectionString("EndpointEsett");
}


// GET: api/BalanceServiceProviders/5
[HttpGet("{id}")]
public async Task<ActionResult<BalanceServiceProviders>> GetBalanceServiceProviders(Guid id)
{
try
{
return _mapping.BalanceServiceProvidersById(id);
}
catch (Exception)
{

throw new Exception("An error has occurred with your request");
}

}


[HttpPut]
public async Task<IActionResult> PutBalanceServiceProviders(BalanceServiceProviders balance)
{
using (TransactionScope scope = new TransactionScope())
{
try
{
_mapping.UpdateBalanceServiceProvidersById(balance);
scope.Complete();
return Ok("Transaction executed successfully");
}
catch (Exception)
{

throw new Exception("An error has occurred with your request");
}
}


}

// POST: api/BalanceServiceProviders
[HttpPost]
public async Task<ActionResult<List<BalanceServiceProviders>>> PostBalanceServiceProviders()
{
using (TransactionScope scope = new TransactionScope())
{
List<BalanceServiceProviders> dataResult = new List<BalanceServiceProviders>();
try
{
HttpClient client = new HttpClient();


var httpReponse = await client.GetAsync(connectionString + "?country=FI");
var statusCode = httpReponse.StatusCode == HttpStatusCode.OK ? 200 : 400;

if (statusCode == 200)
{
var responseBody = await httpReponse.Content.ReadAsStringAsync();

dataResult = JsonConvert.DeserializeObject<List<BalanceServiceProviders>>(responseBody);

foreach (var item in dataResult)
{

_mapping.BalanceServiceProviders(item);

}

}
else
{
return BadRequest();
}

scope.Complete();
return Ok(dataResult);
}
catch (Exception)
{
scope.Dispose();
throw new Exception("An error has occurred with your request");
}


}

}

[HttpDelete("{id}")]
public async Task<IActionResult> DeleteBalanceServiceProviders(Guid id)
{
using (TransactionScope scope = new TransactionScope())
{

try
{
_mapping.DeleteBalanceServiceProvidersById(id);
scope.Complete();
return Ok("Transaction executed successfully");
}
catch (Exception)
{

scope.Dispose();
throw new Exception("An error has occurred with your request");
}


}
}


}
}
34 changes: 34 additions & 0 deletions BackEnd/WebApp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Consulte https://aka.ms/customizecontainer para aprender a personalizar su contenedor de depuración y cómo Visual Studio usa este Dockerfile para compilar sus imágenes para una depuración más rápida.

# Esta fase se usa cuando se ejecuta desde VS en modo rápido (valor predeterminado para la configuración de depuración)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# Define las variables de entorno
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ConnectionStrings__ConnectionDBSQL: "Server=localhost;Database=AlicundeDB;TrustServerCertificate=True;MultiSubnetFailover=True;Trusted_Connection=False;User Id=sa;Password=D@rioSn0w;"
ENV ConnectionStrings__EndpointEsett:"https://api.opendata.esett.com/EXP01/BalanceServiceProviders"

# Esta fase se usa para compilar el proyecto de servicio
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["WebApp.csproj", "."]
RUN dotnet restore "./WebApp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./WebApp.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Esta fase se usa para publicar el proyecto de servicio que se copiará en la fase final.
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./WebApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Esta fase se usa en producción o cuando se ejecuta desde VS en modo normal (valor predeterminado cuando no se usa la configuración de depuración)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApp.dll"]
12 changes: 12 additions & 0 deletions BackEnd/WebApp/Helpers/IHandleServiceProviders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using WebApp.Models;

namespace WebApp.Helpers
{
public interface IHandleServiceProviders
{
void BalanceServiceProviders(BalanceServiceProviders request);
BalanceServiceProviders BalanceServiceProvidersById(Guid request);
void UpdateBalanceServiceProvidersById(BalanceServiceProviders request);
void DeleteBalanceServiceProvidersById(Guid request);
}
}
12 changes: 12 additions & 0 deletions BackEnd/WebApp/Models/BalanceServiceProviders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace WebApp.Models
{
public class BalanceServiceProviders
{
public Guid Id { get; set; }
public string BspCode { get; set; }
public string BspName { get; set; }
public string BusinessId { get; set; }
public string CodingScheme { get; set; }
public string Country { get; set; }
}
}
29 changes: 29 additions & 0 deletions BackEnd/WebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using WebApp.Helpers;
using WebApp.Repositories;

var builder = WebApplication.CreateBuilder(args);


builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddTransient<IHandleServiceProviders,ProviderRepository>();

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();
52 changes: 52 additions & 0 deletions BackEnd/WebApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5288"
},
"https": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7248;http://localhost:5288"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:24920",
"sslPort": 44328
}
}
}
Loading