This commit is contained in:
fedpo
2024-09-08 02:39:13 +01:00
parent c15ae743ab
commit 393caac989
65 changed files with 1138 additions and 282 deletions

View File

@@ -167,7 +167,7 @@ public class Context : Microsoft.EntityFrameworkCore.DbContext
.HasKey(x => x.Id);
modelBuilder.Entity<OrdenDeCompra>()
.HasMany(x => x.Detalles)
.HasMany(x => x.detalles)
.WithOne()
.HasForeignKey(x => x.IdOrdenDeCompra);

View File

@@ -0,0 +1,576 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Modelo;
#nullable disable
namespace Modelo.Migrations
{
[DbContext(typeof(Context))]
[Migration("20240907203054_funcatodo")]
partial class funcatodo
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Entidades.Categoria", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Descripcion")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Categoria", (string)null);
});
modelBuilder.Entity("Entidades.Cliente", b =>
{
b.Property<long>("Cuit")
.HasColumnType("bigint");
b.Property<string>("Apellido")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<string>("Correo")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");
b.Property<string>("Direccion")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<bool>("Habilitado")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(true);
b.Property<string>("Nombre")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.HasKey("Cuit");
b.ToTable("Clientes", (string)null);
});
modelBuilder.Entity("Entidades.DetalleFactura", b =>
{
b.Property<int>("Id")
.HasColumnType("int");
b.Property<int>("IdFactura")
.HasColumnType("int");
b.Property<int>("Cantidad")
.HasColumnType("int");
b.Property<int>("ProductoId")
.HasColumnType("int");
b.HasKey("Id", "IdFactura");
b.HasIndex("IdFactura");
b.HasIndex("ProductoId");
b.ToTable("DetallesFacturas", (string)null);
});
modelBuilder.Entity("Entidades.DetalleOrdenDeCompra", b =>
{
b.Property<int>("Id")
.HasColumnType("int");
b.Property<int>("IdOrdenDeCompra")
.HasColumnType("int");
b.Property<int>("Cantidad")
.HasColumnType("int");
b.Property<int>("IdPresupuesto")
.HasColumnType("int");
b.Property<double>("MontoCU")
.HasColumnType("float");
b.Property<int>("ProductoId")
.HasColumnType("int");
b.HasKey("Id", "IdOrdenDeCompra");
b.HasIndex("IdOrdenDeCompra");
b.HasIndex("ProductoId");
b.ToTable("DetalleOrdenDeCompras");
});
modelBuilder.Entity("Entidades.DetallePresupuesto", b =>
{
b.Property<int>("Id")
.HasColumnType("int");
b.Property<int>("IdPresupuesto")
.HasColumnType("int");
b.Property<int>("Cantidad")
.HasColumnType("int");
b.Property<double>("MontoCUPropuesto")
.HasColumnType("float");
b.Property<int>("ProductoId")
.HasColumnType("int");
b.HasKey("Id", "IdPresupuesto");
b.HasIndex("IdPresupuesto");
b.HasIndex("ProductoId");
b.ToTable("DetallePresupuestos");
});
modelBuilder.Entity("Entidades.Factura", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<long>("ClienteCuit")
.HasColumnType("bigint");
b.Property<DateTime>("Fecha")
.HasColumnType("datetime2");
b.Property<long>("IdCliente")
.HasColumnType("bigint");
b.Property<double>("Total")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClienteCuit");
b.ToTable("Facturas", (string)null);
});
modelBuilder.Entity("Entidades.Lote", b =>
{
b.Property<int>("Id")
.HasColumnType("int");
b.Property<int>("IdRemito")
.HasColumnType("int");
b.Property<int>("Cantidad")
.HasColumnType("int");
b.Property<DateTime>("Fecha")
.HasColumnType("datetime2");
b.Property<bool>("Habilitado")
.HasColumnType("bit");
b.Property<int>("ProductoId")
.HasColumnType("int");
b.HasKey("Id", "IdRemito");
b.HasIndex("IdRemito");
b.HasIndex("ProductoId");
b.ToTable("Lotes");
});
modelBuilder.Entity("Entidades.OrdenDeCompra", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("Entregado")
.HasColumnType("bit");
b.Property<long>("IdProveedor")
.HasColumnType("bigint");
b.Property<long>("ProveedorCuit")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("ProveedorCuit");
b.ToTable("OrdenDeCompras");
});
modelBuilder.Entity("Entidades.Presupuesto", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("Aceptado")
.HasColumnType("bit");
b.Property<DateTime>("Fecha")
.HasColumnType("datetime2");
b.Property<bool>("Habilitado")
.HasColumnType("bit");
b.Property<long>("IdProveedor")
.HasColumnType("bigint");
b.Property<long>("ProveedorCuit")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("ProveedorCuit");
b.ToTable("Presupuestos");
});
modelBuilder.Entity("Entidades.Producto", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Discriminator")
.IsRequired()
.HasMaxLength(21)
.HasColumnType("nvarchar(21)");
b.Property<bool>("EsPerecedero")
.HasColumnType("bit");
b.Property<bool>("Habilitado")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(true);
b.Property<string>("Nombre")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<double>("Precio")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Producto");
b.HasDiscriminator().HasValue("Producto");
b.UseTphMappingStrategy();
});
modelBuilder.Entity("Entidades.Proveedor", b =>
{
b.Property<long>("Cuit")
.HasColumnType("bigint");
b.Property<string>("Direccion")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("nvarchar(60)");
b.Property<bool>("Habilitado")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(true);
b.Property<string>("Nombre")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<string>("RazonSocial")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("nvarchar(60)");
b.HasKey("Cuit");
b.ToTable("Proveedores");
});
modelBuilder.Entity("Entidades.Remito", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("IdProveedor")
.HasColumnType("int");
b.Property<long>("ProveedorCuit")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("ProveedorCuit");
b.ToTable("Remitos");
});
modelBuilder.Entity("ProductoCategoria", b =>
{
b.Property<int>("CategoriaId")
.HasColumnType("int");
b.Property<int>("ProductoId")
.HasColumnType("int");
b.HasKey("CategoriaId", "ProductoId");
b.HasIndex("ProductoId");
b.ToTable("ProductoCategoria");
});
modelBuilder.Entity("ProductoProveedor", b =>
{
b.Property<long>("ProveedorId")
.HasColumnType("bigint");
b.Property<int>("ProductoId")
.HasColumnType("int");
b.HasKey("ProveedorId", "ProductoId");
b.HasIndex("ProductoId");
b.ToTable("ProductoProveedor");
});
modelBuilder.Entity("Entidades.ProductoNoPercedero", b =>
{
b.HasBaseType("Entidades.Producto");
b.Property<string>("TipoDeEnvase")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasDiscriminator().HasValue("ProductoNoPercedero");
});
modelBuilder.Entity("Entidades.ProductoPercedero", b =>
{
b.HasBaseType("Entidades.Producto");
b.Property<int>("MesesHastaConsumoPreferente")
.HasColumnType("int");
b.Property<int>("MesesHastaVencimiento")
.HasColumnType("int");
b.HasDiscriminator().HasValue("ProductoPercedero");
});
modelBuilder.Entity("Entidades.DetalleFactura", b =>
{
b.HasOne("Entidades.Factura", null)
.WithMany("Detalles")
.HasForeignKey("IdFactura")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entidades.Producto", "Producto")
.WithMany()
.HasForeignKey("ProductoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Producto");
});
modelBuilder.Entity("Entidades.DetalleOrdenDeCompra", b =>
{
b.HasOne("Entidades.OrdenDeCompra", null)
.WithMany("Detalles")
.HasForeignKey("IdOrdenDeCompra")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entidades.Producto", "Producto")
.WithMany()
.HasForeignKey("ProductoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Producto");
});
modelBuilder.Entity("Entidades.DetallePresupuesto", b =>
{
b.HasOne("Entidades.Presupuesto", null)
.WithMany("detalles")
.HasForeignKey("IdPresupuesto")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entidades.Producto", "Producto")
.WithMany()
.HasForeignKey("ProductoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Producto");
});
modelBuilder.Entity("Entidades.Factura", b =>
{
b.HasOne("Entidades.Cliente", "Cliente")
.WithMany()
.HasForeignKey("ClienteCuit")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cliente");
});
modelBuilder.Entity("Entidades.Lote", b =>
{
b.HasOne("Entidades.Remito", null)
.WithMany("Lotes")
.HasForeignKey("IdRemito")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entidades.Producto", "Producto")
.WithMany()
.HasForeignKey("ProductoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Producto");
});
modelBuilder.Entity("Entidades.OrdenDeCompra", b =>
{
b.HasOne("Entidades.Proveedor", "Proveedor")
.WithMany()
.HasForeignKey("ProveedorCuit")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Proveedor");
});
modelBuilder.Entity("Entidades.Presupuesto", b =>
{
b.HasOne("Entidades.Proveedor", "Proveedor")
.WithMany()
.HasForeignKey("ProveedorCuit")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Proveedor");
});
modelBuilder.Entity("Entidades.Remito", b =>
{
b.HasOne("Entidades.Proveedor", "Proveedor")
.WithMany()
.HasForeignKey("ProveedorCuit")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Proveedor");
});
modelBuilder.Entity("ProductoCategoria", b =>
{
b.HasOne("Entidades.Categoria", null)
.WithMany()
.HasForeignKey("CategoriaId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entidades.Producto", null)
.WithMany()
.HasForeignKey("ProductoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ProductoProveedor", b =>
{
b.HasOne("Entidades.Producto", null)
.WithMany()
.HasForeignKey("ProductoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entidades.Proveedor", null)
.WithMany()
.HasForeignKey("ProveedorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entidades.Factura", b =>
{
b.Navigation("Detalles");
});
modelBuilder.Entity("Entidades.OrdenDeCompra", b =>
{
b.Navigation("Detalles");
});
modelBuilder.Entity("Entidades.Presupuesto", b =>
{
b.Navigation("detalles");
});
modelBuilder.Entity("Entidades.Remito", b =>
{
b.Navigation("Lotes");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,95 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Modelo.Migrations
{
/// <inheritdoc />
public partial class funcatodo : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DetallesFacturas_Producto_IdProducto",
table: "DetallesFacturas");
migrationBuilder.DropColumn(
name: "IdProducto",
table: "Lotes");
migrationBuilder.DropColumn(
name: "IdProducto",
table: "DetallePresupuestos");
migrationBuilder.DropColumn(
name: "IdProducto",
table: "DetalleOrdenDeCompras");
migrationBuilder.RenameColumn(
name: "IdProducto",
table: "DetallesFacturas",
newName: "ProductoId");
migrationBuilder.RenameIndex(
name: "IX_DetallesFacturas_IdProducto",
table: "DetallesFacturas",
newName: "IX_DetallesFacturas_ProductoId");
migrationBuilder.AddForeignKey(
name: "FK_DetallesFacturas_Producto_ProductoId",
table: "DetallesFacturas",
column: "ProductoId",
principalTable: "Producto",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DetallesFacturas_Producto_ProductoId",
table: "DetallesFacturas");
migrationBuilder.RenameColumn(
name: "ProductoId",
table: "DetallesFacturas",
newName: "IdProducto");
migrationBuilder.RenameIndex(
name: "IX_DetallesFacturas_ProductoId",
table: "DetallesFacturas",
newName: "IX_DetallesFacturas_IdProducto");
migrationBuilder.AddColumn<int>(
name: "IdProducto",
table: "Lotes",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "IdProducto",
table: "DetallePresupuestos",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "IdProducto",
table: "DetalleOrdenDeCompras",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddForeignKey(
name: "FK_DetallesFacturas_Producto_IdProducto",
table: "DetallesFacturas",
column: "IdProducto",
principalTable: "Producto",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -86,14 +86,14 @@ namespace Modelo.Migrations
b.Property<int>("Cantidad")
.HasColumnType("int");
b.Property<int>("IdProducto")
b.Property<int>("ProductoId")
.HasColumnType("int");
b.HasKey("Id", "IdFactura");
b.HasIndex("IdFactura");
b.HasIndex("IdProducto");
b.HasIndex("ProductoId");
b.ToTable("DetallesFacturas", (string)null);
});
@@ -112,9 +112,6 @@ namespace Modelo.Migrations
b.Property<int>("IdPresupuesto")
.HasColumnType("int");
b.Property<int>("IdProducto")
.HasColumnType("int");
b.Property<double>("MontoCU")
.HasColumnType("float");
@@ -127,7 +124,7 @@ namespace Modelo.Migrations
b.HasIndex("ProductoId");
b.ToTable("DetalleOrdenDeCompras");
b.ToTable("DetalleOrdenDeCompras", (string)null);
});
modelBuilder.Entity("Entidades.DetallePresupuesto", b =>
@@ -141,9 +138,6 @@ namespace Modelo.Migrations
b.Property<int>("Cantidad")
.HasColumnType("int");
b.Property<int>("IdProducto")
.HasColumnType("int");
b.Property<double>("MontoCUPropuesto")
.HasColumnType("float");
@@ -156,7 +150,7 @@ namespace Modelo.Migrations
b.HasIndex("ProductoId");
b.ToTable("DetallePresupuestos");
b.ToTable("DetallePresupuestos", (string)null);
});
modelBuilder.Entity("Entidades.Factura", b =>
@@ -203,9 +197,6 @@ namespace Modelo.Migrations
b.Property<bool>("Habilitado")
.HasColumnType("bit");
b.Property<int>("IdProducto")
.HasColumnType("int");
b.Property<int>("ProductoId")
.HasColumnType("int");
@@ -215,7 +206,7 @@ namespace Modelo.Migrations
b.HasIndex("ProductoId");
b.ToTable("Lotes");
b.ToTable("Lotes", (string)null);
});
modelBuilder.Entity("Entidades.OrdenDeCompra", b =>
@@ -239,7 +230,7 @@ namespace Modelo.Migrations
b.HasIndex("ProveedorCuit");
b.ToTable("OrdenDeCompras");
b.ToTable("OrdenDeCompras", (string)null);
});
modelBuilder.Entity("Entidades.Presupuesto", b =>
@@ -269,7 +260,7 @@ namespace Modelo.Migrations
b.HasIndex("ProveedorCuit");
b.ToTable("Presupuestos");
b.ToTable("Presupuestos", (string)null);
});
modelBuilder.Entity("Entidades.Producto", b =>
@@ -303,7 +294,7 @@ namespace Modelo.Migrations
b.HasKey("Id");
b.ToTable("Producto");
b.ToTable("Producto", (string)null);
b.HasDiscriminator().HasValue("Producto");
@@ -337,7 +328,7 @@ namespace Modelo.Migrations
b.HasKey("Cuit");
b.ToTable("Proveedores");
b.ToTable("Proveedores", (string)null);
});
modelBuilder.Entity("Entidades.Remito", b =>
@@ -358,7 +349,7 @@ namespace Modelo.Migrations
b.HasIndex("ProveedorCuit");
b.ToTable("Remitos");
b.ToTable("Remitos", (string)null);
});
modelBuilder.Entity("ProductoCategoria", b =>
@@ -373,7 +364,7 @@ namespace Modelo.Migrations
b.HasIndex("ProductoId");
b.ToTable("ProductoCategoria");
b.ToTable("ProductoCategoria", (string)null);
});
modelBuilder.Entity("ProductoProveedor", b =>
@@ -388,7 +379,7 @@ namespace Modelo.Migrations
b.HasIndex("ProductoId");
b.ToTable("ProductoProveedor");
b.ToTable("ProductoProveedor", (string)null);
});
modelBuilder.Entity("Entidades.ProductoNoPercedero", b =>
@@ -425,7 +416,7 @@ namespace Modelo.Migrations
b.HasOne("Entidades.Producto", "Producto")
.WithMany()
.HasForeignKey("IdProducto")
.HasForeignKey("ProductoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

View File

@@ -22,7 +22,7 @@ namespace Modelo
}
catch (DbUpdateException ex)
{
Console.Error.WriteLine(ex);
throw;
}
return ret;

View File

@@ -14,7 +14,9 @@ namespace Modelo
public override List<Categoria> Listar()
{
return context.Categorias.ToList();
return context.Categorias
.AsNoTracking()
.ToList();
}
public Categoria ObtenerPorId(int Tid)

View File

@@ -1,4 +1,5 @@
using Entidades;
using Microsoft.EntityFrameworkCore;
using System.Security.Cryptography;
namespace Modelo
@@ -13,7 +14,9 @@ namespace Modelo
public override List<Cliente> Listar()
{
return context.Clientes.ToList();
return context.Clientes
.AsNoTracking()
.ToList();
}
public Cliente ObtenerPorId(Int64 Tid)

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using Entidades;
using Microsoft.EntityFrameworkCore;
namespace Modelo
{
@@ -12,7 +13,9 @@ namespace Modelo
public override List<Factura> Listar()
{
return context.Facturas.ToList();
return context.Facturas
.AsNoTracking()
.ToList();
}
public Factura ObtenerPorId(int Tid)

View File

@@ -1,4 +1,5 @@
using Entidades;
using Microsoft.EntityFrameworkCore;
using System.Runtime.Intrinsics.Arm;
namespace Modelo
@@ -12,7 +13,10 @@ namespace Modelo
public override List<Lote> Listar()
{
return context.Lotes.ToList();
return context.Lotes
.AsNoTracking()
.Include(x => x.Producto)
.ToList();
}
public Lote ObtenerPorId(int Tid)

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using Entidades;
using Microsoft.EntityFrameworkCore;
namespace Modelo
{
@@ -12,7 +13,12 @@ namespace Modelo
public override List<OrdenDeCompra> Listar()
{
return context.OrdenDeCompras.ToList();
return context.OrdenDeCompras
.AsNoTracking()
.Include(x => x.Proveedor)
.Include(x => x.detalles)
.ThenInclude(x => x.Producto)
.ToList();
}
public OrdenDeCompra ObtenerPorId(int Tid)
@@ -23,6 +29,14 @@ namespace Modelo
public override void Add(OrdenDeCompra t)
{
t.Proveedor = context.Proveedores.First(x => x.Cuit == t.Proveedor.Cuit);
foreach (var detalle in t.detalles)
{
detalle.Producto = (detalle.Producto.EsPerecedero) ?
context.ProductoPercederos.First(x => x.Id == detalle.Producto.Id) :
context.ProductoNoPercederos.First(x => x.Id == detalle.Producto.Id);
}
context.OrdenDeCompras.Add(t);
}

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using Entidades;
using Microsoft.EntityFrameworkCore;
namespace Modelo
{
@@ -12,7 +13,12 @@ namespace Modelo
public override List<Presupuesto> Listar()
{
return context.Presupuestos.ToList();
return context.Presupuestos
.AsNoTracking()
.Include(x => x.detalles)
.ThenInclude(x => x.Producto)
.Include(x => x.Proveedor)
.ToList();
}
public Presupuesto ObtenerPorId(int Tid)
@@ -23,6 +29,18 @@ namespace Modelo
public override void Add(Presupuesto t)
{
t.Proveedor = context.Proveedores.First(x => x.Cuit == t.Proveedor.Cuit);
foreach (var detalle in t.detalles)
{
detalle.IdPresupuesto = t.Id;
detalle.Producto = detalle.Producto.EsPerecedero ?
context.ProductoPercederos.First(x => x.Id == detalle.Producto.Id) :
context.ProductoNoPercederos.First(x => x.Id == detalle.Producto.Id);
}
context.Presupuestos.Add(t);
}
@@ -34,8 +52,10 @@ namespace Modelo
}
public override void Mod(Presupuesto t)
{
context.Presupuestos.Update(t);
{ // más que modificar es un marcar como aceptado
var pre = context.Presupuestos.First(x => x.Id == t.Id);
pre.Aceptado = t.Aceptado;
}
}
}

View File

@@ -1,4 +1,5 @@
using Entidades;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -16,7 +17,11 @@ namespace Modelo
public override List<ProductoNoPercedero> Listar()
{
return context.ProductoNoPercederos.ToList();
return context.ProductoNoPercederos
.AsNoTracking()
.Include(x => x.proveedores)
.Include(x => x.categorias)
.ToList();
}
public ProductoNoPercedero ObtenerPorId(int Tid)
@@ -27,6 +32,16 @@ namespace Modelo
public override void Add(ProductoNoPercedero t)
{
foreach (var prov in t.proveedores)
{
var prove = context.Proveedores.First(x => x.Cuit == prov.Cuit);
t.proveedores.Add(prove);
}
foreach (var categoria in t.categorias)
{
var cat = context.Categorias.First(x => x.Id == categoria.Id);
t.categorias.Add(cat);
}
context.ProductoNoPercederos.Add(t);
}
@@ -39,7 +54,30 @@ namespace Modelo
public override void Mod(ProductoNoPercedero t)
{
context.ProductoNoPercederos.Update(t);
ProductoNoPercedero pro = context.ProductoNoPercederos
.Include(x => x.proveedores)
.Include(x => x.categorias)
.First(x => x.Id == t.Id);
pro.Nombre = t.Nombre;
pro.Precio = t.Precio;
pro.Habilitado = t.Habilitado;
pro.TipoDeEnvase = t.TipoDeEnvase;
pro.EsPerecedero = t.EsPerecedero;
pro.proveedores.Clear();
pro.categorias.Clear();
foreach (var prov in t.proveedores)
{
var prove = context.Proveedores.First(x => x.Cuit == prov.Cuit);
pro.proveedores.Add(prove);
}
foreach (var categoria in t.categorias)
{
var cat = context.Categorias.First(x => x.Id == categoria.Id);
pro.categorias.Add(cat);
}
}
}
}

