empezé a hacer cosas con el dbcontext, termine la clase de repositorio y añadi/implemente los skeleton de varios repositorios
This commit is contained in:
@@ -7,11 +7,85 @@ public class Context : Microsoft.EntityFrameworkCore.DbContext
|
||||
{
|
||||
public DbSet<Categoria> Categorias { get; set; }
|
||||
public DbSet<Cliente> Clientes { get; set; }
|
||||
|
||||
public DbSet<Factura> Facturas { get; set; }
|
||||
public DbSet<Lote> Lotes { get; set; }
|
||||
public DbSet<DetalleFactura> DetalleFacturas { get; set; }
|
||||
public DbSet<DetallePresupuesto> DetallePresupuestos { get; set; }
|
||||
public DbSet<DetalleOrdenDeCompra> DetalleOrdenDeCompras { get; set; }
|
||||
public DbSet<OrdenDeCompra> OrdenDeCompras { get; set; }
|
||||
public DbSet<Presupuesto> Presupuestos { get; set; }
|
||||
public DbSet<ProductoPercedero> ProductoPercederos { get; set; }
|
||||
public DbSet<ProductoNoPercedero> ProductoNoPercederos { get; set; }
|
||||
public DbSet<Proveedor> Proveedores { get; set; }
|
||||
public DbSet<Remito> Remitos { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{ // Esto de poner credenciales sueltas está mal
|
||||
optionsBuilder.UseSqlServer(@"Server=fedesrv.ddns.net,1433;Database=ControlStockDAS;User Id=ProyectoDas;Password=<IL-:aQI?TK{uRw:AU>A?5?~*=Gux'}JT0me,z5Cf^f(s'-gy[G#-jt%b&uHe+/,$Gl>qkXl-c[@&e(\.V?[3)\w|aMH+<GnkIo*99MNJ}:L=j<T,^$`8J\dXw6>^67x;Trusted_Connection=False;Encrypt=False;Connection Timeout=5;");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
/// Categoria
|
||||
modelBuilder.Entity<Categoria>()
|
||||
.ToTable("Categoria")
|
||||
.HasKey(x => x.Id);
|
||||
modelBuilder.Entity<Categoria>()
|
||||
.Property(c=>c.Descripcion)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
/// Cliente
|
||||
modelBuilder.Entity<Cliente>()
|
||||
.ToTable("Clientes") // Nombre de la tabla
|
||||
.HasKey(c => c.Cuit); // Configura la clave primaria
|
||||
|
||||
modelBuilder.Entity<Cliente>()
|
||||
.Property(c => c.Nombre)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
modelBuilder.Entity<Cliente>()
|
||||
.Property(c => c.Apellido)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
modelBuilder.Entity<Cliente>()
|
||||
.Property(c => c.Direccion)
|
||||
.HasMaxLength(200);
|
||||
|
||||
modelBuilder.Entity<Cliente>()
|
||||
.Property(c => c.Correo)
|
||||
.HasMaxLength(150);
|
||||
|
||||
modelBuilder.Entity<Cliente>()
|
||||
.Property(c => c.Habilitado)
|
||||
.HasDefaultValue(true);
|
||||
|
||||
/// Factura Y DetalleFactura WIP
|
||||
modelBuilder.Entity<Factura>()
|
||||
.ToTable("Facturas")
|
||||
.HasKey(f => f.Id);
|
||||
|
||||
modelBuilder.Entity<Factura>()
|
||||
.HasMany(f => f.Detalles)
|
||||
.WithOne()
|
||||
.HasForeignKey(df => df.FacturaId);
|
||||
|
||||
modelBuilder.Entity<DetalleFactura>()
|
||||
.ToTable("DetallesFacturas")
|
||||
.HasKey(df => df.Id);
|
||||
|
||||
modelBuilder.Entity<DetalleFactura>()
|
||||
.Property(df => df.IdFactura)
|
||||
.IsRequired();
|
||||
|
||||
modelBuilder.Entity<DetalleFactura>()
|
||||
.HasOne(df => df.Producto)
|
||||
.WithMany()
|
||||
.HasForeignKey(df => df.Producto.Id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public abstract class IRepositorio<T>
|
||||
{
|
||||
public IEnumerable<T> Listar();
|
||||
public abstract T ObtenerPorId(int Tid);
|
||||
public abstract void Add(T t);
|
||||
public abstract void Del(T t);
|
||||
public abstract void Mod(T t);
|
||||
public abstract bool Guardar();
|
||||
}
|
||||
}
|
||||
30
Modelo/Repositorio.cs
Normal file
30
Modelo/Repositorio.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public abstract class Repositorio<T>
|
||||
{
|
||||
protected Context context;
|
||||
public abstract IEnumerable<T> Listar();
|
||||
public abstract T ObtenerPorId(int Tid);
|
||||
public abstract void Add(T t);
|
||||
public abstract void Del(T t);
|
||||
public abstract void Mod(T t);
|
||||
|
||||
public bool Guardar()
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
context.SaveChanges();
|
||||
ret = true;
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,27 @@
|
||||
using System.Transactions;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Transactions;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioCategoria : IRepositorio<Categoria>
|
||||
public sealed class RepositorioCategoria : Repositorio<Categoria>
|
||||
{
|
||||
private Context context;
|
||||
|
||||
public RepositorioCategoria(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Categoria> Listar()
|
||||
{
|
||||
return context.Categorias.ToList();
|
||||
}
|
||||
|
||||
public override Categoria ObtenerPorId(int Tid)
|
||||
{
|
||||
return context.Categorias.Find(Tid);
|
||||
Categoria cat = context.Categorias.Find(Tid);
|
||||
return cat ?? new Categoria();
|
||||
}
|
||||
|
||||
public override void Add(Categoria t)
|
||||
@@ -24,25 +31,16 @@ namespace Modelo
|
||||
|
||||
public override void Del(Categoria t)
|
||||
{
|
||||
Categoria? cat = context.Categorias.Find(t.Id);
|
||||
Categoria cat = context.Categorias.Find(t.Id);
|
||||
if (cat == null) return;
|
||||
context.Categorias.Remove(cat);
|
||||
}
|
||||
|
||||
public override void Mod(Categoria t)
|
||||
{
|
||||
context.Entry(t).State = EntityState.Modified;
|
||||
context.Categorias.Update(t);
|
||||
}
|
||||
|
||||
public override void Guardar()
|
||||
{
|
||||
try
|
||||
{
|
||||
context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,42 @@
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioClientes : IRepositorio<Cliente>
|
||||
public sealed class RepositorioClientes : Repositorio<Cliente>
|
||||
{
|
||||
|
||||
public RepositorioClientes(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Cliente> Listar()
|
||||
{
|
||||
return context.Clientes.ToList();
|
||||
}
|
||||
|
||||
public override Cliente ObtenerPorId(int Tid)
|
||||
{
|
||||
Cliente cli = context.Clientes.Find(Tid);
|
||||
return cli ?? new Cliente();
|
||||
}
|
||||
|
||||
public override void Add(Cliente t)
|
||||
{
|
||||
context.Clientes.Add(t);
|
||||
}
|
||||
|
||||
public override void Del(Cliente t)
|
||||
{
|
||||
Cliente cli = context.Clientes.Find(t.Cuit);
|
||||
if (cli == null) return;
|
||||
context.Clientes.Remove(cli);
|
||||
}
|
||||
|
||||
public override void Mod(Cliente t)
|
||||
{
|
||||
context.Categorias.Update(t);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,40 @@ using Entidades;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioFactura : IRepositorio<Factura>
|
||||
public sealed class RepositorioFactura : Repositorio<Factura>
|
||||
{
|
||||
|
||||
|
||||
public RepositorioFactura(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Factura> Listar()
|
||||
{
|
||||
return context.Facturas.ToList();
|
||||
}
|
||||
|
||||
public override Factura ObtenerPorId(int Tid)
|
||||
{
|
||||
Factura fac = context.Facturas.Find(Tid);
|
||||
return fac ?? new Factura();
|
||||
}
|
||||
|
||||
public override void Add(Factura t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(Factura t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(Factura t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,40 @@
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioLote : IRepositorio<Lote>
|
||||
public sealed class RepositorioLote : Repositorio<Lote>
|
||||
{
|
||||
private Context context;
|
||||
|
||||
public RepositorioLote(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Lote> Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Lote ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Add(Lote t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(Lote t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(Lote t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,40 @@ using Entidades;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioOrdenDeCompra : IRepositorio<OrdenDeCompra>
|
||||
public sealed class RepositorioOrdenDeCompra : Repositorio<OrdenDeCompra>
|
||||
{
|
||||
private Context context;
|
||||
|
||||
public RepositorioOrdenDeCompra(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<OrdenDeCompra> Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override OrdenDeCompra ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Add(OrdenDeCompra t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(OrdenDeCompra t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(OrdenDeCompra t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,43 @@ using Entidades;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioPresupuesto : IRepositorio<Presupuesto>
|
||||
public sealed class RepositorioPresupuesto : Repositorio<Presupuesto>
|
||||
{
|
||||
private Context context;
|
||||
|
||||
public RepositorioPresupuesto(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Presupuesto> Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Presupuesto ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Add(Presupuesto t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(Presupuesto t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(Presupuesto t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Guardar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,88 @@
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioProductos : IRepositorio<Producto>
|
||||
public sealed class RepositorioProductos : Repositorio<ProductoPercedero>, Repositorio<ProductoNoPercedero>
|
||||
{
|
||||
private Context context;
|
||||
|
||||
public RepositorioProductos(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Producto> Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ProductoNoPercedero Repositorio<ProductoNoPercedero>.ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Add(ProductoNoPercedero t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(ProductoNoPercedero t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(ProductoNoPercedero t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerable<ProductoNoPercedero> Repositorio<ProductoNoPercedero>.Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ProductoPercedero Repositorio<ProductoPercedero>.ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Add(ProductoPercedero t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(ProductoPercedero t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(ProductoPercedero t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerable<ProductoPercedero> Repositorio<ProductoPercedero>.Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Producto ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Add(Producto t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Del(Producto t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Mod(Producto t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,39 @@
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioProveedor : IRepositorio<Proveedor>
|
||||
public sealed class RepositorioProveedor : Repositorio<Proveedor>
|
||||
{
|
||||
|
||||
|
||||
public RepositorioProveedor(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Proveedor> Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Proveedor ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Add(Proveedor t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(Proveedor t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(Proveedor t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,37 @@ using Entidades;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioRemito : IRepositorio<Remito>
|
||||
public sealed class RepositorioRemito : Repositorio<Remito>
|
||||
{
|
||||
|
||||
|
||||
|
||||
public RepositorioRemito(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override IEnumerable<Remito> Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Remito ObtenerPorId(int Tid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Add(Remito t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Del(Remito t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Mod(Remito t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user