Exemplo n.º 1
0
        public ActionResult GetImageGPS(string Id)
        {
            using (Image_context db = new Image_context())
            {
                int id = Int32.Parse(Id);
                Image_base img = db.Images.SingleOrDefault(f => f.Id == id);
                StringBuilder sb = new StringBuilder();
                try
                {

                    using (var reader = new ExifReader(img.url))
                    {
                        object val;
                        reader.GetTagValue(ExifTags.GPSLatitudeRef, out val);
                        string gps = RenderTag(val);
                        reader.GetTagValue(ExifTags.GPSLatitude, out val);
                        gps = gps + " " + RenderTag(val);
                        reader.GetTagValue(ExifTags.GPSLongitudeRef, out val);
                        gps = gps + " " + RenderTag(val);
                        reader.GetTagValue(ExifTags.GPSLongitude, out val);
                        gps = gps + " " + RenderTag(val);
                        Response.Write(gps);
                    }
                }
                catch (Exception ex)
                {
                    var error = ex.Message.ToString();
                    Response.Write(null);
                }
            }
            return null;
        }
Exemplo n.º 2
0
 //
 // GET: /Home/
 public ActionResult Index()
 {
     using (Image_context db = new Image_context())
     {
         IEnumerable<int> guids = db.Images.Select(img => img.Id).ToList();
         return View(guids);
     }
 }
Exemplo n.º 3
0
        public ActionResult GetImageInfo(string Id)
        {
            using (Image_context db = new Image_context())
            {
                int id = Int32.Parse(Id);
                Image_base img = db.Images.SingleOrDefault(f => f.Id == id);
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("<h2>IMAGE INFO FROM DATABASE</h2>");
                sb.AppendFormat("<p>Load Date: {0}</p>", img.load_date);
                sb.AppendFormat("<p>Change Date: {0}</p>", img.change_date);
                try
                {
                    using (var reader = new ExifReader(img.url))
                    {
                        // Parse through all available fields and generate key-value labels
                        var props = Enum.GetValues(typeof(ExifTags)).Cast<ushort>().Select(tagID =>
                        {
                            object val;
                            if (reader.GetTagValue(tagID, out val))
                            {
                                // Special case - some doubles are encoded as TIFF rationals. These
                                // items can be retrieved as 2 element arrays of {numerator, denominator}
                                if (val is double)
                                {
                                    int[] rational;
                                    if (reader.GetTagValue(tagID, out rational))
                                        val = string.Format("{0} ({1}/{2})", val, rational[0], rational[1]);
                                }

                                return string.Format("<p>{0}: {1}</p>", Enum.GetName(typeof(ExifTags), tagID), RenderTag(val));
                            }

                            return null;

                        }).Where(x => x != null).ToArray();
                         var exifdata = string.Join("\r\n", props);
                         sb.AppendFormat("<h2>EXIF FROM IMAGE</h2>");
                         sb.AppendFormat("<p>{0}</p>", exifdata);
                    }
                }
                catch (Exception ex)
                {
                    // Something didn't work!
                    sb.AppendFormat("<h2>EXIF FROM IMAGE</h2>");
                    sb.AppendFormat("<p>{0}</p>", ex.Message.ToString());
                }
                Response.Write(sb.ToString());
                return null;

            }
        }
Exemplo n.º 4
0
 public FileContentResult viewimage(int id)
 {
     using (Image_context db = new Image_context())
     {
         Image_base img = db.Images.SingleOrDefault(f => f.Id == id);
         FileStream file = new FileStream(img.url, FileMode.Open, FileAccess.Read);
         MemoryStream ms = new MemoryStream();
         file.CopyTo(ms);
         file.Close();
         return File(ms.GetBuffer(), img.imgtype);
     }
 }
Exemplo n.º 5
0
 public ActionResult UploadImage(HttpPostedFileBase[] files)
 {
     if (files[0]!=null)
     {
         foreach (var file in files)
         {
             using (Image_context db = new Image_context())
             {
                 MemoryStream ms = new MemoryStream();
                 file.InputStream.CopyTo(ms);
                 Image_base image = new Image_base
                 {
                     url = ServerPath + "\\images\\" + file.FileName,
                     user_description = null,
                     load_date = DateTime.Now.ToString(),
                     change_date = DateTime.Now.ToString(),
                     imgtype = file.ContentType
                 };
                 db.Images.Add(image);
                 db.SaveChanges();
                 System.IO.Directory.CreateDirectory(ServerPath + "\\images\\");
                 string path =ServerPath + "\\images\\" + file.FileName;
                 FileStream newfile = new FileStream(path, FileMode.Create, FileAccess.Write);
                 ms.WriteTo(newfile);
                 newfile.Close();
                 Response.Write(true);
             }
         }
     }
     return RedirectToAction("Index", "Home");
 }
Exemplo n.º 6
0
 public ActionResult RemoveImage(string Id)
 {
     using (Image_context db = new Image_context())
     {
         int id = Int32.Parse(Id);
         Image_base image = db.Images.SingleOrDefault(f => f.Id == id);
         string url = image.url;
         var img = new Image_base { Id = id };
         if (System.IO.File.Exists(url))
             System.IO.File.Delete(url);
         db.Images.Attach(image);
         db.Images.Remove(image);
         db.SaveChanges();
     }
     return RedirectToAction("Index", "Home");
 }
Exemplo n.º 7
0
 public ActionResult GetSetComments(user_request request)
 {
     using (Image_context db = new Image_context())
     {
         int id = Int32.Parse(request.Id);
         Image_base img = db.Images.SingleOrDefault(f => f.Id == id);
         StringBuilder sb = new StringBuilder();
         if (request.Text == null)
         {
             if (img.user_description != null)
             {
                 sb.AppendFormat("<li class=\"editable\" data-value=\"{0}\"> {1} </li>", id, img.user_description);
                 Response.Write(sb.ToString());
             }
             else
             {
                 sb.AppendFormat("<li class=\"editable\" data-value=\"{0}\"> No Comments </li>", id);
                 Response.Write(sb.ToString());
             }
         }
         else
         {
             img.user_description = request.Text;
             img.change_date = DateTime.Now.ToString();
             var original = db.Images.Find(img.Id);
             if (original != null)
             {
                 original.change_date = img.change_date;
                 original.user_description = img.user_description;
                 db.SaveChanges();
             }
         }
         return null;
     }
 }