Aplicacion inicial
commit
c165c4e507
|
|
@ -0,0 +1,19 @@
|
|||
/.vs/*
|
||||
/obj/*
|
||||
/src/Empresa.App.Application/obj/*
|
||||
/src/VentaUniformes.api/bin/Debug/*
|
||||
/src/Empresa.App.Domain/obj/*
|
||||
/src/VentaUniformes.api/bin/*
|
||||
/src/VentaUniformes.api/obj/*
|
||||
/src/VentaUniformes.app/bin/*
|
||||
/src/VentaUniformes.app/obj/*
|
||||
/src/VentaUniformes.Application/bin/*
|
||||
/src/VentaUniformes.Application/obj/*
|
||||
/src/VentaUniformes.Common/bin/*
|
||||
/src/VentaUniformes.Common/obj/*
|
||||
/src/VentaUniformes.Domain/bin/*
|
||||
/src/VentaUniformes.Domain/obj/*
|
||||
/src/VentaUniformes.External/obj/*
|
||||
/src/VentaUniformes.Persistencia/obj/*
|
||||
/src/VentaUniformes.Persistencia/bin/*
|
||||
/src/VentaUniformes.External/bin/*
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34723.18
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{88D481B0-BD9D-4732-9AE0-4707AE616E01}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{609A233D-1C2C-4041-A03B-F8462D6DFB68}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infraestructure", "Infraestructure", "{E59FA921-6808-48FC-A97D-46187F256EC7}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{D6311563-0AF4-4A92-9EBD-ED86D028EF6A}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{57865052-E859-4E07-B739-CFAC84B05515}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DA87F0AE-9CB9-4453-8C43-5E7AD2B71A73}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F0758F61-2134-49E5-A002-85A021B7B218}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EE0A9118-313B-48E4-8271-AABA50B7D7D0}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VentaUniformes.Application", "src\VentaUniformes.Application\VentaUniformes.Application.csproj", "{CC2DBE75-C8B7-48AF-8C35-8C9CD8D34B30}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VentaUniformes.Domain", "src\VentaUniformes.Domain\VentaUniformes.Domain.csproj", "{9ACA7C27-1ACF-42F9-9030-628888815CB7}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VentaUniformes.Persistencia", "src\VentaUniformes.Persistencia\VentaUniformes.Persistencia.csproj", "{F99418D0-C14F-4435-B693-FA4C860E9059}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VentaUniformes.External", "src\VentaUniformes.External\VentaUniformes.External.csproj", "{00402824-39F8-4C3C-8C36-68D2464ABCA7}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VentaUniformes.app", "src\VentaUniformes.app\VentaUniformes.app.csproj", "{C47A89ED-527B-4D47-9C8B-AD47E152925F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VentaUniformes.Common", "src\VentaUniformes.Common\VentaUniformes.Common.csproj", "{CA11AA4F-42EB-4F84-A3E5-C17BE5DB3B1E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CC2DBE75-C8B7-48AF-8C35-8C9CD8D34B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CC2DBE75-C8B7-48AF-8C35-8C9CD8D34B30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CC2DBE75-C8B7-48AF-8C35-8C9CD8D34B30}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CC2DBE75-C8B7-48AF-8C35-8C9CD8D34B30}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9ACA7C27-1ACF-42F9-9030-628888815CB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9ACA7C27-1ACF-42F9-9030-628888815CB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9ACA7C27-1ACF-42F9-9030-628888815CB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9ACA7C27-1ACF-42F9-9030-628888815CB7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F99418D0-C14F-4435-B693-FA4C860E9059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F99418D0-C14F-4435-B693-FA4C860E9059}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F99418D0-C14F-4435-B693-FA4C860E9059}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F99418D0-C14F-4435-B693-FA4C860E9059}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{00402824-39F8-4C3C-8C36-68D2464ABCA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{00402824-39F8-4C3C-8C36-68D2464ABCA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{00402824-39F8-4C3C-8C36-68D2464ABCA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{00402824-39F8-4C3C-8C36-68D2464ABCA7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C47A89ED-527B-4D47-9C8B-AD47E152925F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C47A89ED-527B-4D47-9C8B-AD47E152925F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C47A89ED-527B-4D47-9C8B-AD47E152925F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C47A89ED-527B-4D47-9C8B-AD47E152925F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CA11AA4F-42EB-4F84-A3E5-C17BE5DB3B1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CA11AA4F-42EB-4F84-A3E5-C17BE5DB3B1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CA11AA4F-42EB-4F84-A3E5-C17BE5DB3B1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CA11AA4F-42EB-4F84-A3E5-C17BE5DB3B1E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{57865052-E859-4E07-B739-CFAC84B05515} = {88D481B0-BD9D-4732-9AE0-4707AE616E01}
|
||||
{DA87F0AE-9CB9-4453-8C43-5E7AD2B71A73} = {D6311563-0AF4-4A92-9EBD-ED86D028EF6A}
|
||||
{F0758F61-2134-49E5-A002-85A021B7B218} = {609A233D-1C2C-4041-A03B-F8462D6DFB68}
|
||||
{EE0A9118-313B-48E4-8271-AABA50B7D7D0} = {E59FA921-6808-48FC-A97D-46187F256EC7}
|
||||
{CC2DBE75-C8B7-48AF-8C35-8C9CD8D34B30} = {F0758F61-2134-49E5-A002-85A021B7B218}
|
||||
{9ACA7C27-1ACF-42F9-9030-628888815CB7} = {F0758F61-2134-49E5-A002-85A021B7B218}
|
||||
{F99418D0-C14F-4435-B693-FA4C860E9059} = {EE0A9118-313B-48E4-8271-AABA50B7D7D0}
|
||||
{00402824-39F8-4C3C-8C36-68D2464ABCA7} = {EE0A9118-313B-48E4-8271-AABA50B7D7D0}
|
||||
{C47A89ED-527B-4D47-9C8B-AD47E152925F} = {57865052-E859-4E07-B739-CFAC84B05515}
|
||||
{CA11AA4F-42EB-4F84-A3E5-C17BE5DB3B1E} = {DA87F0AE-9CB9-4453-8C43-5E7AD2B71A73}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {3C4C824D-0B01-4A6C-BD15-95F92F81A8DC}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>Empresa.App.api</name>
|
||||
</assembly>
|
||||
<members>
|
||||
</members>
|
||||
</doc>
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.configuration;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.DeleteUser;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.UpdateUser;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetAllUser;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetUserById;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetUserByPassAndName;
|
||||
using VentaUniformes.Application.Sesion.Commands.CreateSesion;
|
||||
using VentaUniformes.Application.Validators.Sesion;
|
||||
using VentaUniformes.Application.Validators.User;
|
||||
using FluentValidation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct;
|
||||
using VentaUniformes.Application.VentasView;
|
||||
using VentaUniformes.Application.VentasView.historico;
|
||||
namespace VentaUniformes.Application
|
||||
{
|
||||
public static class DependencyInjectionService
|
||||
{
|
||||
public static IServiceCollection AddAplication(this IServiceCollection services)
|
||||
{
|
||||
var mapper = new MapperConfiguration(confg =>
|
||||
{
|
||||
confg.AddProfile(new MapperProfile());
|
||||
}
|
||||
);
|
||||
#region user
|
||||
services.AddTransient< IcreateUserCommand,CreateUserCommand>();
|
||||
services.AddTransient<IupdateUserCommand, UpdateUserCommand>();
|
||||
services.AddTransient<IDeleteUserCommand, DeleteUserCommand>();
|
||||
services.AddTransient<IGetUserByIdQuery, GetUserByIdQuery>();
|
||||
|
||||
services.AddTransient<IGetAllUserQuery, GetAllUserQuery>();
|
||||
services.AddTransient<IGetUserByPassAndNameQuery, GetUserByPassAndNameQuery>();
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region userValidator
|
||||
|
||||
services.AddScoped<IValidator<CreateUserModel>,CreateUserValidator>();
|
||||
services.AddScoped<IValidator<UpdateUserModel>, UpdateUserValidator>();
|
||||
|
||||
services.AddScoped<IValidator<(string, string)>, GetUserByPassAndNameValidator>();
|
||||
services.AddScoped<IValidator<InCreateSesionModel>, InCreateSesionValidator>();
|
||||
|
||||
|
||||
#endregion
|
||||
#region product
|
||||
|
||||
services.AddTransient<IGetAllProductQuery, GetAllProductQuery >();
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#region ventasView
|
||||
services.AddTransient<IVentasViewService, VentasViewService>();
|
||||
|
||||
|
||||
services.AddTransient<IVentasHistoricoViewService, VentasHistoricoViewService>();
|
||||
#endregion
|
||||
#region Sesion
|
||||
|
||||
services.AddTransient<ICreateSesionCommand, CreateSesionCommand>();
|
||||
#endregion
|
||||
|
||||
services.AddSingleton(mapper.CreateMapper());
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using VentaUniformes.Application.Features;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace VentaUniformes.Application.Exceptions
|
||||
{
|
||||
//captura errores
|
||||
public class ExceptionManager : IExceptionFilter
|
||||
{
|
||||
public void OnException(ExceptionContext context)
|
||||
{
|
||||
context.Result = new ObjectResult(ResponseApiService.Response(
|
||||
StatusCodes.Status500InternalServerError,context.Exception.Message
|
||||
));
|
||||
context.HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using VentaUniformes.Domain.Models;
|
||||
|
||||
namespace VentaUniformes.Application.Features
|
||||
{
|
||||
public static class ResponseApiService
|
||||
{
|
||||
public static BaseResponseModel Response(int statusCode, object data=null, string msg=null)
|
||||
{
|
||||
bool success = false;
|
||||
if(statusCode>=200 && statusCode<300)
|
||||
success = true;
|
||||
var result = new BaseResponseModel
|
||||
{
|
||||
StatusCode = statusCode,
|
||||
Success = success,
|
||||
Data = data,
|
||||
Message = msg
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Enums;
|
||||
|
||||
namespace VentaUniformes.Application.Interfaces.External
|
||||
{
|
||||
public interface IGetTokenJwtService
|
||||
{
|
||||
public string Execute(string id, RoleUserType role);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Interfaces.External
|
||||
{
|
||||
public interface IValidateTokenService
|
||||
{
|
||||
public bool ValidateToken(string token);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Entities.Customer;
|
||||
using VentaUniformes.Domain.Entities.Sale;
|
||||
|
||||
namespace VentaUniformes.Application.Interfaces
|
||||
{
|
||||
//servicion para guardar datos
|
||||
public interface IPersistenciaService
|
||||
{
|
||||
public Task<bool> AddUser(UserEntity user);
|
||||
public Task<bool> UpdateUser(UserEntity user);
|
||||
public Task<bool> DeleteUser(int idUser);
|
||||
|
||||
public Task<bool> UpdateNoNullUser(UserEntity user);
|
||||
public Task<List<UserEntity>> GetAllUser();
|
||||
public Task<UserEntity> GetUserById(int idUser);
|
||||
public Task<UserEntity> GetUserByPassAndName(string pass, string name);
|
||||
|
||||
|
||||
public Task<List<ProductEntity>> GetAllProduct();
|
||||
public Task<ProductEntity> GetProductById(int idProduct);
|
||||
|
||||
public Task<int> AddSale(SaleEntity e);
|
||||
public Task<bool> DeleteSale(int idSale);
|
||||
public Task<bool> AddSaleBill(SaleBillEntity e);
|
||||
public Task<bool> AddLineSales(List<SaleLineEntity> e);
|
||||
|
||||
public Task<List<SaleEntity>> GetSale(int top, string alumnoFilter);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct
|
||||
{
|
||||
public class GetAllProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public double Price { get; set; }
|
||||
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetAllUser;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct
|
||||
{
|
||||
public class GetAllProductQuery : IGetAllProductQuery
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
IMapper _mapper;
|
||||
public GetAllProductQuery(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public async Task<List<GetAllProductModel>> Execute()
|
||||
{
|
||||
var l = await _persistenciaService.GetAllProduct();
|
||||
return _mapper.Map<List<GetAllProductModel>>(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetAllUser;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct
|
||||
{
|
||||
public interface IGetAllProductQuery
|
||||
{
|
||||
public Task<List<GetAllProductModel>> Execute();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetAllUser
|
||||
{
|
||||
public class GetAllUserModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FristName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.UpdateUser;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetAllUser
|
||||
{
|
||||
public class GetAllUserQuery: IGetAllUserQuery
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
IMapper _mapper;
|
||||
public GetAllUserQuery(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public async Task<List<GetAllUserModel>> Execute()
|
||||
{
|
||||
var l = await _persistenciaService.GetAllUser();
|
||||
return _mapper.Map<List<GetAllUserModel>>(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetAllUser
|
||||
{
|
||||
public interface IGetAllUserQuery
|
||||
{
|
||||
public Task<List<GetAllUserModel>> Execute();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetUserById
|
||||
{
|
||||
public class GetUserByIdModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FristName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.UpdateUser;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetUserById
|
||||
{
|
||||
public class GetUserByIdQuery: IGetUserByIdQuery
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
IMapper _mapper;
|
||||
public GetUserByIdQuery(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public async Task<GetUserByIdModel> Execute(int id)
|
||||
{
|
||||
|
||||
//aqui se guarda realmente
|
||||
var enty= await _persistenciaService.GetUserById(id);
|
||||
return _mapper.Map<GetUserByIdModel>(enty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
using VentaUniformes.Application.Persistencia.user.Queries.GetAllUser;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetUserById
|
||||
{
|
||||
public interface IGetUserByIdQuery
|
||||
{
|
||||
public Task<GetUserByIdModel> Execute(int id);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Enums;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetUserByPassAndName
|
||||
{
|
||||
public class GetUserByPassAndNameModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public RoleUserType Role { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetUserById;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetUserByPassAndName
|
||||
{
|
||||
public class GetUserByPassAndNameQuery: IGetUserByPassAndNameQuery
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
IMapper _mapper;
|
||||
public GetUserByPassAndNameQuery(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public async Task<GetUserByPassAndNameModel> Execute(string pass, string name)
|
||||
{
|
||||
|
||||
//aqui se guarda realmente
|
||||
var enty = await _persistenciaService.GetUserByPassAndName(pass, name);
|
||||
return _mapper.Map<GetUserByPassAndNameModel>(enty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.Queries.GetUserByPassAndName
|
||||
{
|
||||
public interface IGetUserByPassAndNameQuery
|
||||
{
|
||||
public Task<GetUserByPassAndNameModel> Execute(string pass, string name);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.CreateUser
|
||||
{
|
||||
public class CreateUserCommand: IcreateUserCommand
|
||||
{
|
||||
private readonly IPersistenciaService _persistenciaService;
|
||||
private IMapper _mapper;
|
||||
|
||||
public CreateUserCommand(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public async Task<CreateUserModel>Execute(CreateUserModel model)
|
||||
{
|
||||
var entity = _mapper.Map<UserEntity>(model);
|
||||
//aqui se guarda realmente
|
||||
await _persistenciaService.AddUser(entity);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.CreateUser
|
||||
{
|
||||
public class CreateUserModel
|
||||
{
|
||||
public string FristName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.CreateUser
|
||||
{
|
||||
public interface IcreateUserCommand
|
||||
{
|
||||
public Task<CreateUserModel> Execute(CreateUserModel model);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.UpdateUser;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.DeleteUser
|
||||
{
|
||||
public class DeleteUserCommand: IDeleteUserCommand
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
public DeleteUserCommand(IPersistenciaService persistenciaService)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
}
|
||||
public async Task<bool> Execute(int id)
|
||||
{
|
||||
//aqui se guarda realmente
|
||||
return await _persistenciaService.DeleteUser(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.DeleteUser
|
||||
{
|
||||
public interface IDeleteUserCommand
|
||||
{
|
||||
public Task<bool> Execute(int id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.UpdateUser
|
||||
{
|
||||
public interface IupdateUserCommand
|
||||
{
|
||||
public Task<UpdateUserModel> Execute(UpdateUserModel UpdateUserModel);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.UpdateUser
|
||||
{
|
||||
public class UpdateUserCommand : IupdateUserCommand
|
||||
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
IMapper _mapper;
|
||||
public UpdateUserCommand(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
public async Task<UpdateUserModel> Execute(UpdateUserModel model)
|
||||
{
|
||||
var entity = _mapper.Map<UserEntity>(model);
|
||||
//aqui se guarda realmente
|
||||
await _persistenciaService.UpdateUser(entity);
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Persistencia.user.commands.UpdateUser
|
||||
{
|
||||
public class UpdateUserModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FristName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Interfaces.External;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetUserByPassAndName;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Sesion.Commands.CreateSesion
|
||||
{
|
||||
public class CreateSesionCommand: ICreateSesionCommand
|
||||
{
|
||||
private readonly IGetTokenJwtService _jwtService;
|
||||
private IGetUserByPassAndNameQuery _userService;
|
||||
|
||||
public CreateSesionCommand(IGetTokenJwtService jwtService, IGetUserByPassAndNameQuery userService)
|
||||
{
|
||||
_jwtService = jwtService;
|
||||
_userService = userService;
|
||||
}
|
||||
public async Task<CreateSesionModel> Execute(InCreateSesionModel data)
|
||||
{
|
||||
|
||||
var entity = await _userService.Execute(data.Password, data.UserName);
|
||||
if (entity == null)
|
||||
return null;
|
||||
var res = new CreateSesionModel();
|
||||
res.UserId = entity.Id;
|
||||
res.Role = (int)entity.Role;
|
||||
|
||||
res.Token = _jwtService.Execute(res.UserId.ToString(), entity.Role);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Sesion.Commands.CreateSesion
|
||||
{
|
||||
public class CreateSesionModel
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public int Role { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Sesion.Commands.CreateSesion
|
||||
{
|
||||
public interface ICreateSesionCommand
|
||||
{
|
||||
public Task<CreateSesionModel> Execute(InCreateSesionModel data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Sesion.Commands.CreateSesion
|
||||
{
|
||||
public class InCreateSesionModel
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformes.Application.Sesion.Commands.CreateSesion;
|
||||
using FluentValidation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Validators.Sesion
|
||||
{
|
||||
public class InCreateSesionValidator : AbstractValidator<InCreateSesionModel>
|
||||
{
|
||||
public InCreateSesionValidator()
|
||||
{
|
||||
RuleFor(x => x.Password).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.UserName).NotNull().NotEmpty().MaximumLength(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using FluentValidation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Validators.User
|
||||
{
|
||||
public class CreateUserValidator:AbstractValidator<CreateUserModel>
|
||||
{
|
||||
public CreateUserValidator() {
|
||||
RuleFor(x=>x.FristName).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.LastName).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.UserName).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.Password).NotNull().NotEmpty().MaximumLength(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using VentaUniformes.Application.Persistencia.user.commands.UpdateUser;
|
||||
using FluentValidation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Validators.User
|
||||
{
|
||||
public class GetUserByPassAndNameValidator : AbstractValidator<(string, string)>
|
||||
{
|
||||
public GetUserByPassAndNameValidator()
|
||||
{
|
||||
RuleFor(x => x.Item1).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.Item2).NotNull().NotEmpty().MaximumLength(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.UpdateUser;
|
||||
using FluentValidation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.Validators.User
|
||||
{
|
||||
public class UpdateUserValidator : AbstractValidator<UpdateUserModel>
|
||||
{
|
||||
public UpdateUserValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotNull().GreaterThan(0);//que no sea nulo y mayor que 0
|
||||
RuleFor(x => x.FristName).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.LastName).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.UserName).NotNull().NotEmpty().MaximumLength(50);
|
||||
RuleFor(x => x.Password).NotNull().NotEmpty().MaximumLength(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="FluentValidation" Version="11.10.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VentaUniformes.Domain\VentaUniformes.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView
|
||||
{
|
||||
public interface IVentasViewService
|
||||
{
|
||||
public Task<VentasViewModel> GetNewVenta();
|
||||
public Task<VentasViewModel> GetVenta(int IdVenta);
|
||||
public Task<bool> BorraVenta(int idSale);
|
||||
public Task<bool> Save(VentasViewModel model);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView
|
||||
{
|
||||
public class LineVentasViewModel
|
||||
{
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public float Price { get; set; }
|
||||
public int Cantidad { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView
|
||||
{
|
||||
public class VentasViewModel
|
||||
{
|
||||
public string Alumno { get; set; }
|
||||
public string Curso { get; set; }
|
||||
public int ModoPago { get; set; }
|
||||
public bool isBill { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string DNI { get; set; }
|
||||
public List<LineVentasViewModel> Productos { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct;
|
||||
using VentaUniformes.Domain.Entities.Sale;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView
|
||||
{
|
||||
public class VentasViewService: IVentasViewService
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
IMapper _mapper;
|
||||
public VentasViewService(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<bool> BorraVenta(int idSale)
|
||||
{
|
||||
return await _persistenciaService.DeleteSale(idSale);
|
||||
}
|
||||
|
||||
public async Task<VentasViewModel> GetNewVenta()
|
||||
{
|
||||
VentasViewModel res = new VentasViewModel();
|
||||
res.Alumno = "";
|
||||
res.Curso = "";
|
||||
res.ModoPago = 0;
|
||||
|
||||
var l = await _persistenciaService.GetAllProduct();
|
||||
res.Productos = _mapper.Map<List<LineVentasViewModel>>(l);
|
||||
return res;
|
||||
}
|
||||
public async Task<VentasViewModel> GetVenta(int IdVenta)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> Save(VentasViewModel model)
|
||||
{
|
||||
var venta = new SaleEntity();
|
||||
venta.Alumno=model.Alumno;
|
||||
venta.Curso = model.Curso;
|
||||
venta.Fecha = DateTime.Now;
|
||||
venta.PaymentType = model.ModoPago;
|
||||
venta.Total = 0;
|
||||
foreach (var l in model.Productos)
|
||||
{
|
||||
venta.Total += (l.Price * l.Cantidad);
|
||||
}
|
||||
|
||||
|
||||
var idsale =await _persistenciaService.AddSale(venta);
|
||||
if(idsale<0)
|
||||
return false;
|
||||
|
||||
if(model.isBill)
|
||||
{
|
||||
var bill=new SaleBillEntity();
|
||||
bill.Name=model.Name;
|
||||
bill.DNI = model.DNI;
|
||||
bill.SaleId=idsale;
|
||||
if(!await _persistenciaService.AddSaleBill(bill))
|
||||
return false;
|
||||
}
|
||||
var lines = new List<SaleLineEntity>();
|
||||
foreach (var l in model.Productos)
|
||||
{
|
||||
if (l.Cantidad > 0)
|
||||
{
|
||||
var line = new SaleLineEntity();
|
||||
line.SaleId = idsale;
|
||||
line.ProductId = l.Id;
|
||||
line.Price = (float)l.Price;
|
||||
line.Amount = l.Cantidad;
|
||||
lines.Add(line);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return await _persistenciaService.AddLineSales(lines);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView.historico.Borrar
|
||||
{
|
||||
public class VentaHistoricoBorrarViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Alumno { get; set; }
|
||||
public string Curso { get; set; }
|
||||
public double Total { get; set; }
|
||||
|
||||
public string AlumnoFiltro { get; set; }
|
||||
public int Top { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView.historico
|
||||
{
|
||||
public interface IVentasHistoricoViewService
|
||||
{
|
||||
public Task<VentasHistoricoViewModel> GetVentas();
|
||||
public Task<VentasHistoricoViewModel> GetVentas(VentasHistoricoViewModel model);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView.historico
|
||||
{
|
||||
public class VentaLineHistoricoViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Alumno { get; set; }
|
||||
public string Curso { get; set; }
|
||||
public float Total { get; set; }
|
||||
public DateTime fecha { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView.historico
|
||||
{
|
||||
public class VentasHistoricoViewModel
|
||||
{
|
||||
public string Alumno { get; set; }
|
||||
public int Top { get; set; }
|
||||
public List<VentaLineHistoricoViewModel> ventas { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
|
||||
namespace VentaUniformes.Application.VentasView.historico
|
||||
{
|
||||
public class VentasHistoricoViewService: IVentasHistoricoViewService
|
||||
{
|
||||
IPersistenciaService _persistenciaService;
|
||||
IMapper _mapper;
|
||||
public VentasHistoricoViewService(IPersistenciaService persistenciaService, IMapper mapper)
|
||||
{
|
||||
_persistenciaService = persistenciaService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<VentasHistoricoViewModel> GetVentas()
|
||||
{
|
||||
var res = new VentasHistoricoViewModel();
|
||||
res.Alumno = "";
|
||||
res.Top = 25;
|
||||
return await GetVentas(res);
|
||||
}
|
||||
public async Task<VentasHistoricoViewModel> GetVentas(VentasHistoricoViewModel model)
|
||||
{
|
||||
|
||||
var l = await _persistenciaService.GetSale(model.Top, model.Alumno);
|
||||
model.ventas = _mapper.Map<List<VentaLineHistoricoViewModel>>(l);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
using AutoMapper;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformes.Application.Persistencia.user.commands.UpdateUser;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetAllUser;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetUserById;
|
||||
using VentaUniformes.Application.Persistencia.user.Queries.GetUserByPassAndName;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Entities.Customer;
|
||||
using VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct;
|
||||
using VentaUniformes.Application.VentasView;
|
||||
using VentaUniformes.Application.VentasView.historico;
|
||||
using VentaUniformes.Domain.Entities.Sale;
|
||||
|
||||
namespace VentaUniformes.Application.configuration
|
||||
{
|
||||
public class MapperProfile : Profile
|
||||
{
|
||||
public MapperProfile()
|
||||
{
|
||||
CreateMap<UserEntity, CreateUserModel>().ReverseMap();
|
||||
CreateMap<UserEntity, UpdateUserModel>().ReverseMap();
|
||||
CreateMap<GetAllUserModel, UserEntity>().ReverseMap();
|
||||
CreateMap<GetUserByIdModel, UserEntity>().ReverseMap();
|
||||
CreateMap<GetUserByPassAndNameModel, UserEntity>().ReverseMap();
|
||||
|
||||
CreateMap<GetAllProductModel, ProductEntity>().ReverseMap();
|
||||
CreateMap<LineVentasViewModel, ProductEntity>().ReverseMap();
|
||||
CreateMap<VentaLineHistoricoViewModel, SaleEntity>().ReverseMap();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.External;
|
||||
using VentaUniformes.Persistencia;
|
||||
namespace VentaUniformes.Common
|
||||
{
|
||||
public static class DependencyInjectionService
|
||||
{
|
||||
public static IServiceCollection AddCommon(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
services.AddExternal(config)
|
||||
.AddPersistencia(config);
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VentaUniformes.Application\VentaUniformes.Application.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformes.Domain\VentaUniformes.Domain.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformes.External\VentaUniformes.External.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformes.Persistencia\VentaUniformes.Persistencia.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Domain.Entities.Customer
|
||||
{
|
||||
public class ProductEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public double Price { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Domain.Entities.PurchaseReturn
|
||||
{
|
||||
public class PurchaseReturnEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SaleId { get; set; }
|
||||
public DateTime Fecha { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Domain.Entities.PurchaseReturn
|
||||
{
|
||||
public class PurchaseReturnLineEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int PurchaseReturnId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public float Price { get; set; }
|
||||
public int Amount { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Domain.Entities.Sale
|
||||
{
|
||||
public class SaleBillEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SaleId { get; set; }
|
||||
public string DNI { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using VentaUniformes.Domain.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Domain.Entities.Sale
|
||||
{
|
||||
public class SaleEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Alumno { get; set; }
|
||||
public string Curso { get; set; }
|
||||
public DateTime Fecha { get; set; }
|
||||
public int PaymentType { get; set; }
|
||||
|
||||
public double Total { get; set; }
|
||||
public bool IsDelete { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Domain.Entities.Sale
|
||||
{
|
||||
public class SaleLineEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SaleId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public float Price { get; set; }
|
||||
public int Amount { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Enums;
|
||||
|
||||
namespace VentaUniformes.Domain.Entities.User
|
||||
{
|
||||
public class UserEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public RoleUserType Role { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Domain.Enums
|
||||
{
|
||||
public enum RoleUserType
|
||||
{
|
||||
Admin,
|
||||
User,
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
|
||||
namespace VentaUniformes.Domain.Models
|
||||
{
|
||||
public class BaseResponseModel
|
||||
{
|
||||
public int StatusCode { get; set; }
|
||||
public string Message { get; set; }
|
||||
public bool Success { get; set; }
|
||||
public dynamic Data { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
namespace VentaUniformes.Domain.Models
|
||||
{
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="F:\desa\v2022\VentaUniformes\src\VentaUniformes.Domain\Entities\Sale\SaleBillEntity.cs" Link="SaleBillEntity.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Entities\Sale\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
using VentaUniformes.Application.Interfaces.External;
|
||||
using VentaUniformes.External.GetTokenJWT;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Enums;
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using VentaUniformes.External.ValidateTokenJwt;
|
||||
|
||||
namespace VentaUniformes.External
|
||||
{
|
||||
public static class DependencyInjectionService
|
||||
{
|
||||
public static IServiceCollection AddExternal(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
|
||||
services.AddSingleton<IGetTokenJwtService, GetTokenJwtService>();
|
||||
services.AddSingleton<IValidateTokenService, ValidateTokenJwtService>();
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(option =>
|
||||
{
|
||||
option.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["SecretKeyJwt"])),
|
||||
ValidIssuer = config["IssuerJWT"],
|
||||
ValidAudience = config["AudienceJwt"]
|
||||
|
||||
};
|
||||
option.Events = new JwtBearerEvents
|
||||
{
|
||||
OnMessageReceived = context =>
|
||||
{
|
||||
var cookie = context.Request.Cookies["JwtToken"];
|
||||
if (!string.IsNullOrEmpty(cookie))
|
||||
{
|
||||
context.Token = cookie;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy("AdminOnly", policy => policy.RequireRole(RoleUserType.Admin.ToString()));
|
||||
});
|
||||
|
||||
//services.AddAuthorization();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
using VentaUniformes.Application.Interfaces.External;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using VentaUniformes.Domain.Enums;
|
||||
|
||||
namespace VentaUniformes.External.GetTokenJWT
|
||||
{
|
||||
public class GetTokenJwtService: IGetTokenJwtService
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
public GetTokenJwtService(IConfiguration config)
|
||||
{
|
||||
_config= config;
|
||||
}
|
||||
public string Execute(string id, RoleUserType role)
|
||||
{
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
string key = _config["SecretKeyJwt"]??"";
|
||||
var singinkey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
|
||||
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject= new ClaimsIdentity(new Claim[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, id),
|
||||
new Claim(ClaimTypes.Role, role.ToString())
|
||||
}),
|
||||
Expires= DateTime.UtcNow.AddMinutes(int.Parse(_config["TimeLogin"])),//expira en un dia
|
||||
SigningCredentials=new SigningCredentials(singinkey,SecurityAlgorithms.HmacSha256Signature),
|
||||
Issuer = _config["IssuerJWT"],
|
||||
Audience = _config["AudienceJwt"],
|
||||
|
||||
};
|
||||
|
||||
var token= tokenHandler.CreateToken(tokenDescriptor);
|
||||
|
||||
var tokenString = tokenHandler.WriteToken(token);
|
||||
return tokenString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Application.Interfaces.External;
|
||||
|
||||
namespace VentaUniformes.External.ValidateTokenJwt
|
||||
{
|
||||
public class ValidateTokenJwtService: IValidateTokenService
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
public ValidateTokenJwtService(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
public bool ValidateToken(string token)
|
||||
{
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.UTF8.GetBytes(_config["SecretKeyJwt"] ?? ""); // La clave secreta que usaste para firmar el token
|
||||
try
|
||||
{
|
||||
tokenHandler.ValidateToken(token, new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = _config["IssuerJWT"],
|
||||
ValidAudience = _config["AudienceJwt"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key)
|
||||
}, out SecurityToken validatedToken);
|
||||
|
||||
// Si el token es válido, regresa true
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Si el token no es válido, regresa false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VentaUniformes.Application\VentaUniformes.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using VentaUniformes.Domain.Entities.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Entities.Customer;
|
||||
|
||||
namespace VentaUniformes.Persistencia.Configurations
|
||||
{
|
||||
public class ProductConfiguration
|
||||
{
|
||||
public ProductConfiguration( EntityTypeBuilder<ProductEntity> entityBuilder) {
|
||||
entityBuilder.ToTable("Product");
|
||||
entityBuilder.HasKey(x => x.Id);
|
||||
entityBuilder.Property(x => x.Name).IsRequired();
|
||||
entityBuilder.Property(x => x.Price).IsRequired();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using VentaUniformes.Domain.Entities.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Entities.Sale;
|
||||
|
||||
namespace VentaUniformes.Persistencia.Configurations
|
||||
{
|
||||
public class SaleBillConfiguration
|
||||
{
|
||||
public SaleBillConfiguration( EntityTypeBuilder<SaleBillEntity> entityBuilder) {
|
||||
entityBuilder.ToTable("SaleBill");
|
||||
entityBuilder.HasKey(x => x.Id);
|
||||
entityBuilder.Property(x => x.DNI).IsRequired();
|
||||
entityBuilder.Property(x => x.SaleId).IsRequired();
|
||||
entityBuilder.Property(x => x.Name).IsRequired();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
using VentaUniformes.Domain.Entities.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Entities.Sale;
|
||||
|
||||
namespace VentaUniformes.Persistencia.Configurations
|
||||
{
|
||||
public class SaleConfiguration
|
||||
{
|
||||
public SaleConfiguration( EntityTypeBuilder<SaleEntity> entityBuilder) {
|
||||
entityBuilder.ToTable("Sale");
|
||||
entityBuilder.HasKey(x => x.Id);
|
||||
entityBuilder.Property(x => x.Curso).IsRequired();
|
||||
entityBuilder.Property(x => x.Alumno).IsRequired();
|
||||
entityBuilder.Property(x => x.Fecha).IsRequired();
|
||||
entityBuilder.Property(x => x.PaymentType).IsRequired();
|
||||
|
||||
entityBuilder.Property(x => x.Total).IsRequired();
|
||||
entityBuilder.Property(x => x.IsDelete).IsRequired();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using VentaUniformes.Domain.Entities.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Entities.Sale;
|
||||
|
||||
namespace VentaUniformes.Persistencia.Configurations
|
||||
{
|
||||
public class SaleLineConfiguration
|
||||
{
|
||||
public SaleLineConfiguration( EntityTypeBuilder<SaleLineEntity> entityBuilder) {
|
||||
entityBuilder.ToTable("SaleLine");
|
||||
entityBuilder.HasKey(x => x.Id);
|
||||
entityBuilder.Property(x => x.Price).IsRequired();
|
||||
entityBuilder.Property(x => x.SaleId).IsRequired();
|
||||
entityBuilder.Property(x => x.ProductId).IsRequired();
|
||||
entityBuilder.Property(x => x.Amount).IsRequired();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using VentaUniformes.Domain.Entities.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VentaUniformes.Persistencia.Configurations
|
||||
{
|
||||
public class UserConfiguration
|
||||
{
|
||||
public UserConfiguration( EntityTypeBuilder<UserEntity> entityBuilder) {
|
||||
entityBuilder.ToTable("User");
|
||||
entityBuilder.HasKey(x => x.Id);
|
||||
entityBuilder.Property(x => x.UserName).IsRequired();
|
||||
entityBuilder.Property(x => x.Role).IsRequired();
|
||||
entityBuilder.Property(x => x.Password).IsRequired();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using VentaUniformes.Persistencia.Services;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Data.SqlClient;
|
||||
namespace VentaUniformes.Persistencia
|
||||
{
|
||||
public static class DependencyInjectionService
|
||||
{
|
||||
public static IServiceCollection AddPersistencia(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
services.AddDbContext<PersistenciaService>( options =>
|
||||
options.UseSqlServer(config["SqlConnectionString"]));
|
||||
|
||||
services.AddScoped<IPersistenciaService, PersistenciaService>();
|
||||
|
||||
|
||||
//para cifrado de bbdd
|
||||
/*
|
||||
* Falta investigar como hacer un probaider de certificados
|
||||
* * /
|
||||
|
||||
SqlConnection.RegisterColumnEncryptionKeyStoreProviders(new Dictionary<string,
|
||||
SqlColumnEncryptionCertificateStoreProvider>(1)//, StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ SqlColumnEncryptionCertificateStoreProvider.ProviderName,provaider_certificados }
|
||||
});
|
||||
|
||||
*/
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
USE [VentaUniformes]
|
||||
GO
|
||||
|
||||
SET ANSI_NULLS ON
|
||||
GO
|
||||
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
--motivos cancelacion
|
||||
-- DROP TABLE [INNOVACION].[dbo].[User]
|
||||
-- SELECT * FROM [INNOVACION].[dbo].[User]
|
||||
CREATE TABLE [VentaUniformes].[dbo].[User](
|
||||
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[UserName] [nvarchar](125) NULL,
|
||||
[Role] [int] NOT NULL,
|
||||
[Password] [nvarchar](256) NULL
|
||||
PRIMARY KEY ([ID])
|
||||
)
|
||||
insert into [VentaUniformes].[dbo].[User]
|
||||
([UserName], [Role], [Password])
|
||||
values
|
||||
('admin', 0, 'admin');
|
||||
--select * FROM [VentaUniformes].[dbo].[SaleLine]
|
||||
--DROP TABLE [VentaUniformes].[dbo].[SaleLine]
|
||||
CREATE TABLE [VentaUniformes].[dbo].[SaleLine](
|
||||
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||
|
||||
[SaleId] [int] NOT NULL,
|
||||
[ProductId] [int] NOT NULL,
|
||||
[Amount] [int] NOT NULL,
|
||||
[Price] [float] NULL
|
||||
PRIMARY KEY ([ID])
|
||||
)
|
||||
--ALTER TABLE [VentaUniformes].[dbo].[Sale]
|
||||
--ADD IsDelete BIT DEFAULT 0;
|
||||
-- DROP TABLE [VentaUniformes].[dbo].[Sale]
|
||||
--DELETE FROM [VentaUniformes].[dbo].[Sale];
|
||||
--select * from [VentaUniformes].[dbo].[Sale]
|
||||
-- update [VentaUniformes].[dbo].[Sale] set IsDelete=0
|
||||
CREATE TABLE [VentaUniformes].[dbo].[Sale](
|
||||
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[Curso] [nvarchar](128) NOT NULL,
|
||||
[Alumno] [nvarchar](256) NOT NULL,
|
||||
[PaymentType] [int] NOT NULL,
|
||||
[Fecha] [date] NOT NULL,
|
||||
[Total] [float] NOT NULL,
|
||||
IsDelete bit not NULL
|
||||
PRIMARY KEY ([ID])
|
||||
)
|
||||
--DELETE FROM [VentaUniformes].[dbo].[SaleBill];
|
||||
CREATE TABLE [VentaUniformes].[dbo].[SaleBill](
|
||||
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[DNI] [nvarchar](128) NULL,
|
||||
[Name] [nvarchar](256) NULL,
|
||||
[SaleId] [int] NOT NULL
|
||||
PRIMARY KEY ([ID])
|
||||
)
|
||||
-- DROP TABLE [VentaUniformes].[dbo].[Product]
|
||||
CREATE TABLE [VentaUniformes].[dbo].[Product](
|
||||
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[Name] [nvarchar](256) NULL,
|
||||
[Description] [nvarchar](256) NULL,
|
||||
[Price] [float] NULL
|
||||
PRIMARY KEY ([ID])
|
||||
)
|
||||
|
||||
insert into [VentaUniformes].[dbo].[Product]
|
||||
( [Name],[Description], Price)
|
||||
values
|
||||
('Producto 1', 'Descripcion 1', 10),
|
||||
('Producto 2', 'Descripcion 1', 10.3436);
|
||||
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
using VentaUniformes.Persistencia.Configurations;
|
||||
using VentaUniformes.Application.Interfaces;
|
||||
using VentaUniformes.Domain.Entities.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VentaUniformes.Domain.Entities.Customer;
|
||||
using VentaUniformes.Domain.Entities.Sale;
|
||||
using VentaUniformes.Domain.Enums;
|
||||
|
||||
namespace VentaUniformes.Persistencia.Services
|
||||
{
|
||||
public class PersistenciaService : DbContext, IPersistenciaService
|
||||
{
|
||||
public PersistenciaService(DbContextOptions options): base(options)
|
||||
{
|
||||
}
|
||||
public DbSet<UserEntity> User { get; set; }
|
||||
public DbSet<ProductEntity> Product { get; set; }
|
||||
public DbSet<SaleEntity> Sales { get; set; }
|
||||
public DbSet<SaleBillEntity> SaleBill { get; set; }
|
||||
public DbSet<SaleLineEntity> SalesLine { get; set; }
|
||||
|
||||
|
||||
|
||||
#region user
|
||||
public async Task<bool> AddUser(UserEntity user)
|
||||
{
|
||||
User.Add(user);
|
||||
return await BoolAsync();
|
||||
}
|
||||
public async Task<bool> UpdateUser(UserEntity user)
|
||||
{
|
||||
User.Update(user);
|
||||
return await BoolAsync();
|
||||
}
|
||||
public async Task<bool> DeleteUser(int idUser)
|
||||
{
|
||||
var enty= await User.FirstOrDefaultAsync(x => x.Id == idUser);
|
||||
if (enty == null)
|
||||
return false;
|
||||
User.Remove(enty);
|
||||
return await BoolAsync();
|
||||
}
|
||||
public async Task<bool> UpdateNoNullUser(UserEntity user)
|
||||
{
|
||||
var enty = await User.FirstOrDefaultAsync(x => x.Id == user.Id);
|
||||
if (enty == null)
|
||||
return false;
|
||||
if(user.Password!=null)
|
||||
enty.Password= user.Password;
|
||||
|
||||
if (user.UserName != null)
|
||||
enty.UserName = user.UserName;
|
||||
|
||||
return await BoolAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<UserEntity>> GetAllUser()
|
||||
{
|
||||
return await User.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<UserEntity> GetUserById(int idUser)
|
||||
{
|
||||
var enty = await User.FirstOrDefaultAsync(x => x.Id == idUser);
|
||||
return enty;
|
||||
}
|
||||
|
||||
public async Task<UserEntity> GetUserByPassAndName(string pass, string name)
|
||||
{
|
||||
var enty = await User.FirstOrDefaultAsync(x => (x.Password == pass) && (x.UserName==name));
|
||||
return enty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region producto
|
||||
public async Task<List<ProductEntity>> GetAllProduct()
|
||||
{
|
||||
return await Product.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<ProductEntity> GetProductById(int idProduct)
|
||||
{
|
||||
var enty = await Product.FirstOrDefaultAsync(x => x.Id == idProduct);
|
||||
return enty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region venta
|
||||
|
||||
public async Task<List<SaleEntity>> GetSale(int top, string alumnoFilter )
|
||||
{
|
||||
var res=Sales.Where(s =>!s.IsDelete&&( String.IsNullOrEmpty(alumnoFilter) || s.Alumno.ToLower().Contains(alumnoFilter.ToLower())))
|
||||
.OrderByDescending(e => e.Id)
|
||||
.Take(top);
|
||||
if (res == null)
|
||||
return new List<SaleEntity>();
|
||||
return res.ToList();
|
||||
}
|
||||
|
||||
public async Task<int> AddSale(SaleEntity e)
|
||||
{
|
||||
Sales.Add(e);
|
||||
if (await BoolAsync())
|
||||
return e.Id;
|
||||
else return -1;
|
||||
}
|
||||
public async Task<bool> DeleteSale(int idSale)
|
||||
{
|
||||
var sale= Sales.FirstOrDefault(e=>!e.IsDelete && e.Id==idSale );
|
||||
if(sale==null)
|
||||
return false;
|
||||
sale.IsDelete=true;
|
||||
|
||||
return await BoolAsync();
|
||||
}
|
||||
public async Task<bool> AddSaleBill(SaleBillEntity e)
|
||||
{
|
||||
SaleBill.Add(e);
|
||||
return await BoolAsync();
|
||||
}
|
||||
public async Task<bool> AddLineSales(List<SaleLineEntity> e)
|
||||
{
|
||||
SalesLine.AddRange(e);
|
||||
return await BoolAsync();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private async Task<bool> BoolAsync()
|
||||
{
|
||||
return await SaveChangesAsync()>0;
|
||||
}
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
EntityConfigration(modelBuilder);
|
||||
}
|
||||
private void EntityConfigration(ModelBuilder model)
|
||||
{
|
||||
//configuras entidades relaccionadas con bbdd
|
||||
new UserConfiguration(model.Entity<UserEntity>());
|
||||
new ProductConfiguration(model.Entity<ProductEntity>());
|
||||
new SaleLineConfiguration(model.Entity<SaleLineEntity>());
|
||||
new SaleConfiguration(model.Entity<SaleEntity>());
|
||||
new SaleBillConfiguration(model.Entity<SaleBillEntity>());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="5.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VentaUniformes.Application\VentaUniformes.Application.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformes.Domain\VentaUniformes.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Scrips\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "8.0.10",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
],
|
||||
"rollForward": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using VentaUniformesApplication.Features;
|
||||
using VentaUniformesApplication.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformesApplication.Sesion.Commands.CreateSesion;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
//using System.Web.Http;
|
||||
|
||||
namespace VentaUniformesapi.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/v1/Sesion")]
|
||||
[ApiController]
|
||||
public class SesionController : ControllerBase
|
||||
{
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create(
|
||||
[FromBody] InCreateSesionModel model,
|
||||
[FromServices] ICreateSesionCommand createSesionCommand,
|
||||
[FromServices] IValidator<InCreateSesionModel> validador
|
||||
)
|
||||
{
|
||||
var validacion = await validador.ValidateAsync(model);
|
||||
if (!validacion.IsValid)
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest, validacion.Errors));
|
||||
|
||||
var data = await createSesionCommand.Execute(model);
|
||||
|
||||
|
||||
//var n=int.Parse("h");
|
||||
return StatusCode(StatusCodes.Status201Created, ResponseApiService.Response(StatusCodes.Status201Created, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
using VentaUniformesApplication.Exceptions;
|
||||
using VentaUniformesApplication.Features;
|
||||
using VentaUniformesApplication.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformesApplication.Persistencia.user.commands.DeleteUser;
|
||||
using VentaUniformesApplication.Persistencia.user.commands.UpdateUser;
|
||||
using VentaUniformesApplication.Persistencia.user.Queries.GetAllUser;
|
||||
using VentaUniformesApplication.Persistencia.user.Queries.GetUserById;
|
||||
using VentaUniformesApplication.Persistencia.user.Queries.GetUserByPassAndName;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
|
||||
//using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
//using System.Web.Http;
|
||||
|
||||
namespace VentaUniformesapi.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/v1/User")]
|
||||
[ApiController]
|
||||
[TypeFilter(typeof(ExceptionManager))]//captura errores de todo el controller
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
/*public UserController()
|
||||
{
|
||||
|
||||
}*/
|
||||
[AllowAnonymous]//no securizada
|
||||
[HttpGet("test")]
|
||||
public async Task<IActionResult> test()
|
||||
{
|
||||
//var n=int.Parse("h");
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, "{}", "Ejecucion exitosa"));
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll(
|
||||
[FromServices] IGetAllUserQuery service
|
||||
)
|
||||
{
|
||||
var data = await service.Execute();
|
||||
if(data==null|| data.Count<=0)
|
||||
return StatusCode(StatusCodes.Status404NotFound, ResponseApiService.Response(StatusCodes.Status404NotFound, data));
|
||||
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, data));
|
||||
|
||||
}
|
||||
[HttpGet("{userId}")]
|
||||
public async Task<IActionResult> Getuser(
|
||||
int userId,
|
||||
[FromServices] IGetUserByIdQuery service
|
||||
)
|
||||
{
|
||||
if (userId <= 0)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest));
|
||||
}
|
||||
var data = await service.Execute(userId);
|
||||
if (data == null)
|
||||
return StatusCode(StatusCodes.Status404NotFound, ResponseApiService.Response(StatusCodes.Status404NotFound, data));
|
||||
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, data));
|
||||
|
||||
}
|
||||
[HttpGet("{userName}/{password}")]
|
||||
public async Task<IActionResult> Getuser(
|
||||
string userName,
|
||||
string password,
|
||||
|
||||
[FromServices] IGetUserByPassAndNameQuery service,
|
||||
[FromServices] IValidator<(string, string)> validador
|
||||
)
|
||||
{
|
||||
var validacion = await validador.ValidateAsync(( userName, password));
|
||||
if (!validacion.IsValid)
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest, validacion.Errors));
|
||||
/*
|
||||
if (userName==null || userName.Length <= 0|| password == null || password.Length <= 0)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest));
|
||||
}*/
|
||||
var data = await service.Execute(password,userName);
|
||||
if (data == null)
|
||||
return StatusCode(StatusCodes.Status404NotFound, ResponseApiService.Response(StatusCodes.Status404NotFound, data));
|
||||
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, data));
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("login")]//se pasa parametros con ?userName=nombre&password=pass
|
||||
public async Task<IActionResult> Getuser2(
|
||||
[FromQuery] string userName,
|
||||
[FromQuery] string password,
|
||||
|
||||
[FromServices] IGetUserByPassAndNameQuery service,
|
||||
[FromServices] IValidator<(string, string)> validador
|
||||
)
|
||||
{
|
||||
var validacion = await validador.ValidateAsync((userName, password));
|
||||
if (!validacion.IsValid)
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest, validacion.Errors));
|
||||
|
||||
var data = await service.Execute(password, userName);
|
||||
if (data == null)
|
||||
return StatusCode(StatusCodes.Status404NotFound, ResponseApiService.Response(StatusCodes.Status404NotFound, data));
|
||||
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, data));
|
||||
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create(
|
||||
[FromBody] CreateUserModel model,
|
||||
[FromServices] IcreateUserCommand createUserCommand,
|
||||
[FromServices] IValidator<CreateUserModel> validador
|
||||
)
|
||||
{
|
||||
var validacion = await validador.ValidateAsync(model);
|
||||
if(!validacion.IsValid)
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest, validacion.Errors));
|
||||
|
||||
var data = await createUserCommand.Execute(model);
|
||||
|
||||
|
||||
//var n=int.Parse("h");
|
||||
return StatusCode(StatusCodes.Status201Created, ResponseApiService.Response(StatusCodes.Status201Created, data));
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> Update(
|
||||
[FromBody] UpdateUserModel model,
|
||||
[FromServices] IupdateUserCommand updateUserCommand,
|
||||
[FromServices] IValidator<UpdateUserModel> validador
|
||||
)
|
||||
{
|
||||
var validacion = await validador.ValidateAsync(model);
|
||||
if (!validacion.IsValid)
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest, validacion.Errors));
|
||||
|
||||
var data = await updateUserCommand.Execute(model);
|
||||
|
||||
|
||||
//var n=int.Parse("h");
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, data));
|
||||
}
|
||||
|
||||
//falta hacerlo en servicio-------------------------
|
||||
[HttpPatch]
|
||||
public async Task<IActionResult> UpdateParcial(
|
||||
[FromBody] UpdateUserModel model,
|
||||
[FromServices] IupdateUserCommand updateUserCommand
|
||||
)
|
||||
{
|
||||
var data = await updateUserCommand.Execute(model);
|
||||
|
||||
|
||||
//var n=int.Parse("h");
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, data));
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("{userId}")]//parametro por url
|
||||
public async Task<IActionResult> borrar(
|
||||
int userId,
|
||||
[FromServices] IDeleteUserCommand servicio
|
||||
)
|
||||
{
|
||||
//validacion---------------------
|
||||
if(userId<=0)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest));
|
||||
}
|
||||
var data = await servicio.Execute(userId);
|
||||
if(!data)
|
||||
return StatusCode(StatusCodes.Status404NotFound, ResponseApiService.Response(StatusCodes.Status404NotFound, data));
|
||||
//var n=int.Parse("h");
|
||||
return StatusCode(StatusCodes.Status200OK, ResponseApiService.Response(StatusCodes.Status200OK, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
using Microsoft.OpenApi.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace VentaUniformesapi
|
||||
{
|
||||
//clase de inyeccion de depèndencias
|
||||
public static class DependencyInjectionService
|
||||
{
|
||||
public static IServiceCollection AddWebApi(this IServiceCollection services)
|
||||
{
|
||||
services.AddSwaggerGen(option =>
|
||||
{
|
||||
option.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Version = "v1",
|
||||
Title = "VentaUniformesapi",
|
||||
Description = "Plantilla generica para apis"
|
||||
});
|
||||
//parametros de seguridad-----------------------------------
|
||||
option.AddSecurityDefinition("Beare", new OpenApiSecurityScheme
|
||||
{
|
||||
In = ParameterLocation.Header,
|
||||
Description="Ingrese un tokenVálido",
|
||||
Name="Authorization",
|
||||
Type=SecuritySchemeType.Http,
|
||||
BearerFormat="JWT",
|
||||
Scheme="Bearer"
|
||||
});
|
||||
option.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference=new OpenApiReference
|
||||
{
|
||||
Type=ReferenceType.SecurityScheme,
|
||||
Id="Bearer"
|
||||
}
|
||||
|
||||
},
|
||||
new string[]{ }
|
||||
}
|
||||
});
|
||||
//-----------------------------------------------------------
|
||||
var fileName = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
option.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, fileName));
|
||||
});
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<DocumentationFile>C:\desa\cursoNet8CA\Empresa.app\src\VentaUniformesapi.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.8.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VentaUniformesApplication\VentaUniformes.Application.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesCommon\VentaUniformesCommon.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesDomain\VentaUniformes.Domain.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesExternal\VentaUniformes.External.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesPersistencia\VentaUniformes.Persistencia.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<DocumentationFile>C:\desa\cursoNet8CA\Empresa.app\src\VentaUniformesapi.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.8.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VentaUniformesApplication\VentaUniformes.Application.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesCommon\VentaUniformesCommon.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesDomain\VentaUniformes.Domain.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesExternal\VentaUniformes.External.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformesPersistencia\VentaUniformes.Persistencia.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<NameOfLastUsedPublishProfile>F:\desa\v2022\PlantillaApiNet8\Empresa.app\src\Empresa.App.api\Properties\PublishProfiles\ParaDocker.pubxml</NameOfLastUsedPublishProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
@VentaUniformesapi_HostAddress = http://localhost:5181
|
||||
|
||||
GET {{VentaUniformesapi_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
using VentaUniformesapi;
|
||||
using VentaUniformesApplication.Interfaces;
|
||||
using VentaUniformesCommon;
|
||||
using VentaUniformesPersistencia;
|
||||
using VentaUniformesExternal;
|
||||
using VentaUniformesApplication.Persistencia.user.commands.CreateUser;
|
||||
using VentaUniformesApplication;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
|
||||
//añadir dependencias por inyeccion---------------------------
|
||||
//añadri cadena de conexion esto te obliga a añadir dependencias a entity
|
||||
//builder.Services.addDbContext
|
||||
|
||||
|
||||
//inyeccion de dependencias te obliga a linckar persistencia y a externo¿?
|
||||
|
||||
//builder.Services.AddScoped<IPersistenciaService, PersistenciaService>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddWebApi()
|
||||
.AddCommon()
|
||||
.AddAplication()
|
||||
.AddExternal(builder.Configuration)
|
||||
.AddPersistencia(builder.Configuration);
|
||||
|
||||
//
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
//poner swagger
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI( options =>
|
||||
{
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
|
||||
options.RoutePrefix = string.Empty;
|
||||
});
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
|
||||
//prueba de servicios-------------------------------------------
|
||||
/*
|
||||
app.MapGet("/test", async (IcreateUserCommand service) =>
|
||||
{
|
||||
var e = new CreateUserModel();
|
||||
e.UserName = "test";
|
||||
e.FristName = "FristName";
|
||||
e.LastName = "LastName";
|
||||
e.Password = "Password";
|
||||
|
||||
return await service.Execute(e);
|
||||
});
|
||||
*/
|
||||
//--------------------------------------------------------------
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
app.Run();
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<DeleteExistingFiles>false</DeleteExistingFiles>
|
||||
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<PublishUrl>bin\Release\net8.0\publish\</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<SiteUrlToLaunchAfterPublish />
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ProjectGuid>c21ae3ac-d81e-4eee-a341-1bf131d2ef9d</ProjectGuid>
|
||||
<SelfContained>false</SelfContained>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<_PublishTargetUrl>F:\desa\v2022\PlantillaApiNet8\Empresa.app\src\Empresa.App.api\bin\Release\net8.0\publish\</_PublishTargetUrl>
|
||||
<History>True|2024-10-13T22:20:08.1409506Z||;False|2024-10-12T00:55:43.7868486+02:00||;False|2024-10-12T00:54:55.4206586+02:00||;False|2024-10-12T00:53:16.4986422+02:00||;False|2024-10-12T00:48:55.1444606+02:00||;False|2024-10-12T00:41:42.3670744+02:00||;True|2024-10-12T00:38:00.0676000+02:00||;False|2024-10-12T00:37:27.3435243+02:00||;False|2024-10-12T00:36:59.2954575+02:00||;False|2024-10-11T23:05:11.9327090+02:00||;False|2024-10-11T22:57:40.4911279+02:00||;False|2024-10-11T22:49:51.2207122+02:00||;False|2024-10-11T22:46:38.3566597+02:00||;False|2024-10-11T22:44:26.6288883+02:00||;False|2024-10-11T22:42:50.5880241+02:00||;False|2024-10-11T22:14:27.4878309+02:00||;True|2024-10-11T21:59:36.3243372+02:00||;</History>
|
||||
<LastFailureDetails />
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5181"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:18396",
|
||||
"sslPort": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"SqlConnectionString": "server=192.168.56.1,1433;user id=sa;password=pass1234.4321@#;initial catalog=AppPrueba; Trust Server Certificate=True",
|
||||
"SecretKeyJwt": "NFAJJSAK3523dgsdf.dasfas.dsnfansnvDSFaskin908348",
|
||||
"IssuerJWT": "EmpresaApp.com",
|
||||
"AudienceJwt": "EmpresaApp.com",
|
||||
"MasterKey": "bdasbvña78678,.p``´dshnihfp"
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using VentaUniformes.Application.Exceptions;
|
||||
using VentaUniformes.Application.VentasView;
|
||||
using VentaUniformes.Application.VentasView.historico.Borrar;
|
||||
|
||||
namespace VentaUniformes.app.Controllers
|
||||
{
|
||||
[TypeFilter(typeof(ExceptionManager))]
|
||||
public class BorrarVentaController : Controller
|
||||
{
|
||||
private readonly IVentasViewService ventasViewService;
|
||||
|
||||
public BorrarVentaController(IVentasViewService ventasViewService)
|
||||
{
|
||||
this.ventasViewService = ventasViewService;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Principal(VentaHistoricoBorrarViewModel model)
|
||||
{
|
||||
return View(model);
|
||||
}
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Borrar(VentaHistoricoBorrarViewModel model)
|
||||
{
|
||||
if (!await ventasViewService.BorraVenta(model.Id))
|
||||
{
|
||||
ViewData["Mensaje"] = "Error al Cargar resultados";
|
||||
return RedirectToAction("Principal", model);
|
||||
}
|
||||
model.Alumno = model.AlumnoFiltro;
|
||||
return RedirectToAction("Principal", "Historico", model);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using VentaUniformes.Application.Exceptions;
|
||||
using VentaUniformes.Application.VentasView.historico;
|
||||
using VentaUniformes.Application.VentasView.historico.Borrar;
|
||||
|
||||
namespace VentaUniformes.app.Controllers
|
||||
{
|
||||
[TypeFilter(typeof(ExceptionManager))]
|
||||
public class HistoricoController : Controller
|
||||
{
|
||||
private readonly IVentasHistoricoViewService ventashistoricoService;
|
||||
public HistoricoController(
|
||||
IVentasHistoricoViewService _ventashistoricoService
|
||||
)
|
||||
{
|
||||
ventashistoricoService = _ventashistoricoService;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Principal(VentasHistoricoViewModel model)
|
||||
{
|
||||
VentasHistoricoViewModel res;
|
||||
if (model == null || model.Top<= 0)
|
||||
{
|
||||
res = await ventashistoricoService.GetVentas();
|
||||
}
|
||||
else
|
||||
{
|
||||
res = await ventashistoricoService.GetVentas(model);
|
||||
}
|
||||
return View(res);
|
||||
}
|
||||
/*
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Principal(VentasHistoricoViewModel model)
|
||||
{
|
||||
//verificar
|
||||
//guardar
|
||||
//ViewData["Mensaje"] = "";
|
||||
var res = await ventashistoricoService.GetVentas(model);
|
||||
if(res==null)
|
||||
{
|
||||
ViewData["Mensaje"] = "Error al Cargar resultados";
|
||||
return View(model);
|
||||
}
|
||||
|
||||
return View(res);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Runtime.Intrinsics.Arm;
|
||||
using System.Text;
|
||||
using VentaUniformes.Application.Exceptions;
|
||||
using VentaUniformes.Application.Features;
|
||||
using VentaUniformes.Application.Interfaces.External;
|
||||
using VentaUniformes.Application.Sesion.Commands.CreateSesion;
|
||||
using VentaUniformes.Application.VentasView;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Model;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace VentaUniformes.app.Controllers
|
||||
{
|
||||
[TypeFilter(typeof(ExceptionManager))]//captura errores de todo el controller
|
||||
public class SesionController : Controller
|
||||
{
|
||||
private readonly ICreateSesionCommand createSesionCommand;
|
||||
private readonly IValidator<InCreateSesionModel> validador;
|
||||
private readonly IConfiguration config;
|
||||
private readonly IValidateTokenService _tokenValidator;
|
||||
|
||||
private readonly IVentasViewService ventasViewService;
|
||||
|
||||
public SesionController(ICreateSesionCommand _createSesionCommand,
|
||||
IValidator<InCreateSesionModel> _validador,
|
||||
IConfiguration _config,
|
||||
IValidateTokenService tokenValidator,
|
||||
IVentasViewService _ventasViewService
|
||||
)
|
||||
{
|
||||
ventasViewService = _ventasViewService;
|
||||
createSesionCommand = _createSesionCommand;
|
||||
validador = _validador;
|
||||
this.config = _config;
|
||||
_tokenValidator= tokenValidator;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
public IActionResult Login()
|
||||
{
|
||||
var token = Request.Cookies["JwtToken"];
|
||||
if (token!=null && !_tokenValidator.ValidateToken(token))
|
||||
{
|
||||
return RedirectToAction("Logout", "Sesion");
|
||||
}
|
||||
else if(token != null)
|
||||
{
|
||||
return RedirectToAction("Principal", "Venta");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Login( InCreateSesionModel model)
|
||||
{
|
||||
// ViewData["Mensaje"] = null;
|
||||
//ViewData["JwtToken"] = "";
|
||||
var validacion = await validador.ValidateAsync(model);
|
||||
if (!validacion.IsValid)
|
||||
{
|
||||
ModelState.AddModelError("", validacion.ToString());
|
||||
return View(model);
|
||||
|
||||
}
|
||||
var data = await createSesionCommand.Execute(model);
|
||||
if(data==null || data.UserId<0)
|
||||
{
|
||||
ViewData["Mensaje"] = "Usuario o contraseña incorrectos.";
|
||||
return View(model);
|
||||
}
|
||||
// Guardar el token en una cookie
|
||||
var cookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true, // Evita el acceso por JavaScript
|
||||
Secure = true, // Solo se enviará a través de HTTPS
|
||||
Expires = DateTimeOffset.UtcNow.AddMinutes(int.Parse(config["TimeLogin"])) // Tiempo de expiración
|
||||
};
|
||||
|
||||
Response.Cookies.Append("JwtToken", data.Token, cookieOptions);
|
||||
Response.Cookies.Append("UserName", model.UserName, cookieOptions);
|
||||
Response.Cookies.Append("UserRole", data.Role.ToString(), cookieOptions);
|
||||
|
||||
// ViewData["URLbase"] = config["URLbase"];
|
||||
//ViewData["JwtToken"] = data.Token; // Pasar el token a la vista
|
||||
//return View(model);
|
||||
return RedirectToAction("Principal", "Venta");
|
||||
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
public IActionResult Logout()
|
||||
{
|
||||
Response.Cookies.Delete("JwtToken");
|
||||
Response.Cookies.Delete("UserName");
|
||||
Response.Cookies.Delete("UserRole");
|
||||
return RedirectToAction("", "Sesion");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using VentaUniformes.Application.Exceptions;
|
||||
using VentaUniformes.Application.Persistencia.Producto.Queries.GetAllProduct;
|
||||
using VentaUniformes.Application.Sesion.Commands.CreateSesion;
|
||||
using VentaUniformes.Application.VentasView;
|
||||
using VentaUniformes.Domain.Models;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace VentaUniformes.app.Controllers
|
||||
{
|
||||
[TypeFilter(typeof(ExceptionManager))]//captura errores de todo el controller
|
||||
public class VentaController : Controller
|
||||
{
|
||||
private readonly ILogger<VentaController> _logger;
|
||||
private readonly IVentasViewService ventasViewService;
|
||||
public VentaController(ILogger<VentaController> logger,
|
||||
IVentasViewService _ventasViewService
|
||||
)
|
||||
{
|
||||
ventasViewService = _ventasViewService;
|
||||
_logger = logger;
|
||||
}
|
||||
//[Authorize(Policy = "AdminOnly")]
|
||||
// [AllowAnonymous]
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Principal()
|
||||
{
|
||||
var model =await ventasViewService.GetNewVenta();
|
||||
//ViewData["Mensaje"] = "";
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Principal( VentasViewModel model)
|
||||
{
|
||||
//verificar
|
||||
//guardar
|
||||
//ViewData["Mensaje"] = "";
|
||||
if (!await ventasViewService.Save(model))
|
||||
{
|
||||
ViewData["Mensaje"] = "Error al guardar la venta.";
|
||||
return View(model);
|
||||
}
|
||||
|
||||
return RedirectToAction("Principal", "Venta");
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
using VentaUniformes.Application;
|
||||
using VentaUniformes.Common;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
/* .AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = null; // Si deseas mantener los nombres de las propiedades
|
||||
});*/
|
||||
//builder.Services.AddControllers();
|
||||
builder.Services.AddAplication();
|
||||
builder.Services.AddCommon(builder.Configuration);
|
||||
//.AddExternal(builder.Configuration)
|
||||
//.AddPersistencia(builder.Configuration);
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Sesion}/{action=Login}/{id?}");
|
||||
|
||||
//app.MapRazorPages();
|
||||
app.Run();
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:42023",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5039",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VentaUniformes.Application\VentaUniformes.Application.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformes.Common\VentaUniformes.Common.csproj" />
|
||||
<ProjectReference Include="..\VentaUniformes.Domain\VentaUniformes.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="Views\Historico\Principal.cshtml">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
||||
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
|
||||
<View_SelectedScaffolderID>RazorViewScaffolder</View_SelectedScaffolderID>
|
||||
<View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
|
||||
<WebStackScaffolding_ViewDialogWidth>650</WebStackScaffolding_ViewDialogWidth>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
@model VentaUniformes.Application.VentasView.historico.Borrar.VentaHistoricoBorrarViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Borrar venta";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
<h3>Datos Venta</h3>
|
||||
|
||||
<div class="row">
|
||||
<!-- Columna izquierda: tabla de productos enctype="multipart/form-data-->
|
||||
<div class="col-md-8" form-group>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="Alumno"></label>
|
||||
<input asp-for="Alumno" class="form-control" readonly />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Curso"></label>
|
||||
<input asp-for="Curso" class="form-control" readonly />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Total"></label>
|
||||
<input asp-for="Total" class="form-control" readonly />
|
||||
</div>
|
||||
</div>
|
||||
<!-- Columna derecha: resumen de total y método de pago -->
|
||||
|
||||
<div class="col-md-4 form-group">
|
||||
<div class="card form-group">
|
||||
<div class="card-body form-group">
|
||||
|
||||
<h5 class="card-title">¿Desea borrar esta venta?</h5>
|
||||
<form asp-area="" asp-controller="Historico" asp-action="Principal" method="get" style="display: inline;">
|
||||
<input type="hidden" name="Alumno" value="@Model.AlumnoFiltro" />
|
||||
<input type="hidden" name="Top" value="@Model.Top" />
|
||||
<button type="submit" class="btn btn-primary mt-3">Volver</button>
|
||||
</form>
|
||||
|
||||
<form asp-action="Borrar" method="post" style="display: inline;">
|
||||
<input type="hidden" name="Id" value="@Model.Id" />
|
||||
<input type="hidden" name="AlumnoFiltro" value="@Model.AlumnoFiltro" />
|
||||
<input type="hidden" name="Top" value="@Model.Top" />
|
||||
<button type="submit" class="btn btn-primary mt-3">Borrar</button>
|
||||
</form>
|
||||
@if (ViewData["Mensaje"] != null)
|
||||
{
|
||||
<div class="alert alert-danger">
|
||||
@ViewData["Mensaje"]
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@section Scripts {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
@model VentaUniformes.Application.VentasView.historico.VentasHistoricoViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Historico de ventas";
|
||||
}
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
|
||||
<div class="row">
|
||||
<!-- Columna izquierda: tabla de productos enctype="multipart/form-data-->
|
||||
<div class="col-md-8" form-group>
|
||||
<!-- Input (oculto inicialmente) -->
|
||||
<div id="campoInput" style="display:none; margin-top:10px;">
|
||||
<label for="inputOpcional">Texto adicional:</label>
|
||||
<input type="text" id="inputOpcional" name="inputOpcional" placeholder="Escribe algo..." />
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Alumno</th>
|
||||
<th>Curso</th>
|
||||
<th>Total</th>
|
||||
<th>Fecha</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (int i = 0; i < Model.ventas.Count; i++)
|
||||
{
|
||||
<tr>
|
||||
<td>@Model.ventas[i].Alumno</td>
|
||||
<td>@Model.ventas[i].Curso</td>
|
||||
<td>@Model.ventas[i].Total.ToString("C")</td>
|
||||
<td>@Model.ventas[i].fecha.ToString()</td>
|
||||
<td>
|
||||
<form asp-area="" asp-controller="EditarVenta" asp-action="Principal" method="post" style="display: inline;">
|
||||
<input type="hidden" name="Id" value="@Model.ventas[i].Id" />
|
||||
<input type="hidden" name="AlumnoFiltro" value="@Model.Alumno" />
|
||||
<input type="hidden" name="Top" value="@Model.Top" />
|
||||
<button type="submit"><i class="fas fa-pencil-alt"></i></button>
|
||||
</form>
|
||||
<form asp-area="" asp-controller="BorrarVenta" asp-action="Principal" method="get" style="display: inline;">
|
||||
<input type="hidden" name="Id" value="@Model.ventas[i].Id" />
|
||||
<input type="hidden" name="AlumnoFiltro" value="@Model.Alumno" />
|
||||
<input type="hidden" name="Top" value="@Model.Top" />
|
||||
<input type="hidden" name="Alumno" value="@Model.ventas[i].Alumno" />
|
||||
<input type="hidden" name="Curso" value="@Model.ventas[i].Curso" />
|
||||
<input type="hidden" name="Total" value="@Model.ventas[i].Total" />
|
||||
<button type="submit" ><i class="fas fa-trash-alt"></i></button>
|
||||
</form>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Columna derecha: resumen de total y método de pago -->
|
||||
|
||||
<div class="col-md-4 form-group">
|
||||
<div class="card form-group">
|
||||
<div class="card-body form-group">
|
||||
|
||||
<h5 class="card-title">Parametros de busqueda</h5>
|
||||
<form asp-action="Principal" method="get">
|
||||
<div class="form-group">
|
||||
<label asp-for="Alumno">Alumno</label>
|
||||
<input asp-for="Alumno" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Top">Mostrar ultimos</label>
|
||||
<input asp-for="Top" class="form-control" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mt-3">Buscar</button>
|
||||
</form>
|
||||
@if (ViewData["Mensaje"] != null)
|
||||
{
|
||||
<div class="alert alert-danger">
|
||||
@ViewData["Mensaje"]
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue