333 lines
14 KiB
C#
333 lines
14 KiB
C#
namespace VECV_WebApi.Models.Vehicle
|
|
{
|
|
#region Namespaces
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using DBHelper;
|
|
using Npgsql;
|
|
using VECV_WebApi.Models.Authorization;
|
|
using LoggingHelper;
|
|
|
|
#endregion
|
|
|
|
#region Repository Class
|
|
|
|
/// <summary>
|
|
/// This class contain method releted to vehicle
|
|
/// </summary>
|
|
public class VehicleRepository
|
|
{
|
|
#region Global Variables
|
|
|
|
/// <summary>
|
|
/// making object of LoggingUtility class available to this class
|
|
/// </summary>
|
|
LoggingUtility objLog = new LoggingUtility();
|
|
|
|
/// <summary>
|
|
/// making the data-log file path available to this class
|
|
/// </summary>
|
|
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
|
|
|
|
/// <summary>
|
|
/// making error log file path available to this class
|
|
/// </summary>
|
|
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
|
|
|
|
/// <summary>
|
|
/// making the Database connection string available to this class
|
|
/// </summary>
|
|
private string _connStr;
|
|
|
|
/// <summary>
|
|
/// making Customer Repository object available to this class
|
|
/// </summary>
|
|
AuthenticationRepository objAuthorization;
|
|
|
|
#endregion
|
|
|
|
#region Contructors
|
|
|
|
/// <summary>
|
|
/// Default constructor intialize connection string of vecv database
|
|
/// </summary>
|
|
public VehicleRepository(string connString)
|
|
{
|
|
this._connStr = connString;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region API Methods
|
|
|
|
/// <summary>
|
|
/// Tho get vehicle detail
|
|
/// </summary>
|
|
/// <param name="model">vehicle info</param>
|
|
/// <returns>status and vehicle details</returns>
|
|
public VehicleModel GetVehicleDetail(VehicleModel model)
|
|
{
|
|
VehicleModel objModel = new VehicleModel();
|
|
try
|
|
{
|
|
DataSet ds = new DataSet();
|
|
objAuthorization = new AuthenticationRepository();
|
|
|
|
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[2];
|
|
nSqlParam[0] = new NpgsqlParameter("inid", model.Id);
|
|
nSqlParam[1] = new NpgsqlParameter("inregistration_number", model.RegistrationNo);
|
|
|
|
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_vehicle_details"], nSqlParam);
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
if (ds.Tables[0].Rows[0]["id"].ToString().Trim() != null)
|
|
{
|
|
objModel.Id = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("id")).FirstOrDefault();
|
|
objModel.RegistrationNo = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("registration_number")).FirstOrDefault();
|
|
objModel.VehicleNumberPlate = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("vehicle_number_plate")).FirstOrDefault();
|
|
objModel.ModelNumber = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("model_number")).FirstOrDefault();
|
|
objModel.Isdeleted = ds.Tables[0].AsEnumerable().Select(s => s.Field<Boolean?>("isdeleted")).FirstOrDefault();
|
|
objModel.VehicleType = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("vehicle_type")).FirstOrDefault();
|
|
objModel.VehicleInstallationDate = ds.Tables[0].AsEnumerable().Select(s => s.Field<DateTime?>("vehicle_installation_date")).FirstOrDefault() != null ? Convert.ToDateTime(ds.Tables[0].AsEnumerable().Select(s => s.Field<DateTime?>("vehicle_installation_date")).FirstOrDefault()).AddMinutes(Convert.ToInt16(model.UtcMinute)).ToString(ConfigurationManager.AppSettings["DateFormat"]) : null;
|
|
objModel.ChassisNumber = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("vehicle_number_plate")).FirstOrDefault();
|
|
}
|
|
objModel.Status = "1";
|
|
}
|
|
else
|
|
{
|
|
objModel.Status = "0";
|
|
|
|
}
|
|
return objModel;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objModel.Status = "0";
|
|
objModel.Message = Ex.Message;
|
|
objLog.ErrorLogFile("GetVehicleDetail", Ex.Message, path, errorlogtf);
|
|
return objModel;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// To insert the detail of vehicle
|
|
/// </summary>
|
|
/// <param name="model">vehicle details</param>
|
|
/// <returns>contain the status 0 or 1</returns>
|
|
public VehicleModel InsertVehicleDetail(VehicleModel model)
|
|
{
|
|
VehicleModel objModel = new VehicleModel();
|
|
try
|
|
{
|
|
DataSet ds = new DataSet();
|
|
objAuthorization = new AuthenticationRepository();
|
|
if (objAuthorization.AuthenticateDevice(model.Token))
|
|
{
|
|
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[6];
|
|
nSqlParam[0] = new NpgsqlParameter("inregistration_number", model.RegistrationNo);
|
|
nSqlParam[1] = new NpgsqlParameter("invehicle_number_plate", model.VehicleNumberPlate);
|
|
nSqlParam[2] = new NpgsqlParameter("inmodel_number", model.ModelNumber);
|
|
nSqlParam[3] = new NpgsqlParameter("invehicle_type", model.VehicleType);
|
|
nSqlParam[4] = new NpgsqlParameter("ininstallation_date", model.InstallationDate != null ? Convert.ToDateTime(model.InstallationDate).AddMinutes(-model.UtcMinute) : model.InstallationDate);
|
|
nSqlParam[5] = new NpgsqlParameter("inkamuser",Convert.ToBoolean(model.KamUser=="Yes")?true:false);
|
|
NpgSqlHelper.ExecuteNonQuery(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_insert_vehicle"], nSqlParam);
|
|
// For Telematics Use
|
|
//NpgSqlHelper.ExecuteNonQuery(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_sync_vehicle_details"]);
|
|
|
|
objModel.Status = "1";
|
|
}
|
|
else
|
|
{
|
|
objModel.Status = "0";
|
|
objModel.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
|
|
}
|
|
return objModel;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objModel.Status = "0";
|
|
objModel.Message = Ex.Message;
|
|
objLog.ErrorLogFile("InsertVehicleDetail", Ex.Message, path, errorlogtf);
|
|
return objModel;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// To update the detail of vehicle
|
|
/// </summary>
|
|
/// <param name="model">vehicle details</param>
|
|
/// <returns>contain the status 0 or 1</returns>
|
|
public VehicleModel UpdateVehicleDetail(VehicleModel model)
|
|
{
|
|
VehicleModel objModel = new VehicleModel();
|
|
try
|
|
{
|
|
DataSet ds = new DataSet();
|
|
objAuthorization = new AuthenticationRepository();
|
|
if (objAuthorization.AuthenticateDevice(model.Token))
|
|
{
|
|
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[2];
|
|
nSqlParam[0] = new NpgsqlParameter("inregistration_number", model.RegistrationNo);
|
|
nSqlParam[1] = new NpgsqlParameter("invehicle_number_plate", model.VehicleNumberPlate);
|
|
NpgSqlHelper.ExecuteNonQuery(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_update_vehicle_detail"], nSqlParam);
|
|
|
|
// For Telematics Use
|
|
//NpgSqlHelper.ExecuteNonQuery(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_sync_vehicle_details"]);
|
|
|
|
objModel.Status = "1";
|
|
}
|
|
else
|
|
{
|
|
objModel.Status = "0";
|
|
objModel.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
|
|
}
|
|
return objModel;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objModel.Status = "0";
|
|
objModel.Message = Ex.Message;
|
|
objLog.ErrorLogFile("UpdateVehicleDetail", Ex.Message, path, errorlogtf);
|
|
return objModel;
|
|
}
|
|
}
|
|
//Mobile OTP CR
|
|
|
|
/// <summary>
|
|
/// To update the detail of vehicle
|
|
/// </summary>
|
|
/// <param name="model">vehicle details</param>
|
|
/// <returns>contain the status 0 or 1</returns>
|
|
public CheckMobileModel CheckOTPMobile(CheckMobileModel model)
|
|
{
|
|
|
|
CheckMobileModel response_model = new CheckMobileModel();
|
|
|
|
try
|
|
{
|
|
DataSet ds = new DataSet();
|
|
objAuthorization = new AuthenticationRepository();
|
|
if (objAuthorization.AuthenticateDevice(model.Token))
|
|
{
|
|
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[3];
|
|
nSqlParam[0] = new NpgsqlParameter("in_ticket_id", model.ticketID);
|
|
nSqlParam[1] = new NpgsqlParameter("in_van_id", model.vanID);
|
|
nSqlParam[2] = new NpgsqlParameter("in_otp", model.OTP);
|
|
|
|
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_check_ticket_otp"], nSqlParam);
|
|
response_model.response = Convert.ToBoolean(ds.Tables[0].Rows[0][0]);
|
|
}
|
|
|
|
|
|
return response_model;
|
|
|
|
|
|
}
|
|
|
|
catch (Exception Ex)
|
|
{
|
|
|
|
response_model.response = false;
|
|
objLog.ErrorLogFile("CheckOTPsenttoUser", Ex.Message, path, errorlogtf);
|
|
return response_model;
|
|
}
|
|
|
|
|
|
}
|
|
//priya
|
|
|
|
public VehicleModel GetchessisDetail(VehicleModel model)
|
|
{
|
|
VehicleModel objModel = new VehicleModel();
|
|
try
|
|
{
|
|
DataSet ds = new DataSet();
|
|
objAuthorization = new AuthenticationRepository();
|
|
|
|
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[2];
|
|
nSqlParam[0] = new NpgsqlParameter("inid", model.Id);
|
|
nSqlParam[1] = new NpgsqlParameter("inregistration_number", model.RegistrationNo);
|
|
|
|
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_vehicle_details"], nSqlParam);
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
if (ds.Tables[0].Rows[0]["id"].ToString().Trim() != null)
|
|
{
|
|
objModel.Id = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("id")).FirstOrDefault();
|
|
objModel.RegistrationNo = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("registration_number")).FirstOrDefault();
|
|
objModel.VehicleNumberPlate = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("vehicle_number_plate")).FirstOrDefault();
|
|
objModel.ModelNumber = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("model_number")).FirstOrDefault();
|
|
objModel.Isdeleted = ds.Tables[0].AsEnumerable().Select(s => s.Field<Boolean?>("isdeleted")).FirstOrDefault();
|
|
objModel.VehicleType = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("vehicle_type")).FirstOrDefault();
|
|
objModel.VehicleInstallationDate = ds.Tables[0].AsEnumerable().Select(s => s.Field<DateTime?>("vehicle_installation_date")).FirstOrDefault() != null ? Convert.ToDateTime(ds.Tables[0].AsEnumerable().Select(s => s.Field<DateTime?>("vehicle_installation_date")).FirstOrDefault()).AddMinutes(Convert.ToInt16(model.UtcMinute)).ToString(ConfigurationManager.AppSettings["DateFormat"]) : null;
|
|
objModel.ChassisNumber = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("_chassis_number")).FirstOrDefault();
|
|
}
|
|
objModel.Status = "1";
|
|
}
|
|
else
|
|
{
|
|
objModel.Status = "0";
|
|
|
|
}
|
|
return objModel;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objModel.Status = "0";
|
|
objModel.Message = Ex.Message;
|
|
objLog.ErrorLogFile("GetVehicleDetail", Ex.Message, path, errorlogtf);
|
|
return objModel;
|
|
}
|
|
}
|
|
|
|
public string updateVehicleConnectedFlag(string ticketid,string vehiclestatus)
|
|
{
|
|
VehicleModel objModel = new VehicleModel();
|
|
string strMsg = "";
|
|
try
|
|
{
|
|
DataSet ds = new DataSet();
|
|
objAuthorization = new AuthenticationRepository();
|
|
|
|
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[2];
|
|
nSqlParam[0] = new NpgsqlParameter("inticketId", ticketid);
|
|
nSqlParam[1] = new NpgsqlParameter("invehiclestatus", vehiclestatus);
|
|
|
|
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_update_vehicle_connected_flag"], nSqlParam);
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
strMsg = "success";
|
|
objModel.Status = "1";
|
|
}
|
|
else
|
|
{
|
|
strMsg = "un successful";
|
|
objModel.Status = "0";
|
|
|
|
}
|
|
return strMsg;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objModel.Status = "0";
|
|
objModel.Message = Ex.Message;
|
|
objLog.ErrorLogFile("GetVehicleDetail", Ex.Message, path, errorlogtf);
|
|
return strMsg;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |