public static byte[] GetThumb(int requestId, int categoryID, int width, int height, long quality)
        {
            ImagesModel  image = ImagesFactor.GetRandomImage(requestId, categoryID, width, height);
            MemoryStream ms    = new MemoryStream(image.Data);

            byte[] imageContent = CreateThumb(ms, width, height, quality);
            //Image img = Image.FromStream(ms);
            return(imageContent);
        }
Exemple #2
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region --------------GetObject--------------
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the spesific record.
        /// </summary>
        /// <param name="ID">The model id.</param>
        /// <returns>Model object.</returns>
        //--------------------------------------------------------------------
        public static ImagesModel GetObject(int ImageID)
        {
            ImagesModel        ImagesObj = null;
            List <ImagesModel> list      = ImagesSqlDataPrvider.Instance.Get(ImageID);

            if (list != null && list.Count > 0)
            {
                ImagesObj = list[0];
            }
            return(ImagesObj);
        }
Exemple #3
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- Create ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the  object properties to SQL paramters and executes the create  procedure 
        /// and updates the object with the SQL data by reference.
        /// </summary>
        /// <param name="ImagesObj">Model object.</param>
        /// <returns>The result of create query.</returns>
        //--------------------------------------------------------------------
        public bool Create(ImagesModel ImagesObj)
        {
            bool result = false;
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("[dbo].[Images_Create]", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                //----------------------------------------------------------------------------------------------
                // Set the parameters
                //----------------------------------------------------------------------------------------------
				myCommand.Parameters.Add("@ImageID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
				myCommand.Parameters.Add("@CategoryID", SqlDbType.Int, 4).Value = ImagesObj.CategoryID;
				myCommand.Parameters.Add("@Name", SqlDbType.NVarChar, 128).Value = ImagesObj.Name;
				myCommand.Parameters.Add("@Path", SqlDbType.NVarChar, 512).Value = ImagesObj.Path;
				myCommand.Parameters.Add("@ImageWidth", SqlDbType.Int, 4).Value = ImagesObj.ImageWidth;
				myCommand.Parameters.Add("@ImageHeight", SqlDbType.Int, 4).Value = ImagesObj.ImageHeight;
				myCommand.Parameters.Add("@ImageSize", SqlDbType.Int, 4).Value = ImagesObj.ImageSize;
				myCommand.Parameters.Add("@ImageExtension", SqlDbType.VarChar, 5).Value = ImagesObj.ImageExtension;
				myCommand.Parameters.Add("@Data", SqlDbType.Image).Value = ImagesObj.Data;
				myCommand.Parameters.Add("@AppearingCount", SqlDbType.Int, 4).Value = ImagesObj.AppearingCount;
				myCommand.Parameters.Add("@Identifire", SqlDbType.VarChar, 128).Value = ImagesObj.Identifire;
				myCommand.Parameters.Add("@BlocKeys", SqlDbType.VarChar, 128).Value = ImagesObj.BlocKeys;

                //----------------------------------------------------------------------------------------------
                // Execute the command
                //----------------------------------------------------------------------------------------------
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    result = true;
                    //Get ID value from database and set it in object
				ImagesObj.ImageID = (int)myCommand.Parameters["@ImageID"].Value;

                }
                myConnection.Close();
                return result;
                //----------------------------------------------------------------------------------------------
            }
        }
Exemple #4
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region --------------Update--------------
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Updates model object by calling sql data provider update method.
        /// </summary>
        /// <param name="ImagesObj">The model object.</param>
        /// <returns>The result of update operation.</returns>
        //--------------------------------------------------------------------
        public static bool Update(ImagesModel ImagesObj)
        {
            return(ImagesSqlDataPrvider.Instance.Update(ImagesObj));
        }
Exemple #5
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- PopulateModelFromIDataReader ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Populates model from IDataReader .
        /// </summary>
        /// <param name="reader"></param>
        /// <returns>Model object.</returns>
        //--------------------------------------------------------------------
        private ImagesModel PopulateModelFromIDataReader(IDataReader reader)
        {
            //Create a new object
            ImagesModel ImagesObj = new ImagesModel();
            //Fill the object with data

			//------------------------------------------------
			//[ImageID]
			//------------------------------------------------
			if (reader["ImageID"] != DBNull.Value)
			    ImagesObj.ImageID = (int)reader["ImageID"];
			//------------------------------------------------
			//------------------------------------------------
			//[CategoryID]
			//------------------------------------------------
			if (reader["CategoryID"] != DBNull.Value)
			    ImagesObj.CategoryID = (int)reader["CategoryID"];
			//------------------------------------------------
			//------------------------------------------------
			//[Name]
			//------------------------------------------------
			if (reader["Name"] != DBNull.Value)
			    ImagesObj.Name = (string)reader["Name"];
			//------------------------------------------------
			//------------------------------------------------
			//[Path]
			//------------------------------------------------
			if (reader["Path"] != DBNull.Value)
			    ImagesObj.Path = (string)reader["Path"];
			//------------------------------------------------
			//------------------------------------------------
			//[ImageWidth]
			//------------------------------------------------
			if (reader["ImageWidth"] != DBNull.Value)
			    ImagesObj.ImageWidth = (int)reader["ImageWidth"];
			//------------------------------------------------
			//------------------------------------------------
			//[ImageHeight]
			//------------------------------------------------
			if (reader["ImageHeight"] != DBNull.Value)
			    ImagesObj.ImageHeight = (int)reader["ImageHeight"];
			//------------------------------------------------
			//------------------------------------------------
			//[ImageSize]
			//------------------------------------------------
			if (reader["ImageSize"] != DBNull.Value)
			    ImagesObj.ImageSize = (int)reader["ImageSize"];
			//------------------------------------------------
			//------------------------------------------------
			//[ImageExtension]
			//------------------------------------------------
			if (reader["ImageExtension"] != DBNull.Value)
			    ImagesObj.ImageExtension = (string)reader["ImageExtension"];
			//------------------------------------------------
			//------------------------------------------------
			//[Data]
			//------------------------------------------------
			if (reader["Data"] != DBNull.Value)
			    ImagesObj.Data = (byte[])reader["Data"];
			//------------------------------------------------
			//------------------------------------------------
			//[AppearingCount]
			//------------------------------------------------
			if (reader["AppearingCount"] != DBNull.Value)
			    ImagesObj.AppearingCount = (int)reader["AppearingCount"];
			//------------------------------------------------
			//------------------------------------------------
			//[Identifire]
			//------------------------------------------------
			if (reader["Identifire"] != DBNull.Value)
			    ImagesObj.Identifire = (string)reader["Identifire"];
			//------------------------------------------------
			//------------------------------------------------
			//[BlocKeys]
			//------------------------------------------------
			if (reader["BlocKeys"] != DBNull.Value)
			    ImagesObj.BlocKeys = (string)reader["BlocKeys"];
			//------------------------------------------------
            //Return the populated object
            return ImagesObj;
        }