namespace VECV_WebApi.Models.FeedBack
{
#region Namespaces
using DBHelper;
using LoggingHelper;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using VECV_WebApi.Models.Authorization;
#endregion
#region Repository Class
///
/// This class contain feed back releted methods
///
public class FeedBackRepository
{
#region Global Variables
///
/// making object of LoggingUtility class available to this class
///
LoggingUtility objLog = new LoggingUtility();
///
/// making the data-log file path available to this class
///
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
///
/// making error log file path available to this class
///
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
///
/// making the Database connection string available to this class
///
private string _connStr;
///
/// making Authentication Repository object available to this class
///
AuthenticationRepository objAuthorization;
#endregion
#region Contructors
///
/// Default constructor intialize connection string of tracking database
///
public FeedBackRepository(string connString)
{
this._connStr = connString;
}
#endregion
#region API Methods
///
/// To insert feedback detail of ticket
///
/// feddback details
/// Status
public FeedBackModel InsertFeedBackForTicket(FeedBackModel model)
{
FeedBackModel objModel = new FeedBackModel();
try
{
objAuthorization = new AuthenticationRepository();
if (objAuthorization.AuthenticateDevice(model.Token))
{
if ((String.IsNullOrEmpty(model.ReasonMoreThan24Hrs)) || (model.ReasonMoreThan24Hrs == "null"))
{
// Creating Feedback Activity
NpgsqlParameter[] nSqlParam1 = new NpgsqlParameter[5];
nSqlParam1[0] = new NpgsqlParameter("inticket_id", model.TicketId);
nSqlParam1[1] = new NpgsqlParameter("increated_by", model.FeedBackagent);
nSqlParam1[2] = new NpgsqlParameter("increation_time", DateTime.Now.AddMinutes(-model.UtcMinute).ToString(ConfigurationManager.AppSettings["DateTimeFormat"]));
nSqlParam1[3] = new NpgsqlParameter("incall_status", model.CallStatus);
nSqlParam1[4] = new NpgsqlParameter("inremarks", model.OtherRemark);
NpgSqlHelper.ExecuteNonQuery(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_insert_tickets_closed_feedback_activity"], nSqlParam1);
}
// Inserting feedback into additional info
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[14];
nSqlParam[0] = new NpgsqlParameter("inticket_id ", model.TicketId);
nSqlParam[1] = new NpgsqlParameter("inreason_for_more_then_24hours ", model.ReasonMoreThan24Hrs);
nSqlParam[2] = new NpgsqlParameter("incall_status ", model.CallStatus);
nSqlParam[3] = new NpgsqlParameter("insuggestion_complaint ", model.SuggestionComplaint);
nSqlParam[4] = new NpgsqlParameter("infeedback_ease_of_getting_call ", model.FeedBackEaseOfGettingCall);
nSqlParam[5] = new NpgsqlParameter("infeedback_response_of_call_center ", model.FeedBackResponseOfCallCenter);
nSqlParam[6] = new NpgsqlParameter("infeedback_timely_updation_by_dealer ", model.FeedBackTimelyUpdationByDealer);
nSqlParam[7] = new NpgsqlParameter("infeedback_total_repair_time ", model.FeedBackTotalRepairTime);
nSqlParam[8] = new NpgsqlParameter("infeedback_eos_charges ", model.FeedBackEosCharges);
nSqlParam[9] = new NpgsqlParameter("infeedback_over_all_experience ", model.FeedBackOverAllExperience);
nSqlParam[10] = new NpgsqlParameter("inother_remarks ", model.OtherRemark);
nSqlParam[11] = new NpgsqlParameter("infeedback_agent ", model.FeedBackagent);
nSqlParam[12] = new NpgsqlParameter("increation_time ", Convert.ToDateTime(model.CreationTime).AddMinutes(-model.UtcMinute));
nSqlParam[13] = new NpgsqlParameter("incomplaints ", model.Complaint);
NpgSqlHelper.ExecuteNonQuery(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_insert_feeback"], nSqlParam);
objModel.Status = "1";
}
else
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
}
return objModel;
}
catch (Exception Ex)
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + " " + Ex.Message;
objLog.ErrorLogFile("InsertFeedBackForTicket", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To get ticket feedback and other detail
///
/// ticket info
/// ticket feedback and other detail
public FeedBackModel GetTicketFeedBackAndOtherInfo(FeedBackModel model)
{
FeedBackModel objModel = new FeedBackModel();
try
{
objAuthorization = new AuthenticationRepository();
if (objAuthorization.AuthenticateDevice(model.Token))
{
DataSet ds = new DataSet();
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[2];
nSqlParam[0] = new NpgsqlParameter("inticket_id ", model.TicketId);//pass ticket id and get feedback details of a ticket.
nSqlParam[1] = new NpgsqlParameter("increation_time ", Convert.ToDateTime(model.CreationTime).AddMinutes(-model.UtcMinute));
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_tickets_additional_info"], nSqlParam);
if (ds.Tables[0].Rows.Count > 0)
{
objModel.CallStatus = ds.Tables[0].Rows[0]["call_status"].ToString();
objModel.Complaint = ds.Tables[0].Rows[0]["complaints"].ToString();
//check creation time is not null.
if (ds.Tables[0].Rows[0]["creation_time"].ToString() != null && ds.Tables[0].Rows[0]["creation_time"].ToString() != "")
{
objModel.CreationTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["creation_time"]).AddMinutes(model.UtcMinute);
}
objModel.FeedBackagent = ds.Tables[0].Rows[0]["feedback_agent"].ToString();
objModel.FeedBackEaseOfGettingCall = ds.Tables[0].Rows[0]["feedback_ease_of_getting_call"].ToString();
objModel.FeedBackEosCharges = ds.Tables[0].Rows[0]["feedback_eos_charges"].ToString();
objModel.FeedBackOverAllExperience = ds.Tables[0].Rows[0]["feedback_over_all_experience"].ToString();
objModel.FeedBackResponseOfCallCenter = ds.Tables[0].Rows[0]["feedback_response_of_call_center"].ToString();
objModel.FeedBackTimelyUpdationByDealer = ds.Tables[0].Rows[0]["feedback_timely_updation_by_dealer"].ToString();
objModel.FeedBackTotalRepairTime = ds.Tables[0].Rows[0]["feedback_total_repair_time"].ToString();
objModel.OtherRemark = ds.Tables[0].Rows[0]["other_remarks"].ToString();
objModel.ReasonMoreThan24Hrs = ds.Tables[0].Rows[0]["reason_for_more_then_24hours"].ToString();
objModel.SuggestionComplaint = ds.Tables[0].Rows[0]["suggestion_complaint"].ToString();
objModel.TicketId = ds.Tables[0].Rows[0]["ticket_id"].ToString();
objModel.State = ds.Tables[0].Rows[0]["state_name"].ToString();
objModel.City = ds.Tables[0].Rows[0]["city_name"].ToString();
objModel.CallerLanguage = ds.Tables[0].Rows[0]["caller_language"].ToString();
objModel.Warranty = ds.Tables[0].Rows[0]["warranty"].ToString();
objModel.TollFreeNoSource = ds.Tables[0].Rows[0]["toll_free_no_source"].ToString();
objModel.OpportunityLoss = ds.Tables[0].Rows[0]["opportunity_loss"].ToString();
}
objModel.Status = "1";
}
else
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
}
return objModel;
}
catch (Exception Ex)
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + " " + Ex.Message;
objLog.ErrorLogFile("GetTicketFeedBackAndOtherInfo", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To get ticket feedback history
///
/// ticket info
/// ticket feedback history
public FeedBackModel GetTicketFeedBackHistory(FeedBackModel model)
{
FeedBackModel objModel = new FeedBackModel();
try
{
objAuthorization = new AuthenticationRepository();
List objFeedbackHistoryList = new List();
if (objAuthorization.AuthenticateDevice(model.Token))
{
DataSet ds = new DataSet();
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[1];
nSqlParam[0] = new NpgsqlParameter("inticket_id ", model.TicketId);//pass ticket id and get feedback details of a ticket.
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_tickets_closed_feedback_activity"], nSqlParam);
if (ds.Tables[0].Rows.Count > 0)
{
objFeedbackHistoryList = ds.Tables[0].AsEnumerable().Select(s => new FeedbackHistory
{
TicketId = s.Field("ticket_id"),
CreatedBy = s.Field("created_by"),
CallStatus = s.Field("call_status"),
CreationTime = s.Field("creation_time").AddMinutes(model.UtcMinute).ToString(ConfigurationManager.AppSettings["DateTimeFormat"].ToString()),
Remarks = s.Field("remarks")
}).ToList();
}
objModel.feedbackHistoryList = objFeedbackHistoryList;
objModel.Status = "1";
}
else
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
}
return objModel;
}
catch (Exception Ex)
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + " " + Ex.Message;
objLog.ErrorLogFile("GetTicketFeedBackAndOtherInfo", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To insert feedback detail of ticket
///
/// feddback details
/// Status
public FeedBackModel InsertFeedBackForCustomerTicket(FeedBackModel model)
{
FeedBackModel objModel = new FeedBackModel();
try
{
objAuthorization = new AuthenticationRepository();
if (objAuthorization.AuthenticateDevice(model.Token))
{
// Inserting feedback into additional info
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[6];
nSqlParam[0] = new NpgsqlParameter("inticket_id ", model.TicketId);
nSqlParam[1] = new NpgsqlParameter("infeedback_agent ", model.FeedBackagent);
//nSqlParam[2] = new NpgsqlParameter("inIsSatisfied ",Convert.ToBoolean(model.IsSatisfied));
nSqlParam[2] = new NpgsqlParameter("inIsSatisfied ", model.IsCustomerSatisfied);
nSqlParam[3] = new NpgsqlParameter("inSelectedOption ", model.SelectedOption);
nSqlParam[4] = new NpgsqlParameter("inSelectedReason ", model.SelectedReason);
nSqlParam[5] = new NpgsqlParameter("increation_time ", Convert.ToDateTime(model.CreationTime).AddMinutes(-model.UtcMinute));
NpgSqlHelper.ExecuteNonQuery(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_insert_customer_feeback"], nSqlParam);
objModel.Status = "1";
}
else
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
}
return objModel;
}
catch (Exception Ex)
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + " " + Ex.Message;
objLog.ErrorLogFile("InsertFeedBackForTicket", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To get ticket feedback history
///
/// ticket info
/// ticket feedback history
public FeedBackModel GetCustomerFeedBackHistory(FeedBackModel model)
{
FeedBackModel objModel = new FeedBackModel();
try
{
objAuthorization = new AuthenticationRepository();
List objFeedbackHistoryList = new List();
List objCustomerFeedbackHistoryList = new List();
if (objAuthorization.AuthenticateDevice(model.Token))
{
DataSet ds = new DataSet();
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[1];
nSqlParam[0] = new NpgsqlParameter("inticket_id ", model.TicketId);//pass ticket id and get feedback details of a ticket.
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_tickets_closed_additional_info"], nSqlParam);
if (ds.Tables[0].Rows.Count > 0)
{
//if (ds.Tables[0]. != null)
//{
//}
objFeedbackHistoryList = ds.Tables[0].AsEnumerable().Select(s => new FeedbackHistory
{
TicketId = s.Field("ticket_id"),
FeedbackAgent=s.Field("feedback_agent"),
IsSatisfied =Convert.ToString(s.Field("are_you_satisfied")),
SelectedOption = s.Field("not_satisfied_option"),
SelectedReason = s.Field("not_satisfied_reason")
}).ToList();
}
objModel.feedbackHistoryList = objFeedbackHistoryList;
foreach (var item in objFeedbackHistoryList)
{
objModel.SelectedOption = item.SelectedOption;
};
string strPar = objModel.SelectedOption;
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.Text, "Select reason_name from dropdown_options where id=('" + strPar + "')");
if (ds.Tables[0].Rows.Count > 0)
{
objCustomerFeedbackHistoryList = ds.Tables[0].AsEnumerable().Select(s => new CustomerFeedbackHistory
{
SelectedOptionText = s.Field("reason_name"),
}).ToList();
foreach (var item in objCustomerFeedbackHistoryList)
{
objModel.SelectedOption = item.SelectedOptionText;
};
}
}
else
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
}
return objModel;
}
catch (Exception Ex)
{
objModel.Status = "0";
objModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + " " + Ex.Message;
objLog.ErrorLogFile("GetTicketFeedBackAndOtherInfo", Ex.Message, path, errorlogtf);
return objModel;
}
}
#endregion
}
#endregion
}