EOS/Models/Inventory/InventoryRepository.cs
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

551 lines
27 KiB
C#

using GODATA.Models.Ticket;
using GODATA.Models.TicketAdministration_Dealer;
using LoggingHelper;
using RestSharp;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.Linq;
using System.Web;
namespace GODATA.Models.Inventory
{
public class InventoryModelRepository
{
LoggingUtility objLog = new LoggingUtility();
/// <summary>
/// Represent string object contain log file path
/// </summary>
//string path = "~/Log/";
string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
/// <summary>
/// Represent string object contain log status
/// </summary>
string logtf = (ConfigurationManager.AppSettings["Log"]);
/// <summary>
/// Represent string object contain Error log status
/// </summary>
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
/// <summary>
/// getting time zone id from AppSetting in web.config file
/// </summary>
private static string _TimeZoneId = ConfigurationManager.AppSettings["TimeZoneId"].ToString();
/// <summary>
/// getting rest api url from AppSetting in web.config file
/// </summary>
private static string _RestClientUrl = ConfigurationManager.AppSettings["RestfulApiUrl"].ToString();
/// <summary>
/// getting web api token from AppSetting in web.config file
/// </summary>
private static string _securityToken = ConfigurationManager.AppSettings["RESTfulSecurityToken"].ToString();
#region Get A Reason List
/// <summary>
/// Get All Reason From Web API
/// </summary>
/// <returns></returns>
public List<InventoryModel> GetReasonList()
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/global?Type=all", Method.POST);
request.AddParameter("Token", _securityToken);
return client.Execute<List<InventoryModel>>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_GetReasonList", ex.Message, path, errorlogtf);
throw ex;
}
}
#endregion
#region Insert Update Reason
/// <summary>
/// Insert Or Update Reason
/// </summary>
public InventoryModel AddOrUpdateReason(InventoryModel objInventoryModel)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Global?UpdateReason=ttpl", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("Id", objInventoryModel.Id == 0 ? "null" : Convert.ToString(objInventoryModel.Id));
request.AddParameter("ReasonName", objInventoryModel.ReasonName);
request.AddParameter("ReasonAlias", objInventoryModel.ReasonAlias);
request.AddParameter("TypeId", objInventoryModel.TypeId);
request.AddParameter("IsDeleted", objInventoryModel.IsDeleted);
return client.Execute<InventoryModel>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_AddOrUpdateReason", ex.Message, path, errorlogtf);
throw ex;
}
}
#endregion
//#region Delete Reason
///// <summary>
///// Delete Reason
///// </summary>
//public InventoryModel DeleteReason(InventoryModel objInventoryModel)
//{
// try
// {
// var client = new RestSharp.RestClient(_RestClientUrl);
// var request = new RestRequest("Api/Global?DeleteReason=ttpl", Method.POST);
// request.AddParameter("Token", _securityToken);
// request.AddParameter("Id", objInventoryModel.Id);
// request.AddParameter("TypeId", objInventoryModel.TypeId);
// return client.Execute<InventoryModel>(request).Data;
// }
// catch (Exception ex)
// {
// objLog.ErrorLogFile("InventorRepository_AddOrUpdateReason", ex.Message, path, errorlogtf);
// throw ex;
// }
//}
//#endregion
/// <summary>
/// Post method to get TypeIds list
/// </summary>
/// <returns>return list of TypeIds</returns>
public List<InventoryModel> GetTypeIdsList()
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Global?Type=dropdown", Method.POST);
return client.Execute<List<InventoryModel>>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_GetTypeIdsList", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Post method to get All Organization Chart Detail
/// </summary>
/// <returns>return list of Organization Chart</returns>
public List<OrganizationChart> OrganizationChart()
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Global?Global=sd&Organization=sds", Method.POST);
return client.Execute<List<OrganizationChart>>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_AddOrUpdateReason", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Post method to Get Dealer List Including Dealer Dealer
/// </summary>
/// <returns>List Of Manage Fleet</returns>
public List<ManageFleet> GetDealerList(string sUserName, string sStateName, string sCityName)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Global?dealer=&dealer1=&dealer2=&dealer3=", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("UserId", sUserName);
request.AddParameter("DealerStateParam", sStateName);
request.AddParameter("DealerCityParam", sCityName);
return client.Execute<List<ManageFleet>>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_GetDealerList", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Post method to Get Complete Dealer Detail Including Dealer Vans Detail
/// </summary>
/// <returns>Object Of ManageFleet class</returns>
public ManageFleet GetDealerCompleteDetail(string sDealerId)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/dealer?DealerDetail=get", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("DealerId", sDealerId);
return client.Execute<ManageFleet>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_GetDealerCompleteDetail", ex.Message, path, errorlogtf);
throw ex;
}
}
public ManageFleet ReleaseIMEI(string IMEI)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Global?IMEI=" + IMEI + "&ReleaseIMEI1=I1&ReleaseIMEI2=I2&ReleaseIMEI3=4&ReleaseIMEI4=5&ReleaseIMEI5=65&ReleaseIMEI6=78&ReleaseIMEI7=kk", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("IMEI", IMEI);
return client.Execute<ManageFleet>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("ReleaseIMEI", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Post method to Update,Insert and Delete Complete Dealer Detail Including Dealer Vans Detail
/// </summary>
/// <returns>Object Of ManageFleet class</returns>
public ManageFleet SaveDealerDetail(ManageFleet objManageFleet)
{
try
{
int iCount = 0;
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest(objManageFleet.DealerId != null ? "Api/dealer?DealerDetail=update" : "Api/dealer?DealerDetail=insert", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("DealerId", objManageFleet.NewDealerId);
request.AddParameter("Operation", objManageFleet.DealerId != null ? "Update" : "Insert");
request.AddParameter("DealerOrganizationId", objManageFleet.DealerOrganizationId);
request.AddParameter("DealerState", objManageFleet.DealerState);
request.AddParameter("DealerCity", objManageFleet.DealerCity);
request.AddParameter("DealerDealerName", objManageFleet.DealerDealerName);
request.AddParameter("DealerContactNo", objManageFleet.DealerContactNo);
request.AddParameter("DealerDealerDefaultLattitude", objManageFleet.DealerDealerDefaultLattitude);
request.AddParameter("DealerDealerDefaultLongitude", objManageFleet.DealerDealerDefaultLongitude);
request.AddParameter("IsDeleted", objManageFleet.IsDeleted);
if (objManageFleet.VanList != null)
{
foreach (VanList objVanList in objManageFleet.VanList)
{
request.AddParameter("VanList[" + iCount + "].DealerId", objManageFleet.DealerId);
request.AddParameter("VanList[" + iCount + "].VanId", objVanList.VanId);
request.AddParameter("VanList[" + iCount + "].VanAlias", objVanList.VanAlias);
request.AddParameter("VanList[" + iCount + "].VanDefaultLatitude", objVanList.VanDefaultLatitude);
request.AddParameter("VanList[" + iCount + "].VanDefaultLongitude", objVanList.VanDefaultLongitude);
request.AddParameter("VanList[" + iCount + "].VanModelName", objVanList.VanModelName);
request.AddParameter("VanList[" + iCount + "].VanRegistrationNo", objVanList.VanRegistrationNo);
request.AddParameter("VanList[" + iCount + "].VanCity", objVanList.VanCity);
request.AddParameter("VanList[" + iCount + "].VanState", objVanList.VanState);
request.AddParameter("VanList[" + iCount + "].ServiceEngineerAlias", objVanList.ServiceEngineerAlias);
request.AddParameter("VanList[" + iCount + "].ServiceEngineerName", objVanList.ServiceEngineerName);
request.AddParameter("VanList[" + iCount + "].ServiceEngineerContactNumber", objVanList.ServiceEngineerContactNumber);
request.AddParameter("VanList[" + iCount + "].IsDeletedVan", objVanList.IsDeletedVan);
request.AddParameter("VanList[" + iCount + "].IsVanRelease", objVanList.IsVanRelease);
request.AddParameter("VanList[" + iCount + "].IsDeletedServiceEngg", objVanList.IsDeletedVan);
request.AddParameter("VanList[" + iCount + "].ServiceEngineerId", objVanList.ServiceEngineerId);
request.AddParameter("VanList[" + iCount + "].VanIsVisitedInterState", objVanList.VanIsVisitedInterState);
request.AddParameter("VanList[" + iCount + "].ServiceEngineerApplicationLicenseKey", objVanList.ServiceEngineerApplicationLicenseKey);
request.AddParameter("VanList[" + iCount + "].ServiceEngineerMobileApplicationBlocked", Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ServiceEngineerMobileApplicationBlocked"]));
iCount++;
}
}
return client.Execute<ManageFleet>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_SaveDealerDetail", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Post method to Duplicate Contact No or Duplicate Van Registration No
/// </summary>
/// <returns>Object Of ManageFleet</returns>
public ManageFleet CheckDealerContactNoAndVanRegistrationNo(string sDealerDetail, string sDealerContactNo)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/dealer?DealerDetail=" + sDealerDetail, Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("DealerContactNo", sDealerContactNo);
return client.Execute<ManageFleet>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_CheckDealerContactNoAndVanRegistrationNo", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Post method to Duplicate SCode
/// </summary>
/// <returns>Object Of DealerOutputModel</returns>
public DealerOutputModel CheckDealerScode(string sDealerCode)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("/Api/Dealer?Dealer=abc&DealerExistOrNot=asa", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("DealerCode", sDealerCode);
return client.Execute<DealerOutputModel>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_CheckDealerScode", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Get next 20 Records of Owner based on state, Filterval, limit, offset
/// </summary>
/// <returns>List Of Owner based on state, Filterval, limit, offset</returns>
public List<ManageOwner> GetOwnerList(string state, string FilterVal, int limit, int Offset)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Customer?owner=hh", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("CustomerState", state);
request.AddParameter("Value", FilterVal);
request.AddParameter("Limit", limit);
request.AddParameter("OffeSet", Offset);
return client.Execute<List<ManageOwner>>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("GetOwnerList", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Get Owner detail based on Owner ID
/// </summary>
/// <param name="sCustId">Owner ID</param>
/// <returns>List Of Owner Detail and Driver Detail</returns>
public List<ManageOwner> GetOwnerDetails(string sCustId)
{
try
{
string _timeOffSetMinutes = HttpContext.Current.Session["UtcMinute"].ToString();
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Customer?owner=", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("CustomerId", sCustId);
request.AddParameter("UtcMinute", _timeOffSetMinutes);
return client.Execute<List<ManageOwner>>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("GetOwnerDetails", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Method to Check Duplicate Contact No or Duplicate Van Registration No
/// </summary>
/// <param name="CustomerId">Id that is used to check</param>
/// <param name="type">type means contact No, Van Registration No</param>
/// <returns>ManageOwner Object</returns>
public ManageOwner CheckDupOwnerContactNoVechRegNoAndVechChasisNo(string CustomerId, string type)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Customer?owner=&type=", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("CustomerId", CustomerId);
request.AddParameter("Type", type);
return client.Execute<ManageOwner>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_CheckDupOwnerContactNoVechRegNoAndVechChasisNo", ex.Message, path, errorlogtf);
throw ex;
}
}
/// <summary>
/// Insert, Update, Delete the Owner
/// </summary>
/// <param name="objManageOwner">Contains Value in property</param>
/// <returns>Returns Object ManageOwner class</returns>
public ManageOwner SaveOwnerDetail(ManageOwner objManageOwner)
{
try
{
int iCount = 0;
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Customer?customer=sds&owner=&vehicle=", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("OwnerModel.CustomerCustomerName", objManageOwner.CustomerCustomerName);
request.AddParameter("OwnerModel.CustomerMobileNumber1", objManageOwner.CustomerMobileNumber1);
request.AddParameter("OwnerModel.CustomerAddress", objManageOwner.CustomerAddress);
request.AddParameter("OwnerModel.CustomerEmailId", objManageOwner.CustomerEmailId);
request.AddParameter("OwnerModel.CustomerCity", objManageOwner.CustomerCity);
request.AddParameter("OwnerModel.CustomerState", objManageOwner.CustomerState);
request.AddParameter("OwnerModel.InIsOwner", true);
request.AddParameter("OwnerModel.CustomerId", objManageOwner.CustomerId == null ? "" : objManageOwner.CustomerId);
request.AddParameter("OwnerModel.IsDeleted", objManageOwner.IsDeleted);
request.AddParameter("OwnerModel.InstallationDate", objManageOwner.VehicleInstallationDate);
request.AddParameter("OwnerModel.IsKamUser", objManageOwner.IsKamUser);
foreach (ManageOwner objCustList in objManageOwner.plsVechileList)
{
request.AddParameter("CustomerList[" + iCount + "].CustomerId", objCustList.CustomerId == null ? "" : objCustList.CustomerId);
request.AddParameter("CustomerList[" + iCount + "].CustomerCustomerName", objCustList.CustomerCustomerName);
request.AddParameter("CustomerList[" + iCount + "].CustomerMobileNumber1", objCustList.CustomerMobileNumber1);
request.AddParameter("CustomerList[" + iCount + "].CustomerEmailId", objCustList.CustomerEmailId);
request.AddParameter("CustomerList[" + iCount + "].CustomerCity", objCustList.CustomerCity);
request.AddParameter("CustomerList[" + iCount + "].CustomerState", objCustList.CustomerState);
request.AddParameter("CustomerList[" + iCount + "].CustomerAddress", objCustList.CustomerAddress);
request.AddParameter("CustomerList[" + iCount + "].VehicleRegistrationNumber", objCustList.VehicleRegistrationNumber);
request.AddParameter("CustomerList[" + iCount + "].VehicleNumberPlate", objCustList.VehicleNumberPlate);
request.AddParameter("CustomerList[" + iCount + "].VehicleModelNumber", objCustList.VehicleModelNumber);
request.AddParameter("CustomerList[" + iCount + "].InIsOwner", false);
request.AddParameter("CustomerList[" + iCount + "].VehicleType", objCustList.VehicleType);
request.AddParameter("CustomerList[" + iCount + "].VehicleId", objCustList.VehicleId);
request.AddParameter("CustomerList[" + iCount + "].CustomerVehicleModelTagging", objCustList.CustomerVehicleModelTagging);
request.AddParameter("CustomerList[" + iCount + "].IsDeleted", objCustList.IsDeleted);
request.AddParameter("CustomerList[" + iCount + "].IsDealetedVehicle", objCustList.IsDealetedVehicle);
request.AddParameter("CustomerList[" + iCount + "].InstallationDate", objCustList.VehicleInstallationDate);
request.AddParameter("CustomerList[" + iCount + "].IsKamUser", objCustList.IsKamUser);
iCount++;
}
return client.Execute<ManageOwner>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_SaveDealerDetail", ex.Message, path, errorlogtf);
throw ex;
}
}
#region Get A Model List
/// <summary>
/// Get All Vechile Model From Web API
/// </summary>
/// <returns>Returns List Of VehicleModel class</returns>
public List<GODATA.Models.TicketAdministration_Dealer.VehicleModelModel> GetVehicleModelList()
{
try
{
TicketAdministration_DealerRepository objTicketDealerAdministrationRepository = new TicketAdministration_DealerRepository();
List<GODATA.Models.TicketAdministration_Dealer.VehicleModelModel> oVehicleModelList = objTicketDealerAdministrationRepository.GetVehicleModelList();
//oVehicleModelList.Remove().Equals()
//oVehicleModelList.RemoveAll(x => x.IsDeleted == true);
return oVehicleModelList;
}
catch (Exception ex)
{
objLog.ErrorLogFile("GetVehicleModelList", ex.Message, path, errorlogtf);
throw ex;
}
}
#endregion
#region Insert Update Delete Or Check Duplicate Vechile Model
/// <summary>
/// Insert, Update, Delete and Also Check Duplicate Vechile Model
/// </summary>
/// <param name="objVehicleModel">Contains Value in property</param>
/// <returns>Returns Object VehicleModel class</returns>
public GODATA.Models.TicketAdministration_Dealer.VehicleModelModel AddOrUpdateVechicleModel(GODATA.Models.TicketAdministration_Dealer.VehicleModelModel objVehicleModel)
{
try
{
#region No Use
var strings = ((IEnumerable)objVehicleModel.VehicleTypeName).Cast<object>()
.Select(x => x == null ? x : x.ToString())
.ToArray();
#endregion
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/Global/?Global=tt&VehicleType=", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("VehicleTypeId", objVehicleModel.VehicleTypeId == null ? objVehicleModel.VehicleTypeName : objVehicleModel.VehicleTypeId);
request.AddParameter("VehicleTypeName", objVehicleModel.VehicleTypeName);
request.AddParameter("VehicleTypeTagging", objVehicleModel.VehicleTypeTagging);
request.AddParameter("IsDeleted", objVehicleModel.IsDeleted);
request.AddParameter("Operation", objVehicleModel.Operation);
request.AddParameter("udanVehicleProductId", objVehicleModel.udanVehicleProductId);
request.AddParameter("udanVehicleProductName", objVehicleModel.udanVehicleProductName);
return client.Execute<GODATA.Models.TicketAdministration_Dealer.VehicleModelModel>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("AddOrUpdateVechicleModel", ex.Message, path, errorlogtf);
throw ex;
}
}
#endregion
// #region Delete Reason
// /// <summary>
// /// Delete Vechile Model
// /// </summary>
// public GODATA.Models.TicketAdministration_Dealer.VehicleModelModel DeleteVehicle(GODATA.Models.TicketAdministration_Dealer.VehicleModelModel objVehicleModel)
// {
// try
// {
// var client = new RestSharp.RestClient(_RestClientUrl);
// var request = new RestRequest("Api/Global?DeleteVechile=ttpl", Method.POST);
// request.AddParameter("Token", _securityToken);
// request.AddParameter("VehicleTypeId", objVehicleModel.VehicleTypeId);
// request.AddParameter("TypeId", objVehicleModel.VehicleTypeTagging);
// return client.Execute<GODATA.Models.TicketAdministration_Dealer.VehicleModelModel>(request).Data;
// }
// catch (Exception ex)
// {
// objLog.ErrorLogFile("DeleteVehicle", ex.Message, path, errorlogtf);
// throw ex;
// }
// }
// #endregion
/// <summary>
/// Post method to Duplicate Contact No of van
/// </summary>
/// <returns>Object Of ManageFleet</returns>
public ManageFleet CheckVanContactNo(string sVanContactNo)
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/dealer?UserType=van&UserType2=", Method.POST);
request.AddParameter("Token", _securityToken);
request.AddParameter("VanContactNo", sVanContactNo);
return client.Execute<ManageFleet>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("InventorRepository_CheckVanContactNo", ex.Message, path, errorlogtf);
throw ex;
}
}
}
}