feat: terminado primer test del form crear inquilino
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Text;
|
|||||||
using Entidades;
|
using Entidades;
|
||||||
using Entidades.Dto;
|
using Entidades.Dto;
|
||||||
using Modelo;
|
using Modelo;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace AlquilaFacil.Controllers;
|
namespace AlquilaFacil.Controllers;
|
||||||
|
|
||||||
@@ -16,29 +17,28 @@ public class InquilinoController: ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/inquilino")]
|
[HttpPost("api/inquilino")]
|
||||||
public IActionResult Post([FromForm] CrearClienteDto cid) {
|
public IActionResult Post([FromBody] CrearClienteDto cid) {
|
||||||
|
|
||||||
var ret = verificarCrearUsuario(cid);
|
var ret = verificarCrearUsuario(cid);
|
||||||
if (ret is BadRequestResult) return ret;
|
if (ret != "") return BadRequest(ret);
|
||||||
|
|
||||||
bool ret2 = RepositorioUsuarios.Singleton.AltaCliente(cid);
|
bool ret2 = RepositorioUsuarios.Singleton.AltaCliente(cid);
|
||||||
return (ret2) ? Ok() : BadRequest();
|
return (ret2) ? Ok() : BadRequest(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IActionResult verificarCrearUsuario(CrearClienteDto cid) {
|
private string verificarCrearUsuario(CrearClienteDto cid) {
|
||||||
string msg = "";
|
string msg = "";
|
||||||
|
|
||||||
if (cid.Usuario.email == string.Empty) msg += "Falta ingresar el email\n";
|
if (cid.email == string.Empty) msg += "Falta ingresar el email\n";
|
||||||
if (cid.Usuario.contraseña.Length < 8) msg += "Por lo menos 8 caracteres en la contraseña\n";
|
if (cid.contraseña.Length < 8) msg += "Por lo menos 8 caracteres en la contraseña\n";
|
||||||
|
|
||||||
if (cid.Cliente.apellido == string.Empty) msg += "Falta Ingresar apellido\n";
|
if (cid.apellido == string.Empty) msg += "Falta Ingresar apellido\n";
|
||||||
if (cid.Cliente.nombre == string.Empty) msg += "Falta Ingresar nombre\n";
|
if (cid.nombre == string.Empty) msg += "Falta Ingresar nombre\n";
|
||||||
if (cid.Cliente.dni <= 0) msg += "Falta Ingresar dni o elejiste un numero negativo\n";
|
if (cid.dni <= 0) msg += "Falta Ingresar dni o elejiste un numero negativo\n";
|
||||||
if (cid.Cliente.celular == string.Empty) msg += "Falta Ingresar Numero de Contacto\n";
|
if (cid.celular == string.Empty) msg += "Falta Ingresar Numero de Contacto\n";
|
||||||
if (cid.Cliente.domicilio == string.Empty) msg += "Falta Ingresar Domicilio Legal";
|
if (cid.domicilio == string.Empty) msg += "Falta Ingresar Domicilio Legal";
|
||||||
|
|
||||||
if (msg == "") return Ok();
|
return msg;
|
||||||
return BadRequest(new {message = msg});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ public partial class AlquilaFacilContext : DbContext
|
|||||||
public virtual DbSet<Venta> Ventas { get; set; }
|
public virtual DbSet<Venta> Ventas { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
|
|
||||||
=> optionsBuilder.UseMySQL("Server=fedesrv.ddns.net;Port=30006;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none");
|
=> optionsBuilder.UseMySQL("Server=fedesrv.ddns.net;Port=30006;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none");
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
@@ -303,7 +302,7 @@ public partial class AlquilaFacilContext : DbContext
|
|||||||
entity.Property(e => e.id).HasColumnType("int(11)");
|
entity.Property(e => e.id).HasColumnType("int(11)");
|
||||||
entity.Property(e => e.contraseña).HasMaxLength(128);
|
entity.Property(e => e.contraseña).HasMaxLength(128);
|
||||||
entity.Property(e => e.email).HasMaxLength(50);
|
entity.Property(e => e.email).HasMaxLength(50);
|
||||||
entity.Property(e => e.token).HasColumnType("json");
|
entity.Property(e => e.token).HasColumnType("text");
|
||||||
|
|
||||||
entity.HasMany(d => d.idgrupos).WithMany(p => p.idusuarios)
|
entity.HasMany(d => d.idgrupos).WithMany(p => p.idusuarios)
|
||||||
.UsingEntity<Dictionary<string, object>>(
|
.UsingEntity<Dictionary<string, object>>(
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
namespace Entidades.Dto;
|
namespace Entidades.Dto;
|
||||||
|
|
||||||
public class CrearClienteDto {
|
public class CrearClienteDto {
|
||||||
public Cliente Cliente { get; set; } = new();
|
public long dni { get; set; }
|
||||||
public Usuario Usuario { get; set; } = new();
|
public string nombre { get; set; } = null!;
|
||||||
|
public string apellido { get; set; } = null!;
|
||||||
|
public string domicilio { get; set; } = null!;
|
||||||
|
public string celular { get; set; } = null!;
|
||||||
|
public string email { get; set; } = null!;
|
||||||
|
public string contraseña { get; set; } = null!;
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ public partial class Usuario
|
|||||||
|
|
||||||
public byte[] contraseña { get; set; } = null!;
|
public byte[] contraseña { get; set; } = null!;
|
||||||
|
|
||||||
public string token { get; set; } = null!;
|
public string? token { get; set; }
|
||||||
|
|
||||||
public virtual ICollection<Cliente> Clientes { get; set; } = new List<Cliente>();
|
public virtual ICollection<Cliente> Clientes { get; set; } = new List<Cliente>();
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
<Route path="/" component={Login} />
|
<Route path="/" component={Login} />
|
||||||
<Route path="/Info" component={InfoPage} />
|
<Route path="/Info" component={InfoPage} />
|
||||||
|
|
||||||
|
<Route path="/inqtest" component={InqPage} />
|
||||||
|
|
||||||
|
|
||||||
<Route path="/Menu">
|
<Route path="/Menu">
|
||||||
<ProteRoute component={MenuPage} />
|
<ProteRoute component={MenuPage} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Col } from "@sveltestrap/sveltestrap";
|
||||||
|
import FormPostInq from "../lib/FormPostCli.svelte";
|
||||||
|
import NavBarAutocompletable from "../lib/NavBarAutocompletable.svelte";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<NavBarAutocompletable/>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row align-items-start">
|
||||||
|
<div class="col">
|
||||||
|
<FormPostInq url="http://127.0.0.1:5007/api/inquilino"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
70
Front/src/lib/FormPostCli.svelte
Normal file
70
Front/src/lib/FormPostCli.svelte
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Form, FormGroup, Input, Button} from "@sveltestrap/sveltestrap";
|
||||||
|
|
||||||
|
export let url: string
|
||||||
|
|
||||||
|
let showAlert: boolean = false;
|
||||||
|
let errorMessage: string
|
||||||
|
|
||||||
|
let dni: number
|
||||||
|
let email: string
|
||||||
|
let contraseña: string
|
||||||
|
let nombre: string
|
||||||
|
let apellido: string
|
||||||
|
let domicilio: string
|
||||||
|
let celular: string
|
||||||
|
|
||||||
|
async function submitForm(event: any) {
|
||||||
|
event.preventDefault();
|
||||||
|
try {
|
||||||
|
let response = await fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type' : 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({dni, nombre, apellido, domicilio, celular, email, contraseña})
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
errorMessage = errorData.message;
|
||||||
|
showAlert = true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error("Fallo al enviar el formulario para crear un inquilino");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Form on:submit={submitForm}>
|
||||||
|
<FormGroup floating label="Dni">
|
||||||
|
<Input type="number" min='1' bind:value={dni} required />
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup floating label="Email">
|
||||||
|
<Input type="email" placeholder="ejemplo@mail.com" bind:value={email} required />
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup floating label="Contraseña">
|
||||||
|
<Input type="password" placeholder="*********" bind:value={contraseña} required />
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup floating label="Nombre">
|
||||||
|
<Input type="text" bind:value={nombre} required />
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup floating label="Apellido">
|
||||||
|
<Input type="text" bind:value={apellido} required />
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup floating label="Domicilio">
|
||||||
|
<Input type="text" bind:value={domicilio} required />
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup floating label="Celular">
|
||||||
|
<Input type="tel" bind:value={celular} required />
|
||||||
|
</FormGroup>
|
||||||
|
<br>
|
||||||
|
<FormGroup>
|
||||||
|
<Button color="primary" type="submit">Ingresar</Button>
|
||||||
|
</FormGroup>
|
||||||
|
</Form>
|
||||||
|
{#if showAlert}
|
||||||
|
<div class='alert alert-warning alert-dismissible fade show' role='alert'>
|
||||||
|
<strong>{errorMessage}</strong>
|
||||||
|
<button type="button" class="btn-close close" aria-label="Close" data-bs-dismiss="alert"></button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
let errorMessage = ""
|
let errorMessage = ""
|
||||||
let showAlert = false;
|
let showAlert = false;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
async function submitForm(event) {
|
async function submitForm(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@@ -40,17 +41,17 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card class="position-sticky top-50 start-50 translate-middle-x" style="width: 18rem; height: auto;" theme="auto" color="dark" outline>
|
<Card class="position-sticky top-50 start-50 translate-middle-x" style="width: 20rem; height: auto;" theme="auto" color="dark" outline>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Iniciar Sesión</CardTitle>
|
<CardTitle>Iniciar Sesión</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<Form on:submit={submitForm}>
|
<Form on:submit={submitForm}>
|
||||||
<FormGroup floating label="Email">
|
<FormGroup floating label="Email">
|
||||||
<Input type="email" placeholder="ejemplo@mail.com" bind:value={email}/>
|
<Input type="email" placeholder="ejemplo@mail.com" bind:value={email} required/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup floating label="Contraseña">
|
<FormGroup floating label="Contraseña">
|
||||||
<Input type="password" placeholder="*********" bind:value={contraseña}/>
|
<Input type="password" placeholder="*********" bind:value={contraseña} required/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<Button color="primary" type="submit">Ingresar</Button>
|
<Button color="primary" type="submit">Ingresar</Button>
|
||||||
@@ -59,7 +60,7 @@
|
|||||||
{#if errorMessage}
|
{#if errorMessage}
|
||||||
<div class='alert alert-warning alert-dismissible fade show' role='alert'>
|
<div class='alert alert-warning alert-dismissible fade show' role='alert'>
|
||||||
<strong>{errorMessage}</strong>
|
<strong>{errorMessage}</strong>
|
||||||
<button type="button" class="btn-close close" aria-label="Close" data-dismiss="alert"></button>
|
<button type="button" class="btn-close close" aria-label="Close" data-bs-dismiss="alert"></button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</CardBody>
|
</CardBody>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public abstract class RepositorioBase<S>
|
|||||||
ret = true;
|
ret = true;
|
||||||
} catch (DbUpdateException ex)
|
} catch (DbUpdateException ex)
|
||||||
{
|
{
|
||||||
|
Context = new AlquilaFacilContext();
|
||||||
Console.Error.WriteLine(ex.Message);
|
Console.Error.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -9,8 +9,18 @@ namespace Modelo;
|
|||||||
public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||||
{
|
{
|
||||||
public bool AltaCliente(CrearClienteDto cid){
|
public bool AltaCliente(CrearClienteDto cid){
|
||||||
var usu = cid.Usuario;
|
var usu = new Usuario {
|
||||||
var cli = cid.Cliente;
|
email = cid.email,
|
||||||
|
contraseña = Encoding.UTF8.GetBytes(HacerHash(cid.contraseña))
|
||||||
|
};
|
||||||
|
|
||||||
|
var cli = new Cliente {
|
||||||
|
dni = cid.dni,
|
||||||
|
nombre = cid.nombre,
|
||||||
|
domicilio = cid.domicilio,
|
||||||
|
apellido = cid.apellido,
|
||||||
|
celular = cid.celular
|
||||||
|
};
|
||||||
|
|
||||||
var cant = Context.Usuarios
|
var cant = Context.Usuarios
|
||||||
.GroupBy(u => u.id)
|
.GroupBy(u => u.id)
|
||||||
@@ -18,10 +28,19 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
|||||||
.ToList();
|
.ToList();
|
||||||
if (cant.Count < 1) return false;
|
if (cant.Count < 1) return false;
|
||||||
|
|
||||||
usu.id = cant[0];
|
usu.id = cant.Count() + 1;
|
||||||
cli.idusuario = cant[0];
|
cli.idusuario = cant.Count() + 1;
|
||||||
|
|
||||||
|
var grupo = Context.Grupos.Find(2);
|
||||||
|
if (grupo == null || grupo.id == 0) return false;
|
||||||
|
|
||||||
Context.Usuarios.Add(usu);
|
Context.Usuarios.Add(usu);
|
||||||
|
Guardar();
|
||||||
|
|
||||||
|
var usut = Context.Usuarios.Find(usu.id);
|
||||||
|
usut.idgrupos.Add(grupo);
|
||||||
|
Guardar();
|
||||||
|
|
||||||
Context.Clientes.Add(cli);
|
Context.Clientes.Add(cli);
|
||||||
return Guardar();
|
return Guardar();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user