private void VerificarStockLinea(Reservasstock model, ReservasstockLin linea) { if (!string.IsNullOrEmpty(linea.lote)) { VerificarDisponibilidad(model, linea); VerificarPertenenciaKit(model, linea); } }
private void VerificarDisponibilidad(Reservasstock model, ReservasstockLin linea) { var loteid = linea.tabla?.ToString() ?? string.Empty; if ( !_db.Stockactual.Any( f => f.empresa == model.empresa && f.fkalmacenes == model.fkalmacen && f.fkarticulos == linea.fkarticulos && f.lote == linea.lote && f.loteid == loteid && f.cantidaddisponible >= linea.cantidad) && !_db.ReservasstockLin.Any(f => f.empresa == model.empresa && f.fkreservasstock == model.id && f.fkarticulos == linea.fkarticulos && f.lote == linea.lote && f.tabla == linea.tabla)) { throw new ValidationException(string.Format("El Lote {0}{1} no dispone de {2} pieza ", linea.lote, Funciones.RellenaCod(loteid, 3), linea.cantidad)); } }
private void VerificarPertenenciaKit(Reservasstock model, ReservasstockLin linea) { var loteid = linea.tabla?.ToString() ?? string.Empty; if (_db.KitLin.Any(f => f.empresa == model.empresa && f.lote == linea.lote && f.loteid == loteid)) { var kitobj = _db.Kit.Include("KitLin") .Single( f => f.empresa == model.empresa && f.KitLin.Any(j => j.lote == linea.lote && j.loteid == loteid)); if (!kitobj.KitLin.All(f => model.ReservasstockLin.Any(j => j.lote == f.lote && j.tabla.ToString() == f.loteid))) { throw new ValidationException(string.Format("El Lote {0}{1} pertenece al Kit {2} que no está completo. Todas los registros del Kit deben añadirse al albarán.", linea.lote, Funciones.RellenaCod(loteid, 3), kitobj.referencia)); } kitobj.estado = (int)EstadoKit.Vendido; _db.Kit.AddOrUpdate(kitobj); } if (_db.BundleLin.Any(f => f.empresa == model.empresa && f.lote == linea.lote && f.loteid == loteid)) { var bundleobj = _db.Bundle.Include("BundleLin") .Single( f => f.empresa == model.empresa && f.BundleLin.Any(j => j.lote == linea.lote && j.loteid == loteid)); if (!bundleobj.BundleLin.All(f => model.ReservasstockLin.Any(j => j.lote == f.lote && j.tabla.ToString() == f.loteid))) { throw new ValidationException(string.Format("El Lote {0}{1} pertenece al Bundle {0}{2} que no está completo. Todas los registros del Bundle deben añadirse al albarán.", linea.lote, Funciones.RellenaCod(loteid, 3), bundleobj.id)); } bundleobj.estado = (int)EstadoKit.Vendido; _db.Bundle.AddOrUpdate(bundleobj); } }