Ejemplo n.º 1
0
        public Driver SaveDriver(Driver driver)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("name", driver.Name);
                parameters.Add("surname", driver.Surname);
                parameters.Add("dni", driver.Dni);
                parameters.Add("address", driver.Address);
                parameters.Add("loginCode", driver.LoginCode);
                parameters.Add("licenseNumber", driver.LicenseNumber);
                parameters.Add("licenseCategory", driver.LicenseCategory);
                parameters.Add("status", driver.Status);
                parameters.Add("driverId", 0);

                connection.ExecuteScalar("sp_add_driver", param: parameters,
                                         commandType: CommandType.StoredProcedure);

                var driverId = parameters.Get <Int32>("driverId");

                driver.Id = driverId;

                return(driver);
            }
        }
Ejemplo n.º 2
0
 public IEnumerable <Driver> GetAllDrivers()
 {
     using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
     {
         connection.Open();
         var drivers = connection.Query <Driver>("sp_all_drivers", commandType: CommandType.StoredProcedure);
         return(drivers);
     }
 }
Ejemplo n.º 3
0
 public IEnumerable <Incidence> GetAllIncidences()
 {
     using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
     {
         connection.Open();
         var incidences = connection.Query <Incidence>("sp_all_incidences", commandType: CommandType.StoredProcedure);
         return(incidences);
     }
 }
Ejemplo n.º 4
0
        public Driver GetDriverByLoginCode(string loginCode)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("loginCode", loginCode);

                var driver = connection.QuerySingle <Driver>("sp_login_driver", param: parameters, commandType: CommandType.StoredProcedure);
                return(driver);
            }
        }
Ejemplo n.º 5
0
        public Driver GetDriver(int driverId)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("driverId", driverId);

                var driver = connection.QuerySingle <Driver>("sp_find_driver_id", param: parameters, commandType: CommandType.StoredProcedure);
                return(driver);
            }
        }
Ejemplo n.º 6
0
        public Incidence GetIncidence(int incidenceId)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("incidenceId", incidenceId);

                var driver = connection.QuerySingle <Incidence>("sp_find_incidence_id", commandType: CommandType.StoredProcedure);
                return(driver);
            }
        }
Ejemplo n.º 7
0
        public IEnumerable <Incidence> GetIncidenceByCode(int orderId)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("orderId", orderId);

                var incidences = connection.Query <Incidence>("sp_find_incidences_order", param: parameters, commandType: CommandType.StoredProcedure);
                return(incidences);
            }
        }
Ejemplo n.º 8
0
        public bool DeleteDriver(int driverId)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("driverId", driverId);

                var result = connection.Execute("sp_delete_driver", param: parameters,
                                                commandType: CommandType.StoredProcedure);
                return(result > 0);
            }
        }
Ejemplo n.º 9
0
        public Incidence UpdateIncidence(Incidence incidence)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("incidenceId", incidence.Id);
                parameters.Add("date", incidence.Date);
                parameters.Add("latitude", incidence.Latitude);
                parameters.Add("longitude", incidence.Longitude);
                parameters.Add("message", incidence.Message);
                parameters.Add("orderId", incidence.OrderId);

                var result = connection.Execute("sp_update_incidence", param: parameters,
                                                commandType: CommandType.StoredProcedure);
                return(result > 0 ? incidence : new Incidence());
            }
        }
Ejemplo n.º 10
0
        public Driver UpdateDriver(Driver driver)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("driverId", driver.Id);
                parameters.Add("name", driver.Name);
                parameters.Add("surname", driver.Surname);
                parameters.Add("dni", driver.Dni);
                parameters.Add("address", driver.Address);
                parameters.Add("loginCode", driver.LoginCode);
                parameters.Add("licenseNumber", driver.LicenseNumber);
                parameters.Add("licenseCategory", driver.LicenseCategory);
                parameters.Add("status", driver.Status);

                var result = connection.Execute("sp_update_driver", param: parameters,
                                                commandType: CommandType.StoredProcedure);
                return(result > 0 ? driver : new Driver());
            }
        }
Ejemplo n.º 11
0
        public Incidence SaveIncidence(Incidence incidence)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("date", incidence.Date);
                parameters.Add("latitude", incidence.Latitude);
                parameters.Add("longitude", incidence.Longitude);
                parameters.Add("message", incidence.Message);
                parameters.Add("orderId", incidence.OrderId);
                parameters.Add("incidenceId", 0);

                connection.ExecuteScalar("sp_add_incidence", param: parameters,
                                         commandType: CommandType.StoredProcedure);

                var incidenceId = parameters.Get <Int32>("incidenceId");

                incidence.Id = incidenceId;

                return(incidence);
            }
        }