예제 #1
0
        public void ShouldAddReports()
        {
            using (var repo = new ReportRepository())
            {
                var reports = new List <Report>()
                {
                    new Report {
                        Location = new GeoLocation
                        {
                            Lat       = 45.712113f,
                            Long      = -121.527200f,
                            Address   = "301 15th Street, Hood River",
                            Narrative = "test"
                        },
                        Type = "Interaction"
                    },
                    new Report {
                        Location = new GeoLocation
                        {
                            Lat       = -45.708457f,
                            Long      = -121.514432f,
                            Address   = "Kaze Sushi, Hood River",
                            Narrative = "test"
                        },
                        Type = "Interaction"
                    },
                };
                foreach (var report in reports)
                {
                    repo.Add(report);
                }

                repo.Commit();
            }
        }
예제 #2
0
        public HttpResponseMessage PostReport([FromBody] ReportDTO reportDTO)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, reportDTO));
            }

            using (var repo = new ReportRepository())
            {
                var report = new Report
                {
                    Lat            = reportDTO.Location.Lat,
                    Long           = reportDTO.Location.Long,
                    Type           = "Interaction",
                    Address        = reportDTO.Location.Cross_Street,
                    Narrative      = reportDTO.Location.Narrative,
                    Mode           = reportDTO.Mode,
                    Description    = reportDTO.Description,
                    CreatedOn      = DateTime.Now,
                    Infrastructure = reportDTO.Infrastructure,
                    Collision      = reportDTO.Collision,
                    PropertyDamage = reportDTO.PropertyDamage,
                    Injury         = reportDTO.Injury,
                    CollisionModes = string.Join(",", reportDTO.Modes.Other)
                };

                repo.Add(report);
                repo.Commit();
                reportDTO.Id = report.Id;

                return(Request.CreateResponse(HttpStatusCode.OK, reportDTO));
            }
        }
예제 #3
0
        public HttpResponseMessage PostImageFile(int id)
        {
            if (HttpContext.Current.Request.Files.AllKeys.Any())
            {
                // Get the uploaded image from the Files collection
                var image = HttpContext.Current.Request.Files["image"];

                if (image != null)
                {
                    // Validate the uploaded image(optional)
                    var rand     = new Random();
                    var unique   = rand.Next(1000000).ToString();
                    var ext      = Path.GetExtension(image.FileName).ToLower();
                    var fileName = string.Format("{0}-{1}{2}", id, unique, ext);
                    if (ext == ".png" || ext == ".jpg")
                    {
                        // Get the complete file path
                        var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"), fileName);

                        // Save the uploaded file to "Images" folder
                        image.SaveAs(fileSavePath);

                        using (var repo = new ReportRepository())
                        {
                            var report = repo.Find(r => r.Id == id).FirstOrDefault();
                            if (report != null)
                            {
                                report.Image = fileName;
                                repo.Commit();
                                return(Request.CreateResponse(HttpStatusCode.Created));
                            }
                            else
                            {
                                // delete file
                                // report does not exist
                                return(Request.CreateResponse(HttpStatusCode.BadRequest));
                            }
                        }
                    }
                    else
                    {
                        // create err invalid file extension (jpg, png)
                        return(Request.CreateResponse(HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    // no image posted
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
            }
            else
            {
                // no image posted
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
예제 #4
0
        public HttpResponseMessage GetLoadData()
        {
            using (var repo = new ReportRepository())
            {
                var reports = new List <Report>()
                {
                    new Report {
                        Lat            = 47.608746f,
                        Long           = -122.336894f,
                        Address        = "301 15th Street, Hood River",
                        Narrative      = "test",
                        Mode           = "Bike",
                        Description    = "Doored on 2nd n seneca",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = false,
                        PropertyDamage = false,
                        Injury         = false,
                        CollisionModes = "",
                    },
                    new Report {
                        Lat            = 47.60731f,
                        Long           = -122.337066f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.606127f,
                        Long           = -122.337538f,
                        Address        = "Kaze Sushi",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = false,
                        Collision      = true,
                        PropertyDamage = false,
                        Injury         = true,
                        CollisionModes = "Car",
                    },
                    new Report {
                        Lat            = 47.606818f,
                        Long           = -122.333536f,
                        Address        = "Kaze Sushi/Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = false,
                        CollisionModes = "Walk",
                    },
                    new Report {
                        Lat            = 47.606561f,
                        Long           = -122.334115f,
                        Address        = "Kaze Sushi / Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Walk",
                    },
                    new Report {
                        Lat            = 47.606702f,
                        Long           = -122.334984f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.608297f,
                        Long           = -122.336454f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.609509f,
                        Long           = -122.338364f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.611639f,
                        Long           = -122.339523f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    }
                };
                foreach (var report in reports)
                {
                    repo.Add(report);
                }

                repo.Commit();
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }