コード例 #1
0
ファイル: PhotoController.cs プロジェクト: jfbomber/kk
        public JsonResult Add(HttpPostedFileBase upload, bool storeRaw = false, string redirect = "")
        {
            Photo photo = new Photo(upload, storeRaw);
            photo.Save();

            Session["temp_image"] = photo;

            if (redirect.Length > 0)
            {
                Response.Redirect("~/Admin/Index");
            }
            return Json(photo);
        }
コード例 #2
0
ファイル: Photo.cs プロジェクト: jfbomber/kk
        /// <summary>
        /// Converts a posted http image to a C# System.Drawing.Image
        /// </summary>
        /// <param name="postedImage">HttpPostedFileBase</param>
        /// <returns>System.Drawing.Image</returns>
        public static List<Photo> GetAll()
        {
            List<Photo> photos = new List<Photo>();
            string query = @"SELECT photo_id, photo_name, photo_width, photo_height
                             FROM kk_photo
                             ORDER BY photo_id;";
            using (SqliteConnection conn = new SqliteConnection(connectionString))
            {
                conn.Open();
                // execute cmd
                using (SqliteCommand cmd = new SqliteCommand(query, conn))
                {

                    // user reader to fill data
                    using (SqliteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Photo photo = new Photo();
                            DBFill(reader, photo);
                            photos.Add(photo);
                        }
                    }

                }
            }
            return photos;
        }
コード例 #3
0
ファイル: Photo.cs プロジェクト: jfbomber/kk
        /// <summary>
        /// Gets a photo by id
        /// </summary>
        /// <param name="S">Integer</param>
        /// <returns>System.Drawing.Image</returns>
        public static Photo Get(int photoId, string[] columns = null)
        {
            if (columns == null || columns.Length == 0) {
                columns = new string[] { "photo_thumb" };
            }
            Photo photo = new Photo();
            string query = "SELECT photo_id, photo_name, photo_width, photo_height, " + string.Join(",", columns) + @"
                            FROM kk_photo
                            WHERE photo_id = @photo_id;";
            using (SqliteConnection conn = new SqliteConnection(connectionString))
            {
                conn.Open();
                // execute cmd
                using (SqliteCommand cmd = new SqliteCommand(query, conn))
                {
                    cmd.Parameters.Add("@photo_id", System.Data.DbType.Int32).Value = photoId;
                    // user reader to fill data
                    using (SqliteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {

                            Photo.DBFill(reader, photo, columns);
                        }

                    }

                }
            }
            return photo;
        }
コード例 #4
0
ファイル: Photo.cs プロジェクト: jfbomber/kk
 /// <summary>
 /// Converts a posted http image to a C# System.Drawing.Image
 /// </summary>
 /// <param name="postedImage">HttpPostedFileBase</param>
 /// <returns>System.Drawing.Image</returns>
 public static void DBFill(SqliteDataReader reader, Photo photo, string[] columns = null)
 {
     photo.PhotoID = Convert.ToInt32(reader["photo_id"]);
     photo.PhotoName = reader["photo_name"].ToString();
     photo.PhotoWidth = Convert.ToInt32(reader["photo_width"]);
     photo.PhotoHeight = Convert.ToInt32(reader["photo_height"]);
     if (columns != null)
     {
         for (int i = 0; i < columns.Length; i++)
         {
             string column = columns[i] as string;
             switch (column)
             {
                 case "photo_raw": photo.PhotoRawData = (byte[])reader["photo_raw"]; break;
                 case "photo_large": photo.PhotoRawData = (byte[])reader["photo_large"]; break;
                 case "photo_medium": photo.PhotoRawData = (byte[])reader["photo_medium"]; break;
                 case "photo_small": photo.PhotoRawData = (byte[])reader["photo_small"]; break;
                 case "photo_thumb": photo.PhotoRawData = (byte[])reader["photo_thumb"]; break;
                 default: break;
             }
         }
     }
 }
コード例 #5
0
ファイル: Project.cs プロジェクト: jfbomber/kk
        public string GetImageUrl(Photo.PhotoSize size)
        {
            if (this.ProjectImageID == 0) {
                return "";
            }

            Photo photo = Photo.Get (this.ProjectImageID);
            return photo.GetUrlBySize (size);
        }