public async Task <long> RegisterOrdenSalidaDetalle(OrdenSalidaDetalleForRegister command) { OrdenSalidaDetalle dominio; string linea = ""; int cantidadTotal = 0; var detalles = _context.OrdenSalidaDetalle.Where(x => x.OrdenSalidaId == command.OrdenSalidaId); if (detalles.Count() == 0) { linea = "0001"; } else { linea = detalles.Max(x => x.Linea).ToString(); linea = (Convert.ToInt32(linea) + 1).ToString().PadLeft(4, '0'); } var huelladetalle = await _context.HuellaDetalle.SingleOrDefaultAsync(x => x.HuellaId == command.HuellaId && x.UnidadMedidaId == command.UnidadMedidaId); var huelladetalle_aux = await _context.HuellaDetalle.Where(x => x.HuellaId == command.HuellaId).ToListAsync(); if (huelladetalle.Pallet) // pallet { cantidadTotal = huelladetalle.UntQty * command.Cantidad; command.Cantidad = cantidadTotal; } // else // { // cantidadTotal = huelladetalle.UntQty * command.Cantidad; // } dominio = new OrdenSalidaDetalle(); dominio.Cantidad = command.Cantidad; dominio.Completo = command.Completo; dominio.EstadoID = command.EstadoID; dominio.HuellaId = command.HuellaId; dominio.Linea = linea; dominio.Lote = command.Lote; dominio.OrdenSalidaId = command.OrdenSalidaId; dominio.ProductoId = command.ProductoId; dominio.UnidadMedidaId = command.UnidadMedidaId; using (var transaction = _context.Database.BeginTransaction()) { await _context.OrdenSalidaDetalle.AddAsync(dominio); await _context.SaveChangesAsync(); transaction.Commit(); return(dominio.Id); } }
public CommandContracts.Common.CommandResult Handle(InsertarOrdenSalidaDetalleCommand command) { if (command == null) { throw new ArgumentException("Tiene que ingresar una cliente"); } var dominio = new OrdenSalidaDetalle(); dominio.cantidad = command.cantidad; dominio.fechahoraatencion = command.fechahoraatencion; dominio.idordensalida = command.idordensalida; dominio.idproducto = command.idproducto; dominio.idusuarioatencion = command.idusuarioatencion; dominio.imei = command.imei; dominio.mac = command.mac; dominio.repuesto = command.repuesto; dominio.serie = command.serie; try { _OrdenSalidaDetalleRepository.Add(dominio); _OrdenSalidaDetalleRepository.Commit(); return(new InsertarOrdenSalidaDetalleOutput() { idordensalidadetalle = dominio.idordensalidadetalle }); } catch (Exception ex) { // _ValortablaRepository.Delete(dominio); //_ValortablaRepository.Commit(); throw; } }
public async Task <long> RegisterOrdenSalidaDetalle(OrdenSalidaDetalleForRegister command) { OrdenSalidaDetalle dominio; string linea = ""; //int cantidadTotal = 0; var detalles = _context.OrdenSalidaDetalle.Where(x => x.OrdenSalidaId == command.OrdenSalidaId); if (detalles.Count() == 0) { linea = "0001"; } else { linea = detalles.Max(x => x.Linea).ToString(); linea = (Convert.ToInt32(linea) + 1).ToString().PadLeft(4, '0'); } int total = 0; var inventario = _context.InventarioGeneral.Where(x => x.ProductoId == command.ProductoId).ToList(); inventario.ForEach(x => total = total + x.UntQty); if (total < command.Cantidad) { throw new ArgumentException("No existen productos sufientes en el inventario"); } total = 0; if (command.Lote != null) { var existen = inventario.Where(x => x.LotNum == command.Lote).ToList(); existen.ForEach(x => total = total + x.UntQty); if (total < command.Cantidad) { throw new ArgumentException("No existen productos sufientes en el inventario"); } } dominio = new OrdenSalidaDetalle(); dominio.Cantidad = command.Cantidad; dominio.Completo = command.Completo; dominio.EstadoId = command.EstadoID; dominio.HuellaId = command.HuellaId; dominio.Linea = linea; dominio.Lote = command.Lote; dominio.OrdenSalidaId = command.OrdenSalidaId; dominio.ProductoId = command.ProductoId; dominio.UnidadMedidaId = command.UnidadMedidaId; using (var transaction = _context.Database.BeginTransaction()) { await _context.OrdenSalidaDetalle.AddAsync(dominio); await _context.SaveChangesAsync(); transaction.Commit(); return(dominio.Id); } }