You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.2 KiB
C#

using Common.Library.SQL.MySQL;
using System;
using System.Data;
4 years ago
using Common.Library.DataLayer.DTO.Websites.DMCDynamics.LLC;
using System.Collections.Generic;
4 years ago
using MySql.Data.MySqlClient;
4 years ago
namespace Common.Library.DataLayer.DAO.Websites.DMCDynamics.LLC
{
public class TestimonialsDAO : MySQL
{
public TestimonialsDAO(string server, string database, string username, string password) : base(server, database, username, password) { }
public TestimonialsDAO(DBConnectionInformation dBConnectionInformation) : base(dBConnectionInformation) { }
public TestimonialsDTOCollection SelectAll()
{
InitConnection();
try
{
4 years ago
TestimonialsDTOCollection items = new();
DBCommand.CommandType = CommandType.StoredProcedure;
DBCommand.CommandText = "Testimonials_SelectAll";
DBReader = DBCommand.ExecuteReader();
while (DBReader.Read())
{
4 years ago
TestimonialsDTO item = new()
{
TestimonialID = GetInt("TestimonialID").Value,
CompanyName = GetString("CompanyName"),
CompanySpokesPerson = GetString("CompanySpokesPerson"),
CompanyTitle = GetString("CompanyTitle"),
CompanyWebsite = GetString("CompanyWebsite"),
Testimonial = GetString("Testimonial")
};
items.Add(item);
}
4 years ago
return (items.Count == 0 ? null : items);
}
catch (Exception)
{
throw;
}
finally
{
DisposeConnection();
}
}
4 years ago
public int Insert(TestimonialsDTO testimonial)
{
InitConnection();
try
{
DBCommand.CommandType = CommandType.StoredProcedure;
DBCommand.CommandText = "Testimonials_Insert";
//> Add parameters
DBCommand.Parameters.Add(GetParameter("companyName", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanyName));
DBCommand.Parameters.Add(GetParameter("companySpokesPerson", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanySpokesPerson));
DBCommand.Parameters.Add(GetParameter("companyTitle", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanyTitle));
DBCommand.Parameters.Add(GetParameter("testimonialText", MySqlDbType.Text, 65535, ParameterDirection.Input, testimonial.Testimonial));
DBCommand.Parameters.Add(GetParameter("companyWebsite", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.CompanyWebsite));
DBCommand.Parameters.Add(GetParameter("testimonialGUID", MySqlDbType.VarChar, 255, ParameterDirection.Input, testimonial.TestimonialGUID));
DBCommand.Parameters.Add(GetParameter("testimonialID", MySqlDbType.Int32, 0, ParameterDirection.Output, testimonial.TestimonialID));
4 years ago
DBCommand.ExecuteNonQuery();
return (int)DBCommand.Parameters["TestimonialID"].Value;
}
catch(Exception)
{
throw;
}
finally
{
DisposeConnection();
}
}
//public void InsertImage(int testimonialID, KeyValuePair<string, byte[]> imageData)
//{
// 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);
// DBCommand.ExecuteNonQuery();
// }
// catch (Exception)
// {
// throw;
// }
// finally
// {
// DisposeConnection();
// }
//}
}
}