113 lines
4.2 KiB
C#
113 lines
4.2 KiB
C#
using Entidades;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Modelo;
|
|
public class RepositorioVentas: RepositorioBase<RepositorioVentas> {
|
|
public bool EfectuarVenta(long idventa) {
|
|
var con = Context;
|
|
var vent = con.Ventas.Include(x=>x.IdpropiedadNavigation).FirstOrDefault(x => x.Id == idventa);
|
|
if (vent == null||vent.Idestado != 2) return false;
|
|
|
|
vent.IdpropiedadNavigation.Dnipropietario = vent.IdComprador;
|
|
|
|
vent.IdpropiedadNavigation.Idestado=3;
|
|
vent.Idestado=3;
|
|
vent.Fechafinal = DateTime.Now;
|
|
return Guardar(con);
|
|
}
|
|
|
|
public bool IniciarVenta(Venta v, long dni) {
|
|
var con = Context;
|
|
v.Id = (con.Ventas.Any()?con.Ventas.Count():0)+1;
|
|
|
|
con.Ventas.Add(v);
|
|
GenerarLog(con, dni, "Alta Venta espera recibo");
|
|
return Guardar(con);
|
|
}
|
|
|
|
public Contrato? ObtenerVentaPorContrato(long idcontrato) {
|
|
var con = Context;
|
|
var c = con.Contratos.Include(x=>x.Idcanons).Include(x=>x.IdventaNavigation).ThenInclude(x=>x.IddivisaNavigation)
|
|
.FirstOrDefault(x=>x.Id == idcontrato);
|
|
if (c == null || c.IdventaNavigation == null) return null;
|
|
return c;
|
|
}
|
|
|
|
public Venta? ObtenerVentaPorId(long idventa) {
|
|
var con = Context;
|
|
var vent = con.Ventas
|
|
.Include(x=>x.IddivisaNavigation)
|
|
.Include(x=>x.IdestadoNavigation)
|
|
.Include(x=>x.IdVendedorNavigation)
|
|
.Include(x=>x.IdCompradorNavigation)
|
|
.Include(x=>x.IdpropiedadNavigation)
|
|
.Where(x=>x.Idestado != 1)
|
|
.FirstOrDefault(x=>x.Id == idventa);
|
|
if (vent == null) return null;
|
|
return vent;
|
|
}
|
|
|
|
public IQueryable<Venta>? ObtenerVentasPorDni(long dni) {
|
|
var con = Context;
|
|
var venta = con.Ventas
|
|
.Include(x=>x.IddivisaNavigation)
|
|
.Include(x=>x.IdestadoNavigation)
|
|
.Include(x=>x.IdVendedorNavigation)
|
|
.Include(x=>x.IdCompradorNavigation)
|
|
.Include(x=>x.IdpropiedadNavigation)
|
|
.Where(x=>(x.IdComprador == dni || x.IdVendedor == dni) && x.Idestado!=1 )
|
|
.Distinct();
|
|
return venta;
|
|
}
|
|
|
|
public bool PatchVenta(Venta venta, long dni) {
|
|
var con = Context;
|
|
var a = con.Ventas.FirstOrDefault(x=>x.Id == venta.Id);
|
|
|
|
a.IdVendedor = venta.IdVendedor;
|
|
a.IdComprador = venta.IdComprador;
|
|
a.Idpropiedad = venta.Idpropiedad;
|
|
a.Fechainicio = venta.Fechainicio;
|
|
a.Idestado=2;
|
|
GenerarLog(con, dni, $"Se Ejercio la opcion de venta para la propiedad: {venta.Idpropiedad}");
|
|
return Guardar(con);
|
|
}
|
|
|
|
public bool SetUrlRecibo(long id, string nuevoNombreArchivo, long dni) {
|
|
var con = Context;
|
|
var venta = con.Ventas.FirstOrDefault(x=>x.Id == id);
|
|
if (venta==null) return false;
|
|
venta.UrlRecibo = nuevoNombreArchivo;
|
|
GenerarLog(con, dni, $"Se seteo el recibo con nombre: {nuevoNombreArchivo}");
|
|
return Guardar(con);
|
|
}
|
|
|
|
public bool SetVenta(int idpropiedad, decimal monto, int iddivisa, long dni) {
|
|
var con = Context;
|
|
Propiedade? cont = con.Propiedades.Include(x=>x.Contratos).FirstOrDefault(x=>x.Id == idpropiedad);
|
|
if (cont==null) return false;
|
|
if (cont.Idestado == 2 || cont.Idestado == 4) return false;
|
|
if (cont.Contratos.Any(x=>x.Habilitado == 1 && x.Cancelado == 0)) return false;
|
|
|
|
cont.Monto = monto;
|
|
cont.Iddivisa = iddivisa;
|
|
cont.Idestado = 4;
|
|
GenerarLog(con, dni, "Se puso la propiedad de venta");
|
|
return Guardar(con);
|
|
}
|
|
|
|
public bool UnSetVenta(int id, decimal monto, int iddivisa, long dni) {
|
|
var con = Context;
|
|
Propiedade? cont = con.Propiedades.Include(x=>x.Venta).Include(x=>x.Contratos).FirstOrDefault(x=>x.Id == id);
|
|
if (cont==null) return false;
|
|
if (cont.Idestado != 4) return false;
|
|
if (cont.Contratos.Any(x=>x.Habilitado == 1 && x.Cancelado == 0)) return false;
|
|
if (cont.Venta.Any(x=>x.Idestado == 2)) return false;
|
|
|
|
cont.Monto = monto;
|
|
cont.Iddivisa = iddivisa;
|
|
cont.Idestado = 3;
|
|
GenerarLog(con, dni, "Se Bajo la propiedad de venta");
|
|
return Guardar(con);
|
|
}
|
|
} |