예제 #1
0
        /// <summary>
        /// This load asynchronously a vehicle.
        /// </summary>
        /// <param name="fields">Fields to be loaded.</param>
        /// <param name="codeVehicle">Vehicle code to be loaded.</param>
        /// <returns></returns>
        public async Task <bool> LoadValue(IDictionary <string, string> fields, string codeVehicle)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            Contract.Requires(!string.IsNullOrEmpty(fields["VEHICULO1"]));
            Contract.Requires(!string.IsNullOrEmpty(fields["VEHICULO2"]));
            Contract.Requires(_vehicleMapper != null);

            string fieldsValue  = fields["VEHICULO1"] + "," + fields["VEHICULO2"];
            string vehicleQuery = string.Format(VehicleQueryFormat, fieldsValue, codeVehicle);

            using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
            {
                try
                {
                    var queryResult = await connection.QueryAsync <VehiclePoco>(vehicleQuery);

                    _vehicleValue = queryResult.FirstOrDefault(c => c.CODIINT == codeVehicle);
                    if (_vehicleValue == null)
                    {
                        return(false);
                    }

                    /*
                     *  See if for the lookup tables. we shall try to use multiple query,
                     */
                    var query = string.Format(BrandByVehicle, _vehicleValue.CODIINT);
                    var brand = await connection.QueryAsync <MARCAS>(query);

                    BrandDtos = _vehicleMapper.Map <IEnumerable <MARCAS>, IEnumerable <BrandVehicleDto> >(brand);
                    var queryPicture = string.Format(PhotoByValue, _vehicleValue.CODIINT);
                    _pictureResult = await connection.QueryAsync <PICTURES>(queryPicture);

                    PictureDtos = _vehicleMapper.Map <IEnumerable <PICTURES>, IEnumerable <PictureDto> >(_pictureResult);
                    var queryActivi = string.Format(ActividadByVehicle, _vehicleValue.ACTIVIDAD);
                    var actividad   = await connection.QueryAsync <ACTIVEHI>(queryActivi);

                    ActividadDtos = _vehicleMapper.Map <IEnumerable <ACTIVEHI>, IEnumerable <ActividadDto> >(actividad);
                    // this is the owner. Just in this case i sue the dto.
                    string queryOwner = string.Format(OwnersByVehicle, _vehicleValue.PROPIE);
                    AssistQueryOwner = queryOwner;
                    OwnerDtos        = await connection.QueryAsync <OwnerDto>(queryOwner);

                    VehicleAgentQuery = string.Format(AgentByVehicule, _vehicleValue.AGENTE);
                    AgentDtos         = await connection.QueryAsync <AgentDto>(VehicleAgentQuery);

                    var maintananceQuery = string.Format(MaintenanceQuery, _vehicleValue.CODIINT);
                    MaintenanceDtos = await connection.QueryAsync <MaintainanceDto>(maintananceQuery);

                    var queryVehicle = string.Format(QueryModels, _vehicleValue.MODELO);
                    var models       = await connection.QueryAsync <MODELO>(queryVehicle);

                    ModelDtos = _vehicleMapper.Map <IEnumerable <MODELO>, IEnumerable <ModelVehicleDto> >(models);
                    Valid     = true;
                }
                catch (System.Exception e)
                {
                    string message = "Vehicle Loading error: " + e.Message;
                    throw new DataLayerExecutionException(message);
                }
            }
            stopwatch.Stop();
            // around 100 ms/ 90 ms just to load the vehicle.
            long value = stopwatch.ElapsedMilliseconds;

            return(true);
        }
예제 #2
0
        private static string CraftVehicleGroup(VehiclePoco poco)
        {
            var query = $"SELECT * from GRUPOS WHERE CODIGO='{poco.GRUPO}'";

            return(query);
        }