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(); /// /// Represent string object contain log file path /// //string path = "~/Log/"; string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]); /// /// Represent string object contain log status /// string logtf = (ConfigurationManager.AppSettings["Log"]); /// /// Represent string object contain Error log status /// string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]); /// /// getting time zone id from AppSetting in web.config file /// private static string _TimeZoneId = ConfigurationManager.AppSettings["TimeZoneId"].ToString(); /// /// getting rest api url from AppSetting in web.config file /// private static string _RestClientUrl = ConfigurationManager.AppSettings["RestfulApiUrl"].ToString(); /// /// getting web api token from AppSetting in web.config file /// private static string _securityToken = ConfigurationManager.AppSettings["RESTfulSecurityToken"].ToString(); #region Get A Reason List /// /// Get All Reason From Web API /// /// public List 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>(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_GetReasonList", ex.Message, path, errorlogtf); throw ex; } } #endregion #region Insert Update Reason /// /// Insert Or Update Reason /// 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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_AddOrUpdateReason", ex.Message, path, errorlogtf); throw ex; } } #endregion //#region Delete Reason ///// ///// Delete Reason ///// //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(request).Data; // } // catch (Exception ex) // { // objLog.ErrorLogFile("InventorRepository_AddOrUpdateReason", ex.Message, path, errorlogtf); // throw ex; // } //} //#endregion /// /// Post method to get TypeIds list /// /// return list of TypeIds public List GetTypeIdsList() { try { var client = new RestSharp.RestClient(_RestClientUrl); var request = new RestRequest("Api/Global?Type=dropdown", Method.POST); return client.Execute>(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_GetTypeIdsList", ex.Message, path, errorlogtf); throw ex; } } /// /// Post method to get All Organization Chart Detail /// /// return list of Organization Chart public List OrganizationChart() { try { var client = new RestSharp.RestClient(_RestClientUrl); var request = new RestRequest("Api/Global?Global=sd&Organization=sds", Method.POST); return client.Execute>(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_AddOrUpdateReason", ex.Message, path, errorlogtf); throw ex; } } /// /// Post method to Get Dealer List Including Dealer Dealer /// /// List Of Manage Fleet public List 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>(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_GetDealerList", ex.Message, path, errorlogtf); throw ex; } } /// /// Post method to Get Complete Dealer Detail Including Dealer Vans Detail /// /// Object Of ManageFleet class 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(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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("ReleaseIMEI", ex.Message, path, errorlogtf); throw ex; } } /// /// Post method to Update,Insert and Delete Complete Dealer Detail Including Dealer Vans Detail /// /// Object Of ManageFleet class 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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_SaveDealerDetail", ex.Message, path, errorlogtf); throw ex; } } /// /// Post method to Duplicate Contact No or Duplicate Van Registration No /// /// Object Of ManageFleet 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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_CheckDealerContactNoAndVanRegistrationNo", ex.Message, path, errorlogtf); throw ex; } } /// /// Post method to Duplicate SCode /// /// Object Of DealerOutputModel 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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_CheckDealerScode", ex.Message, path, errorlogtf); throw ex; } } /// /// Get next 20 Records of Owner based on state, Filterval, limit, offset /// /// List Of Owner based on state, Filterval, limit, offset public List 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>(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("GetOwnerList", ex.Message, path, errorlogtf); throw ex; } } /// /// Get Owner detail based on Owner ID /// /// Owner ID /// List Of Owner Detail and Driver Detail public List 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>(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("GetOwnerDetails", ex.Message, path, errorlogtf); throw ex; } } /// /// Method to Check Duplicate Contact No or Duplicate Van Registration No /// /// Id that is used to check /// type means contact No, Van Registration No /// ManageOwner Object 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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_CheckDupOwnerContactNoVechRegNoAndVechChasisNo", ex.Message, path, errorlogtf); throw ex; } } /// /// Insert, Update, Delete the Owner /// /// Contains Value in property /// Returns Object ManageOwner class 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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_SaveDealerDetail", ex.Message, path, errorlogtf); throw ex; } } #region Get A Model List /// /// Get All Vechile Model From Web API /// /// Returns List Of VehicleModel class public List GetVehicleModelList() { try { TicketAdministration_DealerRepository objTicketDealerAdministrationRepository = new TicketAdministration_DealerRepository(); List 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 /// /// Insert, Update, Delete and Also Check Duplicate Vechile Model /// /// Contains Value in property /// Returns Object VehicleModel class public GODATA.Models.TicketAdministration_Dealer.VehicleModelModel AddOrUpdateVechicleModel(GODATA.Models.TicketAdministration_Dealer.VehicleModelModel objVehicleModel) { try { #region No Use var strings = ((IEnumerable)objVehicleModel.VehicleTypeName).Cast() .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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("AddOrUpdateVechicleModel", ex.Message, path, errorlogtf); throw ex; } } #endregion // #region Delete Reason // /// // /// Delete Vechile Model // /// // 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(request).Data; // } // catch (Exception ex) // { // objLog.ErrorLogFile("DeleteVehicle", ex.Message, path, errorlogtf); // throw ex; // } // } // #endregion /// /// Post method to Duplicate Contact No of van /// /// Object Of ManageFleet 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(request).Data; } catch (Exception ex) { objLog.ErrorLogFile("InventorRepository_CheckVanContactNo", ex.Message, path, errorlogtf); throw ex; } } } }