public IActionResult Index() { var model = new FrontPageModel(); model.NewPhotos = _dataContext.Photos.Cast <MediaItem>().ToList(); model.PopularPhotos = _dataContext.Photos.Cast <MediaItem>().ToList(); var path = _galleryContext.GetFolderPath(8, "lill.jpg"); return(View(model)); }
public bool Execute(EditFolderModel model) { var parentPath = ""; var folder = new MediaFolder(); folder.Title = model.Title; if (model.parentFolderId.HasValue) { var parentFolder = _dataContext.Folders.FirstOrDefault(f => f.Id == model.parentFolderId); folder.ParentFolder = parentFolder; parentFolder.Items.Add(folder); parentPath = _galleryContext.GetFolderPath(model.parentFolderId.Value, null); } _dataContext.Items.Add(folder); _dataContext.SaveChanges(); var path = Path.Combine(_host.WebRootPath, "gallery", parentPath, folder.Title); Directory.CreateDirectory(path); return(true); }
public void GetFile(int id) { var item = _dataContext.Photos .Include(p => p.ParentFolder) .FirstOrDefault(i => i.Id == id); var folder = item.ParentFolder; var path = item.FileName; if (folder != null) { path = _galleryContext.GetFolderPath(folder.Id, item.FileName); } Response.Clear(); Response.Headers.Add("Content-Disposition", "attachment;filename=" + item.FileName); try { using (var fileStream = _fileClient.GetFile(path)) { fileStream.CopyTo(Response.Body); } } catch (Exception ex) { _logger.LogError(ex, ""); } }
private string GetParentPath(EditFolderModel model) { var parentPath = ""; if (model.parentFolderId.HasValue) { var parentFolder = _dataContext.Folders.FirstOrDefault(f => f.Id == model.parentFolderId); parentPath = _galleryContext.GetFolderPath(model.parentFolderId.Value, null); } return(parentPath); }
public bool Execute(PhotoEditModel model) { var parentPath = ""; MediaFolder folder = null; if (model.ParentFolderId.HasValue) { folder = _dataContext.Folders.First(f => f.Id == model.ParentFolderId.Value); parentPath = _context.GetFolderPath(model.ParentFolderId.Value, null); } //var fileName = Path.GetFileName(model.FileName); //var filePath = Path.Combine(_host.WebRootPath, "gallery", parentPath, fileName); _fileClient.UploadPhoto(Path.Combine(parentPath, model.FileName), model.File.OpenReadStream()); return(true); }
public bool Execute(PhotoEditModel model) { var parentPath = ""; MediaFolder folder = null; if (model.ParentFolderId.HasValue) { folder = _dataContext.Folders.First(f => f.Id == model.ParentFolderId.Value); parentPath = _context.GetFolderPath(model.ParentFolderId.Value, null); } var fileName = Path.GetFileName(model.FileName); var filePath = Path.Combine(_host.WebRootPath, "gallery", parentPath, fileName); using (var localFile = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write)) { model.File.CopyTo(localFile); } return(true); }
//public GetFileWithEffectsCommand() //{ //} public bool Execute(PicWithEffectModel model) { var item = _dataContext.Items .Include(p => p.ParentFolder) .FirstOrDefault(i => i.Id == model.Id); var fileItem = (Photo)item; var folder = fileItem.ParentFolder; var path = fileItem.FileName; if (folder != null) { path = _galleryContext.GetFolderPath(folder.Id, fileItem.FileName); } var fileName = fileItem.FileName; var effect = model.Effect; try { IImageFormat format; using (var fileStream = _fileClient.GetFile(path)) using (var image = Image.Load(fileStream, out format)) { Image <Rgba32> imageWithEffect; if (effect == "BlackWhite") { imageWithEffect = image.Clone(ctx => ctx.BlackWhite()); } else if (effect == "OilPaint") { imageWithEffect = image.Clone(ctx => ctx.OilPaint()); } else if (effect == "Sepia") { imageWithEffect = image.Clone(ctx => ctx.Sepia()); } else if (effect == "Blur") { imageWithEffect = image.Clone(ctx => ctx.GaussianBlur()); } else if (effect == "Sharpen") { imageWithEffect = image.Clone(ctx => ctx.GaussianSharpen()); } else if (effect == "Glow") { imageWithEffect = image.Clone(ctx => ctx.Glow()); } else if (effect == "Invert") { imageWithEffect = image.Clone(ctx => ctx.Invert()); } else { imageWithEffect = image; } imageWithEffect.Save(model.outStream, format); } } catch (Exception ex) { _logger.LogError(ex, ""); } return(true); }