/// <summary> /// devuelve la lista de choferes de la bd que no tienen vehiculos asociados /// </summary> /// <returns>lista de choferes</returns> public async Task <List <Chofer> > choferesDisponibles() { try { List <Chofer> salida = new List <Chofer>(); var lista = await DBRepositoryMongo <Chofer> .GetItemsAsync("Choferes"); List <Chofer> aux = new List <Chofer>(); foreach (Chofer c in lista) { Chofer chofer = c.Desencriptar(c); aux.Add(chofer); } foreach (Chofer c in aux) { if (c.Disponible) { salida.Add(c); } } return(salida); } catch (MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
/// <summary> /// se devuelve el chofer con el id seleccionado /// se desencripta antes de devolverlo /// </summary> /// <param name="idChofer"></param> /// <returns>Chofer</returns> public async Task <Chofer> getChofer(string idChofer) { try { if (idChofer != null) { Chofer chofer = await DBRepositoryMongo <Chofer> .GetItemAsync(idChofer, "Choferes"); chofer = chofer.Desencriptar(chofer); return(chofer); } else { throw new MensajeException("El Id del chofer no existe"); } } catch (MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
/// <summary> /// se toma en cuenta los vehiculos de la bd /// se desencriptan los choferes antes de devolverlos /// </summary> /// <returns>lista de vehiculos que estan ingresados al sistema</returns> public async Task <IEnumerable <Vehiculo> > getVehiculos() { try { var items = await DBRepositoryMongo <Vehiculo> .GetItemsAsync("Vehiculos"); List <Vehiculo> salida = new List <Vehiculo>(); foreach (Vehiculo v in items) { if (!v.Chofer.Id.ToString().Equals("000000000000000000000000")) { Chofer c = v.Chofer; v.Chofer = c.Desencriptar(c); salida.Add(v); } else { salida.Add(v); } } return(salida); } catch (MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
/// <summary> /// ingresa un nuevo chofer al sistema y lo devuelve /// </summary> /// <param name="chofer"></param> /// <param name="libreta"></param> /// <returns>Chofer</returns> public async Task<Chofer> CrearChofer(Chofer chofer, LibretaDeConducir libreta) { Chofer salida = null; try { Chofer c = await DBRepositoryMongo<Chofer>.GetUsuario(chofer.User, "Choferes"); if (c != null) { throw new MensajeException("El chofer ya existe"); } else { salida = chofer; salida.Tipo = "Chofer"; salida.Disponible = true; salida.LibretaDeConducir = libreta; salida.Leyenda = chofer.Numero + " - " + chofer.Nombre + " " + chofer.Apellido; if (salida.Ubicacion == null) { salida.Ubicacion = new PosicionSatelital() { Latitud = "", Longitud = "" }; } salida = salida.Encriptar(salida); await DBRepositoryMongo<Chofer>.Create(salida, "Choferes"); } return salida; } catch(MensajeException msg) { throw msg; }catch(Exception ex) { throw ex; } }
public Vehiculo() { Items = new List <Item>(); Calificacion = 0; Id = new ObjectId(); Matricula = ""; Marca = ""; Modelo = ""; Unidades = 0; Tipo = TipoVehiculo.Otros; Disponible = true; PosicionSatelital = new PosicionSatelital(); Chofer = new Chofer(); CantidadPasajeros = 0; EmpresaAseguradora = ""; VencimientoSeguro = DateTime.Now; Tarifa = 0; VencimientoPermisoPortuario = DateTime.Now; Alto = 0; Largo = 0; Ancho = 0; CantidadPasajeros = 0; EmpresaAseguradora = ""; CapacidadCargaKg = 0; ConsumoKml = 0; }
/// <summary> /// SE ELIMINA EL CHOFER Y SE ACTUALIZAN LOS VEHICULOS EN MEMORIA Y EN LA BD /// </summary> /// <param name="chofer"></param> /// <param name="id"></param> /// <returns></returns> public async Task EliminarChofer(Chofer chofer, string id) { try { if (chofer != null && id != null) { await DBRepositoryMongo<Usuario>.DeleteAsync(id, "Choferes"); var vehiculos = await ControladoraVehiculos.getInstance(_settings).getVehiculos(); List<Vehiculo> aux = vehiculos.ToList(); foreach (Vehiculo v in aux) { if (v.Chofer.Id.ToString().Equals(id)) { v.Chofer = new Chofer(); await ControladoraVehiculos.getInstance(_settings).editarVehiculo(v, v.Id.ToString(), v.Chofer.Id.ToString(), v.Tipo); // se acualiza el vehiculo en memoria y en la bd } } } else { throw new MensajeException("Ha ocurrido un error inesperado, vuelva a intentarlo mas tarde"); } } catch (MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
/// <summary> /// devuelve el chofer si lo puede validar o si no devuelve null /// </summary> /// <param name="usuario"></param> /// <param name="pass"></param> /// <returns>el chofer con las credenciales solicitadas</returns> public async Task<Chofer>LoginChofer(string usuario, string pass) { try { Chofer chofer = await DBRepositoryMongo<Chofer>.Login(Seguridad.Encriptar(usuario), "Choferes"); if (chofer != null) { chofer = chofer.Desencriptar(chofer); if (chofer.Password == pass) { return chofer; } else { throw new MensajeException("Usuario y/o contraseña incorrecta"); } } else { throw new MensajeException("Usuario y/o contraseña incorrecta"); } } catch(MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
/// <summary> /// Inserta un cliente encriptado en la base de datos /// </summary> /// <param name="cliente"></param> /// <param name="tarjeta"></param> /// <returns></returns> public async Task CrearCliente(Cliente cliente, TarjetaDeCredito tarjeta) { try { Cliente salida = null; Usuario usuario = await DBRepositoryMongo<Usuario>.GetUsuario(Seguridad.Encriptar(cliente.User), "Usuarios"); Cliente cli = await DBRepositoryMongo<Cliente>.GetUsuario(Seguridad.Encriptar(cliente.User), "Clientes"); Chofer chofer = await DBRepositoryMongo<Chofer>.GetUsuario(Seguridad.Encriptar(cliente.User), "Choferes"); if (usuario == null && cli == null && chofer == null) { cliente.Tipo = "Cliente"; cliente.Tarjeta = tarjeta; if (cliente.RazonSocial != null) { cliente.Leyenda = cliente.RazonSocial; } else { cliente.Leyenda = cliente.Nombre + " " + cliente.Apellido; cliente.RazonSocial = ""; } if (cliente.Rut == null) { cliente.Rut = ""; } if (cliente.Ubicacion == null) { cliente.Ubicacion = new PosicionSatelital() { Latitud = "", Longitud = "" }; } if (string.IsNullOrEmpty(cliente.Tarjeta.fVencimiento)) { cliente.Tarjeta.fVencimiento = ""; } if (string.IsNullOrEmpty(cliente.Tarjeta.Numero)) { cliente.Tarjeta.Numero = ""; } salida = cliente.Encriptar(cliente); await DBRepositoryMongo<Cliente>.Create(salida, "Clientes"); } else { throw new MensajeException("Ya existe un usuario con ese nick"); } } catch (MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
/// <summary> /// DEVUELVE EL CHOFER CON EL ID SOLICITADO /// </summary> /// <param name="id"></param> /// <returns>CHOFER</returns> public async Task<Chofer> getChofer(string id) { Chofer usuario = null; if (id == null) { throw new MensajeException("Id de usuario inexistente"); } else { usuario = await DBRepositoryMongo<Chofer>.GetItemAsync(id, "Choferes"); usuario.Desencriptar(usuario); return usuario; } }
/// <summary> /// recibe un chofer desencriptado y lo devuelve encriptado /// </summary> /// <param name="chofer"></param> /// <returns>chofer encriptado</returns> public Chofer Encriptar(Chofer chofer) { chofer.Apellido = Seguridad.Encriptar(chofer.Apellido); chofer.Direccion = Seguridad.Encriptar(chofer.Direccion); chofer.Documento = Seguridad.Encriptar(chofer.Documento); chofer.Email = Seguridad.Encriptar(chofer.Email); chofer.FNacimiento = Seguridad.Encriptar(chofer.FNacimiento); chofer.Nombre = Seguridad.Encriptar(chofer.Nombre); chofer.Password = Seguridad.Encriptar(chofer.Password); chofer.Telefono = Seguridad.Encriptar(chofer.Telefono); chofer.Tipo = Seguridad.Encriptar(chofer.Tipo); chofer.User = Seguridad.Encriptar(chofer.User); chofer.Ubicacion.Latitud = Seguridad.Encriptar(chofer.Ubicacion.Latitud); chofer.Ubicacion.Longitud = Seguridad.Encriptar(chofer.Ubicacion.Longitud); chofer.LibretaDeConducir.Categoria = Seguridad.Encriptar(chofer.LibretaDeConducir.Categoria); chofer.LibretaDeConducir.FVencimiento = Seguridad.Encriptar(chofer.LibretaDeConducir.FVencimiento); chofer.Leyenda = Seguridad.Encriptar(chofer.Leyenda); return(chofer); }
/// <summary> /// DEVUELVE LA LISTA DE CHOFERES QUE HAY EN EL SISTEMA /// </summary> /// <returns>LISTA DE CHOFER</returns> public async Task<List<Chofer>> getChoferes() { try { var items = await DBRepositoryMongo<Chofer>.GetItemsAsync("Choferes"); List<Chofer> salida = new List<Chofer>(); foreach (Chofer c in items) { Chofer aux = c.Desencriptar(c); salida.Add(aux); } return salida; } catch (MensajeException msg) { throw msg; } catch (Exception) { throw new MensajeException("Se produjo un error inesperado, intente de nuevo mas tarde"); } }
/// <summary> /// modifica el chofer pasado en la base. Se tienen en cuenta tambien los vehiculos en base y en memoria /// </summary> /// <param name="chofer"></param> /// <param name="idChofer"></param> /// <returns></returns> public async Task ModificarChofer(Chofer chofer, string idChofer) { try { if (chofer != null && idChofer != null) { chofer.Id = new ObjectId(idChofer); if (chofer.Ubicacion == null) { chofer.Ubicacion = new PosicionSatelital() { Latitud = "", Longitud = "" }; } chofer = chofer.Encriptar(chofer); await DBRepositoryMongo<Chofer>.UpdateAsync(chofer.Id, chofer, "Choferes"); Vehiculo v = await ControladoraVehiculos.getInstance(_settings).getVehiculoChofer(idChofer); if (v != null) { v.Chofer = chofer.Encriptar(chofer); await ControladoraVehiculos.getInstance(_settings).editarVehiculo(v, v.Id.ToString(), chofer.Id.ToString(), v.Tipo); } } else { throw new MensajeException("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde"); } } catch (MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
public LiquidacionChofer() { Viajes = new List <Viaje>(); Chofer = new Chofer(); }
/// <summary> /// Se edita el vehiculo pasado. El id del vehiculo se utiliza para reconstruir el objeto ObjectId. /// si no se pasa un chofer, se crea solo un vehiculo /// </summary> /// <param name="vehiculo"></param> /// <param name="idVehiculo"></param> /// <param name="choferSeleccionado"></param> /// <param name="tipoVehiculo"></param> /// <returns></returns> public async Task editarVehiculo(Vehiculo vehiculo, string idVehiculo, string choferSeleccionado, TipoVehiculo tipoVehiculo) { try { if (vehiculo != null && !choferSeleccionado.Equals("000000000000000000000000")) { vehiculo.Id = new ObjectId(idVehiculo); vehiculo.Unidades = calcularUnidades(vehiculo.Alto, vehiculo.Ancho, vehiculo.Largo); vehiculo.Tipo = tipoVehiculo; //Chofer chofer = await DBRepositoryMongo<Chofer>.GetItemAsync(choferSeleccionado, "Choferes"); Chofer chofer = await ControladoraUsuarios.getInstance(_settings).getChofer(choferSeleccionado); if (chofer != null) { vehiculo.Chofer = chofer; } chofer = chofer.Encriptar(chofer); await DBRepositoryMongo <Vehiculo> .UpdateAsync(vehiculo.Id, vehiculo, "Vehiculos"); Vehiculo eliminar = null; foreach (Vehiculo v in Vehiculos) { if (v.Id.ToString().Equals(idVehiculo)) { if (v.Disponible && v.Items.Count > 0)// me fijo que no este en un viaje { eliminar = v; } } } if (eliminar != null) { Vehiculos.Remove(eliminar); Vehiculos.Add(vehiculo); } } else if (vehiculo != null && choferSeleccionado.Equals("000000000000000000000000")) { vehiculo.Id = new ObjectId(idVehiculo); vehiculo.Unidades = calcularUnidades(vehiculo.Alto, vehiculo.Ancho, vehiculo.Largo); vehiculo.Tipo = tipoVehiculo; vehiculo.Chofer = new Chofer(); await DBRepositoryMongo <Vehiculo> .UpdateAsync(vehiculo.Id, vehiculo, "Vehiculos"); Vehiculo eliminar = null; foreach (Vehiculo v in Vehiculos) { if (v.Id.ToString().Equals(idVehiculo)) { eliminar = v; } } Vehiculos.Remove(eliminar); Vehiculos.Add(vehiculo); } else { throw new MensajeException("Ha ocurrido un error inesperado, vuelva a intentarlo mas tarde"); } } catch (MensajeException msg) { throw msg; } catch (Exception ex) { throw ex; } }
/// <summary> /// guarda un nuevo vehiculo con o sin chofer. si no tiene chofer no queda disponible /// </summary> /// <param name="vehiculo"></param> /// <param name="idChofer"></param> /// <returns></returns> public async Task nuevoVehiculo(Vehiculo vehiculo, string idChofer) { try { if (vehiculo != null && !idChofer.Equals("000000000000000000000000")) { Chofer chofer = await getChofer(idChofer); chofer.Disponible = false; chofer = chofer.Encriptar(chofer); vehiculo.Chofer = chofer; vehiculo.Disponible = true; vehiculo.Unidades = calcularUnidades(vehiculo.Largo, vehiculo.Ancho, vehiculo.Alto); Tarifa t = await ControladoraViajes.getInstancia(_settings).obtenerUltimaTarifa(); if (vehiculo.Tipo.Equals(TipoVehiculo.Camioneta)) { vehiculo.Tarifa = t.Camioneta; } if (vehiculo.Tipo.Equals(TipoVehiculo.CamionChico)) { vehiculo.Tarifa = t.CamionChico; } if (vehiculo.Tipo.Equals(TipoVehiculo.Camion)) { vehiculo.Tarifa = t.Camion; } if (vehiculo.Tipo.Equals(TipoVehiculo.CamionGrande)) { vehiculo.Tarifa = t.CamionGrande; } if (vehiculo.Tipo.Equals(TipoVehiculo.CamionMudanza)) { vehiculo.Tarifa = t.CamionMudanza; } await DBRepositoryMongo <Vehiculo> .Create(vehiculo, "Vehiculos"); Vehiculos.Add(vehiculo); await DBRepositoryMongo <Chofer> .UpdateAsync(chofer.Id, chofer, "Choferes"); } else if (vehiculo != null && idChofer.Equals("000000000000000000000000")) { Tarifa t = await ControladoraViajes.getInstancia(_settings).obtenerUltimaTarifa(); if (vehiculo.Tipo.Equals(TipoVehiculo.Camioneta)) { vehiculo.Tarifa = t.Camioneta; } if (vehiculo.Tipo.Equals(TipoVehiculo.CamionChico)) { vehiculo.Tarifa = t.CamionChico; } if (vehiculo.Tipo.Equals(TipoVehiculo.Camion)) { vehiculo.Tarifa = t.Camion; } if (vehiculo.Tipo.Equals(TipoVehiculo.CamionGrande)) { vehiculo.Tarifa = t.CamionGrande; } if (vehiculo.Tipo.Equals(TipoVehiculo.CamionMudanza)) { vehiculo.Tarifa = t.CamionMudanza; } vehiculo.Chofer = new Chofer(); vehiculo.Disponible = false; vehiculo.Unidades = calcularUnidades(vehiculo.Largo, vehiculo.Ancho, vehiculo.Alto); await DBRepositoryMongo <Vehiculo> .Create(vehiculo, "Vehiculos"); Vehiculos.Add(vehiculo); } else { throw new MensajeException("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde"); } } catch (MensajeException msg) { throw msg; } catch (Exception e) { throw (e); } }