Idea of the project: if someone wants to order a project development, here you can send an application.
using ProjectRequestTest.Core.Enums;
using System;
using System.Data;
using System.Data.SqlClient;
using ProjectRequestTest.Core.DbContext;
namespace ProjectRequestTest.Core
{
public class ProjectRequestService : IProjectRequestService
{
public int Create(ProjectRequestItem item)
{
using (var conn = DataAccessService.SqlConn())
{
var cmd = new SqlCommand(DbSpName.ProjectRequestSave.ToName()) { CommandType = CommandType.StoredProcedure };
cmd.Parameters.Add("@Identifier", SqlDbType.Int).Value = item.Identifier;
cmd.Parameters.Add("@ClientName", SqlDbType.NVarChar).Value = item.ClientName;
cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = item.Email;
cmd.Parameters.Add("@PhoneNumber", SqlDbType.VarChar).Value = item.PhoneNumber;
cmd.Parameters.Add("@ProjectType", SqlDbType.VarChar).Value = item.ProjectType.ToString();
cmd.Parameters.Add("@Description", SqlDbType.NVarChar).Value = item.Description;
cmd.Parameters.Add("@UserIP", SqlDbType.VarChar).Value = Helpers.GetUserIP();
var resultParam = cmd.Parameters.Add("@NewItemID", SqlDbType.Int);
resultParam.Direction = ParameterDirection.Output;
DataAccessService.ExecuteSQL(cmd);
return Convert.ToInt32(resultParam.Value);
}
}
public ProjectRequestItem GetRequestByIdentifier(int identifier)
{
ProjectRequestItem result = null;
using (var conn = DataAccessService.SqlConn())
{
var cmd = new SqlCommand(DbSpName.ProjectRequestLoadByIdentifier.ToName(), conn) { CommandType = CommandType.StoredProcedure };
cmd.Parameters.Add("@Identifier", SqlDbType.Int).Value = identifier;
var sqlReader = cmd.ExecuteReader();
if (sqlReader.Read() && sqlReader[TableProjectRequest.ROWID.ToName()] != DBNull.Value)
{
result = new ProjectRequestItem();
result.Id = Convert.ToInt32(sqlReader[TableProjectRequest.ROWID.ToName()]);
result.Identifier = Convert.ToInt32(sqlReader[TableProjectRequest.ROWID.ToName()]);
if (sqlReader[TableProjectRequest.ClientName.ToName()] != DBNull.Value)
result.ClientName = sqlReader[TableProjectRequest.ClientName.ToName()].ToString();
if (sqlReader[TableProjectRequest.Email.ToName()] != DBNull.Value)
result.Email = sqlReader[TableProjectRequest.Email.ToName()].ToString();
if (sqlReader[TableProjectRequest.PhoneNumber.ToName()] != DBNull.Value)
result.PhoneNumber = sqlReader[TableProjectRequest.PhoneNumber.ToName()].ToString();
if (sqlReader[TableProjectRequest.ProjectType.ToName()] != DBNull.Value)
result.ProjectType = EnumHelper<ProjectType>.Parse(sqlReader[TableProjectRequest.ProjectType.ToName()].ToString());
if (sqlReader[TableProjectRequest.Description.ToName()] != DBNull.Value)
result.Description = sqlReader[TableProjectRequest.Description.ToName()].ToString();
if (sqlReader[TableProjectRequest.UserIP.ToName()] != DBNull.Value)
result.UserIP = sqlReader[TableProjectRequest.UserIP.ToName()].ToString();
if (sqlReader[TableProjectRequest.DateCreated.ToName()] != DBNull.Value)
result.DateCreated = Convert.ToDateTime(sqlReader[TableProjectRequest.DateCreated.ToName()]);
}
}
return result;
}
}
}