Example #1
0
        public static int InsertIncident(model.Incident incident)
        {
            int result = 0;

            result = domain.Driver.InsertIncident(incident);

            return(result);
        }
Example #2
0
        public static int InsertIncident(model.Incident incident)
        {
            int result = 0;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>("@Latitude", incident.Latitude));
            parameters.Add(new KeyValuePair <string, object>("@Longitude", incident.Longitude));
            parameters.Add(new KeyValuePair <string, object>("@UserId", incident.UserId));
            parameters.Add(new KeyValuePair <string, object>("@DriverId", incident.DriverId));

            try
            {
                result = (int)utils.DatabaseHelper.ExecuteNonQuery(
                    parameters,
                    "procIncident_create",
                    new KeyValuePair <string, object>("@id", result));
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (incident.Photos.Count > 0)
            {
                foreach (var photo in incident.Photos)
                {
                    parameters.Clear();
                    parameters.Add(new KeyValuePair <string, object>("@Name", photo.Name));
                    parameters.Add(new KeyValuePair <string, object>("@Url", photo.Url));
                    parameters.Add(new KeyValuePair <string, object>("@IncidentId", result));

                    try
                    {
                        utils.DatabaseHelper.ExecuteNonQuery(parameters, "procPhoto_Create", new KeyValuePair <string, object>("@Id", photo.Id));
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }

            return(result);
        }
Example #3
0
        private static void testDriverFeatures()
        {
            // Create Driver
            model.Driver driverToBeCreated = new model.Driver()
            {
                Color    = "Black",
                Label    = "FOH5698",
                Model    = "Sentra",
                Supplier = "Nissan"
            };

            driverToBeCreated = service.Driver.CreateDriver(driverToBeCreated);

            // Get Driver
            model.Driver driverToBeGot = service.Driver.GetDriverById(1);

            // Update Driver
            model.Driver driverToBeUpdated = driverToBeGot;
            bool         driverUpdated     = false;

            Console.WriteLine("Driver Getted / To Be Updated Color [BEFORE CHANGE COLOR]: {0}", driverToBeUpdated.Color);
            driverToBeUpdated.Color = (driverToBeGot.Color == "Black") ? "White" : "Black";

            Console.WriteLine("Driver Getted / To Be Updated Color [AFTER CHANGE COLOR]: {0}", driverToBeUpdated.Color);
            driverUpdated = service.Driver.UpdateDriver(driverToBeUpdated);

            Console.WriteLine("Driver Updated: {0}", driverUpdated);

            driverToBeUpdated = service.Driver.GetDriverById(driverToBeUpdated.Id);
            Console.WriteLine("Driver new color: {0}", driverToBeUpdated.Color);


            // Insert incident for Driver
            model.Incident incident =
                new model.Incident()
            {
                Latitude  = "-23.6152779",
                Longitude = "-46.7043542",
                UserId    = id,
                DriverId  = driverToBeUpdated.Id,
                Photos    = new List <model.Photo>()
            };

            incident.Photos.Add(
                new badDriverModel.Photo()
            {
                Name = "badDriverSample01.jpg",
                Url  = @"\badDriverSample01.jpg",
            });

            incident.Photos.Add(
                new badDriverModel.Photo()
            {
                Name = "badDriverSample02.jpg",
                Url  = @"\badDriverSample02.jpg",
            });



            int incidentInserted = service.Driver.InsertIncident(incident);

            Console.WriteLine("Incident inserted id: {0}", incidentInserted);



            // Insert more than 1 incident for Driver
            Console.WriteLine("######################################");
            Console.WriteLine("Insert more than 1 incident for Driver");
            Random random     = new Random();
            int    randomNext = random.Next(3, 10);

            model.Driver newDriver = randomicDriver();

            newDriver = service.Driver.CreateDriver(newDriver);

            for (int i = 1; i <= randomNext; i++)
            {
                model.Incident inc = new model.Incident()
                {
                    Latitude  = "-23.6152779",
                    Longitude = "-46.7043542",
                    UserId    = id,
                    Photos    = new List <model.Photo>(),
                    DriverId  = newDriver.Id
                };

                inc.Photos.Add(
                    new badDriverModel.Photo()
                {
                    Name = "badDriverSample01.jpg",
                    Url  = @"\badDriverSample01.jpg",
                });

                inc.Photos.Add(
                    new badDriverModel.Photo()
                {
                    Name = "badDriverSample02.jpg",
                    Url  = @"\badDriverSample02.jpg",
                });

                incidentInserted = service.Driver.InsertIncident(inc);
                incident.Id      = incidentInserted;
                Console.WriteLine("{0} from {1} Incident(s) inserted(s) to driver id {2}, incident id: {3}", i, randomNext, newDriver.Id, incidentInserted);

                newDriver.Incidents.Add(incident);
            }


            // List Driver
            List <model.Driver> drivers = new List <model.Driver>();

            drivers = service.Driver.ListDrivers();

            // Path for photos
            List <model.Photo> photos = new List <model.Photo>();

            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory.Replace(@"bin\Debug", string.Empty));

            // List Driver Photos
            List <model.Photo> driverPhotos = new List <model.Photo>();

            foreach (var i in newDriver.Incidents)
            {
                Console.WriteLine("For Driver ID {0} we have {1} Incidents", driverToBeGot.Id, driverToBeGot.Incidents.Count());

                foreach (var p in i.Photos)
                {
                    Console.WriteLine("----- Photo ID {0}, URL {1} and Name {2}", p.Id, p.Url, p.Name);
                }
            }

            // List total Drivers
            Console.WriteLine("List total Drivers : {0}", service.Driver.ListDriversCount());

            // Listing worst drivers
            foreach (var d in service.Driver.ListWorstDrivers())
            {
                Console.WriteLine("Listing worst Drivers {0} - {1} {2}", d.Id, d.Label, d.Model);
            }

            Console.ReadKey();
        }