public async Task <IActionResult> EditBuque(Buques Buque) { if (_dataContext.Buques.Any(x => x.Codigo == Buque.Codigo)) { var Buques = _dataContext.Buques.First(x => x.Codigo == Buque.Codigo); Buques.BuqueName = Buque.BuqueName; try { await _dataContext.SaveChangesAsync(); return(Ok(new { Data = new { Buque.ID, Buques.Codigo, Buques.BuqueName }, Success = true })); } catch (Exception ex) { return(BadRequest(new { Data = ex.ToString(), Success = false })); } } else { return(BadRequest(new { Data = "El buque con codigo " + Buque.Codigo + " no se encuentra en la base de datos.", Success = false })); } }
public void cambiosBuques(string BUQUE, string VIAJE, string tipo_Cambio) { if (GetBuques != null) { var exportacionIndex = GetBuques.IndexOf(GetBuques.FirstOrDefault(c => c.BUQUE == BUQUE)); if (exportacionIndex >= 0) { if (tipo_Cambio == ChangeType.Update.ToString()) { GetBuques[exportacionIndex] = new Buques { BUQUE = BUQUE, VIAJE = VIAJE } } ; if (tipo_Cambio == ChangeType.Delete.ToString()) { GetBuques.RemoveAt(exportacionIndex); } } else { GetBuques.Add(new Buques { BUQUE = BUQUE, VIAJE = VIAJE }); } } }
public async Task <Buques> Create(Buques Buque) { if (!this.ExistBuque(Buque.Codigo)) { _dataContext.Buques.Add(Buque); } else { return(_dataContext.Buques.FirstOrDefault(x => x.Codigo == Buque.Codigo)); } await _dataContext.SaveChangesAsync(); return(Buque); }
public async Task <IActionResult> CreateBuque(Buques Buque) { List <Buques> ListBuque = new List <Buques>(); try { Buques B = await this.Create(Buque); return(Ok(new { Data = B, Success = true })); } catch (Exception ex) { return(BadRequest(new { Data = ex.ToString(), Success = false })); } }
public async Task <string> CreateMasivo(List <CreatePomas> Pomas) { ExportadorController exportadorController = new ExportadorController(_dataContext); PuertoController puertoController = new PuertoController(_dataContext); BuqueController buqueController = new BuqueController(_dataContext); DestinoController destinoController = new DestinoController(_dataContext); FrutasController frutasController = new FrutasController(_dataContext); FincaController fincaController = new FincaController(_dataContext); PaletController paletController = new PaletController(_dataContext); List <Vehiculos> ListPoma = new List <Vehiculos>(); foreach (var Poma in Pomas) { try { Vehiculos Vehiculo = new Vehiculos(); Vehiculos V = new Vehiculos(); V.Placa = Poma.Placa; Vehiculo = await this.Create(V); Fincas Finca = new Fincas(); Fincas F = new Fincas(); F.Codigo = Poma.Finca.Codigo; F.FincaName = Poma.Finca.FincaName; Finca = await fincaController.Create(F); Puertos Puerto = new Puertos(); Puertos PU = new Puertos(); PU.Codigo = Poma.Puerto.Codigo; PU.PuertoName = Poma.Puerto.PuertoName; Puerto = await puertoController.Create(PU); Destinos Destino = new Destinos(); Destinos D = new Destinos(); D.Codigo = Poma.Destino.Codigo; D.DestinoName = Poma.Destino.DestinoName; Destino = await destinoController.Create(D); Buques Buque = new Buques(); Buques B = new Buques(); B.Codigo = Poma.Buque.Codigo; B.BuqueName = Poma.Buque.BuqueName; Buque = await buqueController.Create(B); Exportadores Exportador = new Exportadores(); Exportadores E = new Exportadores(); E.Codigo = Poma.Exportador.Codigo; E.ExportadorName = Poma.Exportador.ExportadorName; Exportador = await exportadorController.Create(E); TransportGuide TransportGuide = new TransportGuide(); TransportGuide.Vehiculo = Vehiculo; TransportGuide.Numero = Poma.Numero; TransportGuide.Estado = (int)EstadosPoma.NoChequeado; TransportGuide.FechaRegistro = DateTime.UtcNow; TransportGuide.Recibido = false; TransportGuide.LlegadaCamion = Poma.LlegadaCamion.ToUniversalTime(); TransportGuide.SalidaFinca = Poma.SalidaFinca.ToUniversalTime(); TransportGuide.Estimado = Poma.Estimado.ToUniversalTime(); TransportGuide.LlegadaTerminal = null; TransportGuide.Finca = Finca; TransportGuide.Puerto = Puerto; TransportGuide.Buque = Buque; TransportGuide.Destino = Destino; TransportGuide.Exportador = Exportador; bool EditTG = false; TransportGuide valTG = this.ExistTransportGuide(Poma.Numero); if (valTG == null) { _dataContext.TransportGuides.Add(TransportGuide); await _dataContext.SaveChangesAsync(); } else { var currentDate = DateTime.UtcNow.ToLocalTime(); var StartDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 3, 0, 0); var EndDate = StartDate.AddDays(1); EndDate = new DateTime(EndDate.Year, EndDate.Month, EndDate.Day, 2, 59, 0); if (currentDate < StartDate) { StartDate = StartDate.AddDays(-1); EndDate = EndDate.AddDays(-1); } if ((valTG.FechaRegistro >= StartDate && valTG.FechaRegistro <= EndDate) && valTG.Estado == 0) { EditTG = true; } else { return("La poma ya existe"); } } foreach (var detail in Poma.DetailPoma) { Frutas Fruta = new Frutas(); Frutas FR = new Frutas(); FR.Codigo = detail.Frutas.Codigo; FR.FrutaName = detail.Frutas.FrutaName; Fruta = await frutasController.Create(FR); DetailTransportGuide valDTG = null; DetailTransportGuide DetailTG = new DetailTransportGuide(); DetailTG.Fruta = Fruta; if (EditTG) { valDTG = this.ExistDetailTransportGuide(valTG.ID, Fruta.ID); if (valDTG == null) { DetailTG.TransportGuide = valTG; _dataContext.DetailTransportGuide.Add(DetailTG); await _dataContext.SaveChangesAsync(); } } else { DetailTG.TransportGuide = TransportGuide; _dataContext.DetailTransportGuide.Add(DetailTG); await _dataContext.SaveChangesAsync(); } foreach (var palet in detail.Palets) { Pallets Palet = new Pallets(); Palet.CodigoPalet = palet.CodigoPalet; Palet.UsuarioLectura = ""; Palet.LecturaPalet = DateTime.UtcNow; Palet.UsuarioInspeccion = ""; Palet.InspeccionPalet = DateTime.UtcNow; Palet.CaraPalet = palet.CaraPalet; Palet.NumeroCajas = palet.NumeroCajas; Palet.Carga = palet.Carga; Palet.Tipo = palet.Tipo; Palet.Perfilar = false; if (EditTG) { if (valDTG == null) { Palet.DetailTransportGuide = DetailTG; } else { Palet.DetailTransportGuide = valDTG; } } else { Palet.DetailTransportGuide = DetailTG; } _dataContext.Palets.Add(Palet); } } } catch (Exception ex) { continue; } } await _dataContext.SaveChangesAsync(); try { await _NotificationHubContext.Clients.All.BroadcastMessage(Get()); } catch (Exception ex) { return(ex.Message); } return("Ejecutado correctamente"); }