|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Common.Library.SQL.MySQL;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Common.Library.ImageHandling;
|
|
|
|
|
using Common.Library.Settings;
|
|
|
|
|
using MySql.Data.MySqlClient;
|
|
|
|
|
|
|
|
|
|
namespace Common.Library.Console.Image.Uploader
|
|
|
|
|
{
|
|
|
|
|
public class ImageUploader : MySQL
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly string _patoToImage;
|
|
|
|
|
|
|
|
|
|
public ImageUploader(string pathToImage) : base(SettingsLoader.DBHost, SettingsLoader.DBName, SettingsLoader.DBUserName, SettingsLoader.DBPassword)
|
|
|
|
|
{
|
|
|
|
|
_patoToImage = pathToImage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UploadImage(int testimonialID)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ImageHandler imageHandler = new ImageHandler();
|
|
|
|
|
|
|
|
|
|
KeyValuePair<string, byte[]> imageData = imageHandler.ConvertImageFromFile(_patoToImage);
|
|
|
|
|
|
|
|
|
|
InitConnection();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DBCommand.CommandType = CommandType.StoredProcedure;
|
|
|
|
|
DBCommand.CommandText = "Testimonial_Images_Insert";
|
|
|
|
|
|
|
|
|
|
DBCommand.Parameters.AddWithValue("@testimonialID", testimonialID);
|
|
|
|
|
DBCommand.Parameters.AddWithValue("@imageType", imageData.Key);
|
|
|
|
|
//DBCommand.Parameters.AddWithValue("@imageData", imageData.Value);
|
|
|
|
|
MySqlParameter image = new MySqlParameter("@imageData", MySqlDbType.MediumBlob, imageData.Value.Length);
|
|
|
|
|
image.Value = imageData.Value;
|
|
|
|
|
DBCommand.Parameters.Add(image);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DBCommand.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
DisposeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|