Ejemplo n.º 1
0
        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";
        }
Ejemplo n.º 2
0
 partial void DeletePicture(Picture instance);
Ejemplo n.º 3
0
 partial void UpdatePicture(Picture instance);
Ejemplo n.º 4
0
 partial void InsertPicture(Picture instance);
Ejemplo n.º 5
0
		private void detach_Pictures(Picture entity)
		{
			this.SendPropertyChanging();
			entity.Album = null;
		}
Ejemplo n.º 6
0
		private void attach_Pictures(Picture entity)
		{
			this.SendPropertyChanging();
			entity.Album = this;
		}