예제 #1
0
        public ActionResult CreateReport(HttpPostedFileBase file, Report model, String PhotoDataChoice)
        {
            file = Request.Files[0];

            var photoId = Guid.NewGuid();
            var photoUrl = photoId.ToString() + "." + file.FileName.Split('.')[1];
            var reportId = Guid.NewGuid();

            /** Set up report in DB **/
            var db = new ChwinockEntities();

            model.ReportID = reportId;
            model.CreateDate = DateTime.UtcNow;
            model.Content = model.Content.Replace("\n", "<br />");

            // Set up photo
            model.Photo.Url = photoUrl;
            model.Photo.PhotoID = photoId;
            model.Photo.ReportID = reportId;

            // Get extra data
            if (PhotoDataChoice == "Metadata")
            {
                model = Common.Utilities.GetPhotoMetadata(model, file);
            }
            else
            {
                model = Common.Utilities.GetPhotoLocation(model);
            }

            db.Photos.AddObject(model.Photo);

            Common.Utilities.UploadPhoto(file, photoUrl);

            // Connect report to photo
            model.PhotoID = photoId;

            db.Reports.AddObject(model);

            //Save everything in DB
            db.SaveChanges();

            return RedirectToAction("Manage");
        }
예제 #2
0
        public static Report GetPhotoMetadata(Report model, HttpPostedFileBase file)
        {
            dynamic metadata = MetaDataFor(file);
            model.Photo.CreateDate = metadata.date;
            model.Photo.Lat = metadata.lat;
            model.Photo.Lng = metadata.lng;

            return model;
        }
예제 #3
0
        public static Report GetPhotoLocation(Report model)
        {
            dynamic loc_data = Common.Utilities.GetLatLngFor(model.Photo.Location);
            model.Photo.CreateDate = DateTime.UtcNow;
            model.Photo.Lat = loc_data.lat;
            model.Photo.Lng = loc_data.lng;

            return model;
        }
예제 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Reports EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToReports(Report report)
 {
     base.AddObject("Reports", report);
 }
예제 #5
0
 /// <summary>
 /// Create a new Report object.
 /// </summary>
 /// <param name="reportID">Initial value of the ReportID property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="author">Initial value of the Author property.</param>
 /// <param name="content">Initial value of the Content property.</param>
 /// <param name="photoID">Initial value of the PhotoID property.</param>
 /// <param name="createDate">Initial value of the CreateDate property.</param>
 public static Report CreateReport(global::System.Guid reportID, global::System.String title, global::System.String author, global::System.String content, global::System.Guid photoID, global::System.DateTime createDate)
 {
     Report report = new Report();
     report.ReportID = reportID;
     report.Title = title;
     report.Author = author;
     report.Content = content;
     report.PhotoID = photoID;
     report.CreateDate = createDate;
     return report;
 }
예제 #6
0
        public ActionResult EditReport(Report model, String PhotoDataChoice)
        {
            var db = new ChwinockEntities();

            var targetReport = db.Reports.Single(r => r.ReportID == model.ReportID);

            // If a file was added, change the photos
            if (Request.Files[0].ContentLength > 0)
            {
                // Delete old photo blob
                //Common.Utilities.DeletePhotoBlob(targetReport.PhotoID);

                // Add new photo blob
                HttpPostedFileBase file = Request.Files[0];
                var photoUrl = targetReport.PhotoID.ToString() + "." + file.FileName.Split('.')[1];

                Common.Utilities.UploadPhoto(file, photoUrl);

                // Change the db entry, we change the URL in case the
                // extension of the image has changed, but the actual
                // Guid remains the same
                targetReport.Photo.Url = photoUrl;

                // Get extra data
                if (PhotoDataChoice == "Metadata")
                {
                    targetReport = Common.Utilities.GetPhotoMetadata(model, file);
                }
                else
                {
                    targetReport = Common.Utilities.GetPhotoLocation(model);
                }

            }

            // Change other photo attributes
            targetReport.Photo.Title = model.Photo.Title;
            targetReport.Photo.Caption = model.Photo.Caption;
            targetReport.Photo.Location = model.Photo.Location;

            // Change report properties
            targetReport.Title = model.Title;
            targetReport.Author = model.Author;

            // Convert formatting
            model.Content = model.Content.Replace("\n", "<br />");
            targetReport.Content = model.Content;

            db.SaveChanges();

            return RedirectToAction("Manage");
        }