Beispiel #1
0
        private static model.Driver randomicDriver()
        {
            model.Driver d = new model.Driver();

            string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            for (int i = 0; i < 3; i++)
            {
                d.Label += new string(Enumerable.Repeat(chars, 1).Select(s => s[new Random().Next(26)]).ToArray());
            }

            Random label = new Random();

            d.Label += label.Next(1000, 9999).ToString();

            Random randomColor = new Random();

            KnownColor[] names           = (KnownColor[])Enum.GetValues(typeof(KnownColor));
            KnownColor   randomColorName = names[randomColor.Next(names.Length)];

            d.Color = Color.FromKnownColor(randomColorName).Name;

            d.Supplier = "Ford";
            d.Model    = "Fiesta";

            return(d);
        }
Beispiel #2
0
        public static model.Driver CreateDriver(model.Driver driver)
        {
            model.Driver result = new model.Driver();
            result = GetDriver(driver);

            if (result.Id == 0)
            {
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

                parameters.Add(new KeyValuePair <string, object>("@Color", driver.Color));
                parameters.Add(new KeyValuePair <string, object>("@Label", driver.Label));
                parameters.Add(new KeyValuePair <string, object>("@Model", driver.Model));
                parameters.Add(new KeyValuePair <string, object>("@Supplier", driver.Supplier));

                try
                {
                    result.Id = (Int32)utils.DatabaseHelper.ExecuteNonQuery(
                        parameters,
                        "procDriver_Create",
                        new KeyValuePair <string, object>("@Id", driver.Id));

                    driver.Id = result.Id;
                    result    = driver;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(result);
        }
Beispiel #3
0
        public List <model.Driver> ListWorstDrivers()
        {
            List <model.Driver> result = new List <model.Driver>();

            try
            {
                IDataReader reader = utils.DatabaseHelper.ExecuteReader(new List <KeyValuePair <string, object> >(), "procDriverTop10Worst_Read");
                while (reader.Read())
                {
                    badDriverModel.Driver d = new badDriverModel.Driver()
                    {
                        Color            = reader["Color"].ToString(),
                        Id               = (int)reader["Id"],
                        Incidents        = new List <model.Incident>(),
                        Label            = reader["Label"].ToString(),
                        Model            = reader["Model"].ToString(),
                        Supplier         = reader["Supplier"].ToString(),
                        IncidentQuantity = (int)reader["quantity"]
                    };



                    result.Add(d);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
Beispiel #4
0
        public static bool UpdateDriver(model.Driver driverToBeUpdated)
        {
            bool result = false;

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

            parameters.Add(new KeyValuePair <string, object>("@Id", driverToBeUpdated.Id));
            parameters.Add(new KeyValuePair <string, object>("@Color", driverToBeUpdated.Color));
            parameters.Add(new KeyValuePair <string, object>("@Label", driverToBeUpdated.Label));
            parameters.Add(new KeyValuePair <string, object>("@Model", driverToBeUpdated.Model));
            parameters.Add(new KeyValuePair <string, object>("@Supplier", driverToBeUpdated.Supplier));

            try
            {
                utils.DatabaseHelper.ExecuteNonQuery(parameters, "procDriver_Update", null);
                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally { }

            return(result);
        }
Beispiel #5
0
        public static List <model.Driver> ListWorstDrivers()
        {
            List <model.Driver> result = new List <model.Driver>();

            foreach (var i in _apiService.ListWorstDrivers())
            {
                model.Driver d = new model.Driver();
                d.Id               = i.Id;
                d.Color            = i.Color;
                d.Label            = i.Label;
                d.Model            = i.Model;
                d.Supplier         = i.Supplier;
                d.IncidentQuantity = i.IncidentQuantity;

                result.Add(d);
            }

            return(result);
        }
Beispiel #6
0
        private static model.Driver GetDriver(model.Driver driver)

        {
            model.Driver result = new model.Driver();

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

            parameters.Add(new KeyValuePair <string, object>("@Color", driver.Color));
            parameters.Add(new KeyValuePair <string, object>("@Label", driver.Label));
            parameters.Add(new KeyValuePair <string, object>("@Model", driver.Model));
            parameters.Add(new KeyValuePair <string, object>("@Supplier", driver.Supplier));

            IDataReader reader = null;

            try
            {
                using (reader = utils.DatabaseHelper.ExecuteReader(parameters, "procDriver_Read"))
                {
                    if (reader.Read())
                    {
                        result.Id       = (int)reader["Id"];
                        result.Color    = reader["Color"].ToString();
                        result.Label    = reader["Label"].ToString();
                        result.Model    = reader["Model"].ToString();
                        result.Supplier = reader["Supplier"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (reader.IsClosed == false)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }

            return(result);
        }
Beispiel #7
0
        public static model.Driver GetDriverById(int id)
        {
            model.Driver result = new model.Driver();

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

            parameters.Add(new KeyValuePair <string, object>("@id", id));

            IDataReader reader = null;

            try
            {
                using (reader = utils.DatabaseHelper.ExecuteReader(parameters, "procDriverId_read"))
                {
                    if (reader.Read())
                    {
                        result.Id       = (int)reader["Id"];
                        result.Color    = reader["color"].ToString();
                        result.Label    = reader["label"].ToString();
                        result.Model    = reader["model"].ToString();
                        result.Supplier = reader["supplier"].ToString();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (reader.IsClosed == false)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }

            return(result);
        }
Beispiel #8
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();
        }
Beispiel #9
0
 public static bool UpdateDriver(model.Driver driverToBeUpdated)
 {
     return(domain.Driver.UpdateDriver(driverToBeUpdated));
 }
Beispiel #10
0
 public static model.Driver CreateDriver(model.Driver driver)
 {
     return(domain.Driver.CreateDriver(driver));
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }


            HtmlForm form = (HtmlForm)Master.FindControl("form1");

            form.Attributes.Add("class", "dropzone");

            if (IsPostBack)
            {
                model.Driver driver = new model.Driver();

                if (driver.Id == 0)
                {
                    driver.Color    = ColorDropdownlist.Text;
                    driver.Label    = LabelTextbox.Text;
                    driver.Model    = Request["ModelSelect"];
                    driver.Supplier = Request["SupplierSelect"];

                    driver.Incidents.Add(new model.Incident()
                    {
                        Latitude  = Request.Form["latitudeTextBox"].ToString(),
                        Longitude = Request.Form["longitudeTextBox"].ToString(),
                        DriverId  = driver.Id,
                        UserId    = (int)Session["UserId"]
                    });
                }

                int         i        = 0;
                string      savePath = string.Empty;
                string      saveFile = string.Empty;
                model.Photo p        = new model.Photo();

                foreach (var s in Request.Files.AllKeys)
                {
                    i++;
                    savePath = string.Empty;
                    saveFile = string.Empty;

                    HttpPostedFile file            = Request.Files[s];
                    int            fileSizeInBytes = file.ContentLength;
                    string         fileName        = file.FileName;
                    string         fileExtension   = string.Empty;

                    if (string.IsNullOrEmpty(fileName) == false)
                    {
                        fileExtension = Path.GetExtension(fileName);
                    }

                    savePath = Path.Combine(Request.PhysicalApplicationPath, dir, driver.Id.ToString());
                    saveFile = Path.Combine(savePath, i.ToString(), fileExtension);


                    file.SaveAs(saveFile);
                    p = new model.Photo()
                    {
                        IncidentId = driver.Incidents[0].Id,
                        Name       = fileName,
                        Url        = saveFile
                    };
                }

                driver.Incidents[0].Photos.Add(p);

                //driver = domain.Driver.CreateDriver(driver);
            }
        }