View File

@@ -1,4 +1,5 @@
using Entidades;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -20,8 +21,16 @@ namespace Modelo
public ReadOnlyCollection<Producto> Listar()
{
List<Producto> prod = new();
prod.AddRange(_context.ProductoNoPercederos.ToList());
prod.AddRange(_context.ProductoPercederos.ToList());
prod.AddRange(_context.ProductoNoPercederos
.AsNoTracking()
.Include(x => x.categorias)
.Include(x => x.proveedores)
.ToList());
prod.AddRange(_context.ProductoPercederos
.AsNoTracking()
.Include(x => x.categorias)
.Include(x => x.proveedores)
.ToList());
return prod.AsReadOnly();
}

View File

@@ -1,4 +1,5 @@
using Entidades;
using Microsoft.EntityFrameworkCore;
namespace Modelo
{
@@ -11,7 +12,11 @@ namespace Modelo
public override List<ProductoPercedero> Listar()
{
return context.ProductoPercederos.ToList();
return context.ProductoPercederos
.AsNoTracking()
.Include(x => x.proveedores)
.Include(x => x.categorias)
.ToList();
}
public ProductoPercedero ObtenerPorId(int Tid)
@@ -22,6 +27,16 @@ namespace Modelo
public override void Add(ProductoPercedero t)
{
foreach (var prov in t.proveedores)
{
var prove = context.Proveedores.First(x => x.Cuit == prov.Cuit);
t.proveedores.Add(prove);
}
foreach (var categoria in t.categorias)
{
var cat = context.Categorias.First(x => x.Id == categoria.Id);
t.categorias.Add(cat);
}
context.ProductoPercederos.Add(t);
}
@@ -34,7 +49,40 @@ namespace Modelo
public override void Mod(ProductoPercedero t)
{
context.ProductoPercederos.Update(t);
ProductoPercedero pro = context.ProductoPercederos
.Include(x => x.proveedores)
.Include(x => x.categorias)
.First(x => x.Id == t.Id);
pro.Nombre = t.Nombre;
pro.Precio = t.Precio;
pro.Habilitado = t.Habilitado;
pro.MesesHastaConsumoPreferente = t.MesesHastaConsumoPreferente;
pro.MesesHastaVencimiento = t.MesesHastaVencimiento;
pro.EsPerecedero = t.EsPerecedero;
pro.proveedores.Clear();
pro.categorias.Clear();
foreach (var prov in t.proveedores)
{
var prove = context.Proveedores.First(x => x.Cuit == prov.Cuit);
pro.proveedores.Add(prove);
}
foreach (var categoria in t.categorias)
{
var cate = context.Categorias.First(x => x.Id == categoria.Id);
pro.categorias.Add(cate); // Añade las categorías actualizadas
}
//List<Proveedor> proveedores = new List<Proveedor>();
//foreach (var prov in t.proveedores)
//{
// var prove = context.Proveedores.First(x => x.Cuit == prov.Cuit);
// proveedores.Add(prove);
//}
//t.proveedores = proveedores;
//context.ProductoPercederos.Update(t);
}
}
}

View File

@@ -1,4 +1,5 @@
using Entidades;
using Microsoft.EntityFrameworkCore;
namespace Modelo
{
@@ -11,7 +12,9 @@ namespace Modelo
public override List<Proveedor> Listar()
{
return context.Proveedores.ToList();
return context.Proveedores
.AsNoTracking()
.ToList();
}
public Proveedor ObtenerPorId(long Tid)

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using Entidades;
using Microsoft.EntityFrameworkCore;
namespace Modelo
{
@@ -13,7 +14,12 @@ namespace Modelo
public override List<Remito> Listar()
{
return context.Remitos.ToList();
return context.Remitos
.AsNoTracking()
.Include(x => x.Lotes)
.ThenInclude(x => x.Producto)
.Include(x => x.Proveedor)
.ToList();
}
public Remito ObtenerPorId(int Tid)