public ActionResult NewDetail(int id) { ViewBag.ActiveIndex = 3; var item = _ns.GetById(id); IndexVM ivm = new IndexVM(); if (item != null) { _ias.Initialize(ServerPath); File_t file = null; if (item.AlbumId.HasValue) { file = _ias.GetAlbumById(item.AlbumId.Value, false).File_t.Where(f => f.IsOnTopAlbum).FirstOrDefault(); } ivm.AlbumId = item.AlbumId; ivm.Id = item.Id; ivm.IssueDate = item.IssueDate; ivm.FilePath = file != null ? file.ThumPath : "null"; ivm.Text = item.Text; ivm.Title = item.Title; ivm.Location = item.Location; } return(View(ivm)); }
public static void SaveImageToDirectory(byte[] image, File_t file) { using (var s = new MemoryStream(image)) { SaveImageToDirectory(s, file); } }
public ActionResult UploadFile() { HttpPostedFileBase myFile = Request.Files[0]; bool isok = false; string message = "File upload failed"; string thumurl = ""; string pvresult = null; File_t file = null; if (myFile != null && myFile.ContentLength != 0) { try { _ias.Initialize(ServerPath); file = _ias.UploadImage(CurrentUserID.Value, SessionData.Current.AlbumId.Value, myFile.FileName, myFile.InputStream); isok = true; message = "File uploaded successfully!"; pvresult = RenderPartialViewToString("_ContentContainerPartial", file); } catch (Exception ex) { message = string.Format("File upload failed: {0}", ex.Message); } } return(Json(new { isok = isok, message = message, imageid = file != null ? file.Id : 0, thumurl = thumurl, content = pvresult }, "text/html")); }
private IndexVM GetIndexVm(int eventCount = int.MaxValue, int newCount = int.MaxValue) { IndexVM ivm = new IndexVM(); _ias.Initialize(ServerPath); //news var news = _ns.GetAll().Take(newCount); foreach (var item in news) { File_t file = null; if (item.AlbumId.HasValue) { file = _ias.GetAlbumById(item.AlbumId.Value, false).File_t.Where(f => f.IsOnTopAlbum).FirstOrDefault(); } ivm.NewVMCollection.Add( new IndexVM() { AlbumId = item.AlbumId, Id = item.Id, IssueDate = item.IssueDate, FilePath = file != null ? file.NewThumPath : "null", Text = item.Text, Title = item.Title, Location = item.Location }); } //events var events = _es.GetAll().Where(e => e.IssueDate >= DateTime.Now).Take(eventCount); var album = _ias.GetEventAlbum(); foreach (var item in events) { File_t file = null; if (item.FileId.HasValue) { file = album.File_t.Where(f => f.Id == item.FileId.Value).FirstOrDefault(); } ivm.EventVMCollection.Add(new IndexVM() { Id = item.Id, IssueDate = item.IssueDate, FilePath = file != null ? file.NEWTHUM_FILE : "null", Text = item.Text, Title = item.Title, Location = item.Location }); } return(ivm); }
public static void SaveImageToDirectory(Stream s, File_t file) { //JpegBitmapDecoder decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); //BitmapSource bitmapSource = decoder.Frames[0]; //System.Windows.Controls.Image myImage = new System.Windows.Controls.Image(); //myImage.Source = bitmapSource; using (var img = Image.FromStream(s, true, false)) { try { if (!CreateFolderIfNeeded(file.STAND_FILE)) { throw new Exception("not possible to create folder"); } if (!File.Exists(file.STAND_FILE)) { using (var imagStand = PictureHelper.Thumbnail(1200, 1200, img, false)) { imagStand.Save(file.STAND_FILE, System.Drawing.Imaging.ImageFormat.Jpeg); } } if (!File.Exists(file.THUM_FILE)) { using (var imagSmall = PictureHelper.Thumbnail(560, 310, img, true)) { imagSmall.Save(file.THUM_FILE, System.Drawing.Imaging.ImageFormat.Jpeg); } } if (!File.Exists(file.NEWTHUM_FILE)) { using (var imagSmall = PictureHelper.Thumbnail(100, 100, img, true)) { imagSmall.Save(file.NEWTHUM_FILE, System.Drawing.Imaging.ImageFormat.Jpeg); } } } catch (Exception ex) { } } }
public File_t UploadImage(int userId, int albumId, string fileName, Stream s) { File_t file = null; using (MemoryStream ms = new MemoryStream()) { s.CopyTo(ms); s.Position = 0; var fileId = SaveFileInAlbum(userId, albumId, fileName, ms.ToArray()); if (fileId > 0) { file = _fr.GetById(fileId); file.InitialisePaths(_serverPath); PictureHelper.SaveImageToDirectory(s, file); } s.Close(); } return(file); }
public ActionResult EventDetail(int id) { ViewBag.ActiveIndex = 4; var item = _es.GetById(id); IndexVM ivm = new IndexVM(); if (item != null) { var album = _ias.GetEventAlbum(); File_t file = null; if (item.FileId.HasValue) { file = album.File_t.Where(f => f.Id == item.FileId.Value).FirstOrDefault(); } ivm.Id = item.Id; ivm.IssueDate = item.IssueDate; ivm.FilePath = file != null ? file.THUM_FILE : "null"; ivm.Text = item.Text; ivm.Title = item.Title; ivm.Location = item.Location; } return(View(ivm)); }
public static bool CheckFiles(File_t file) { return(File.Exists(file.THUM_FILE) && File.Exists(file.NEWTHUM_FILE) && File.Exists(file.STAND_FILE)); }