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