public static string EndFileUpload(string folderName, string fileName) { if (!Roles.IsUserInRole("family")) { return "Error: Current user is not allowed to upload pictures."; } string originalPicFile = Path.Combine( HttpContext.Current.Server.MapPath("~/pictures/original/" + folderName), fileName); try { File.Copy(GetTempFilePath(fileName), originalPicFile); } catch (IOException) { return "Error: file with same name already exists in this album."; } finally { File.Delete(GetTempFilePath(fileName)); } // Create and save web-sized image string webPicFile = HttpContext.Current.Server.MapPath(string.Format( "~/pictures/web/{0}/{1}", folderName, fileName)); ResizeImage(originalPicFile, webPicFile, 640); // Create and save thumbnail-sized image string thumbPicFile = HttpContext.Current.Server.MapPath(string.Format( "~/pictures/thumb/{0}/{1}", folderName, fileName)); ResizeImage(originalPicFile, thumbPicFile, 120); // Add picture to the database using (var db = new NietoYostenDbDataContext()) { var album = db.Albums.FirstOrDefault(x => x.FolderName == folderName); var picture = new Picture(); picture.AlbumId = album.Id; picture.FileName = fileName; picture.Title = fileName; db.Pictures.InsertOnSubmit(picture); db.SubmitChanges(); } return "Upload successful"; }
partial void DeletePicture(Picture instance);
partial void UpdatePicture(Picture instance);
partial void InsertPicture(Picture instance);
private void detach_Pictures(Picture entity) { this.SendPropertyChanging(); entity.Album = null; }
private void attach_Pictures(Picture entity) { this.SendPropertyChanging(); entity.Album = this; }