using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Net; using System.Net.Mail; using System.Text; using MantriAPI.Models; using System.Data; using System.Data.SqlClient; using System.Configuration; using Newtonsoft.Json; using System.Web.Script.Serialization; using System.IO; using iTextSharp.text; using iTextSharp.text.html.simpleparser; using iTextSharp.text.pdf; using System.Drawing; namespace MantriAPI.Controllers { public class MantriAPIController : Controller { public const string strApiKey = "AIzaSyAdGrPJh9LOWwwls3dtTOD2kVOQb30AAqg"; public const string strSecretKey = "AIzaSyCE7tQA4uFxYWW-gY4cvFkXoyC5LCYpVew"; // GET: MantriAPI public ActionResult Index() { return View(); } public DataTable fnReturnDt(string strSQL) { DataTable dtDet = new DataTable(); SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; SqlCommand cmd; SqlDataAdapter sdaDet = new SqlDataAdapter(); con.Open(); cmd = new SqlCommand(strSQL, con); sdaDet.SelectCommand = cmd; dtDet = new DataTable(); sdaDet.Fill(dtDet); con.Close(); return dtDet; } public string fnReturnString(string strSQL) { string strData; SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; SqlCommand cmd; if (con.State == ConnectionState.Closed) { con.Open(); } else { con.Close(); con.Open(); } cmd = new SqlCommand(strSQL, con); strData = cmd.ExecuteScalar().ToString(); con.Close(); return strData.Replace(@"\", ""); } public List> GetTableRows(DataTable dtData) { List> lstRows = new List>(); Dictionary dictRow = null; foreach (DataRow dr in dtData.Rows) { dictRow = new Dictionary(); foreach (DataColumn col in dtData.Columns) { dictRow.Add(col.ColumnName, dr[col]); } lstRows.Add(dictRow); } return lstRows; } public string GenerateDateFormat(String Date, Int32 intLocId) { string DateFormat = ""; string strSQL = ""; DataTable dtEFP = new DataTable(); strSQL = "SELECT [dbo].[TPF_DateFormat]('" + Date + "'," + intLocId + ") AS DFormat"; dtEFP = new DataTable(); dtEFP = fnReturnDt(strSQL); DateFormat = dtEFP.Rows[0].Field("DFormat"); return DateFormat; } public string GenerateTrNo(Int32 intLocId, string trtype) { string Prefix = ""; Int32 Numbers = 0; string strMonth = ""; if (DateTime.Now.Month == 1) { strMonth = "A"; } if (DateTime.Now.Month == 2) { strMonth = "B"; } if (DateTime.Now.Month == 3) { strMonth = "C"; } if (DateTime.Now.Month == 4) { strMonth = "D"; } if (DateTime.Now.Month == 5) { strMonth = "E"; } if (DateTime.Now.Month == 6) { strMonth = "F"; } if (DateTime.Now.Month == 7) { strMonth = "G"; } if (DateTime.Now.Month == 8) { strMonth = "H"; } if (DateTime.Now.Month == 9) { strMonth = "I"; } if (DateTime.Now.Month == 10) { strMonth = "J"; } if (DateTime.Now.Month == 11) { strMonth = "K"; } if (DateTime.Now.Month == 12) { strMonth = "L"; } Prefix = DateTime.Now.ToString("yy") + "" + strMonth; string strSQL; DataTable dtDet = new DataTable(); if (trtype == "leaveapply") { strSQL = "Select Top 1 Right(LAP_No, Len(LAP_No) - " + Prefix.Length + ") As TrNo From PDV_LAP " + "Where LAP_CliId = " + intLocId + " And LAP_No <> '' " + "And Left(LAP_No, " + Prefix.Length + ") = '" + Prefix + "' " + "Order By Len(LAP_No) Desc, LAP_No Desc "; } else if (trtype == "canteenmeal") { Prefix = Convert.ToString(DateTime.Now.ToString("yy") + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd")); strSQL = "Select Top 1 Right(CPOM_No, Len(CPOM_No) - " + Prefix.Length + ") As TrNo From PDV_CTRCPOM " + "Where CPOM_CliId = " + intLocId + " And CPOM_No <> '' " + "And Left(CPOM_No, " + Prefix.Length + ") = '" + Prefix + "' " + "Order By Len(CPOM_No) Desc, CPOM_No Desc "; } else { strSQL = "Select Top 1 Right(GPP_No, Len(GPP_No) - " + Prefix.Length + ") As TrNo From PDV_GPP " + "Where GPP_CliId = " + intLocId + " And GPP_No <> '' " + "And Left(GPP_No, " + Prefix.Length + ") = '" + Prefix + "' " + "Order By Len(GPP_No) Desc, GPP_No Desc "; } dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); if (dtDet.Rows.Count > 0) { Numbers = Convert.ToInt32(dtDet.Rows[0]["TrNo"]); } int nextNumber = Numbers + 1; string TrNo = Prefix + nextNumber.ToString("00000"); if (trtype == "canteenmeal") { TrNo = Prefix + nextNumber.ToString("0000000"); } else { TrNo = Prefix + nextNumber.ToString("00000"); } return TrNo; } [HttpPost] public JsonResult GetEmployees(EmployeeObject EO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (EO.apikey != strApiKey || EO.secretkey != strSecretKey) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("employeename", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("employeeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_GetEmployees " + EO.empid + "," + EO.locid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); if (dtDet.Rows.Count > 1 && EO.allreq == "Y") { DataRow row = dtDet.NewRow(); row["employeename"] = "All"; row["employeeid"] = 0; dtDet.Rows.InsertAt(row, 0); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetLeaveType(LeaveTypeObject LT) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (LT.apikey != strApiKey || LT.secretkey != strSecretKey) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("leavetype", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("leavetypeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("minleavedays", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("allowexcessleave", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_GetLeaveType " + LT.empid + ", " + LT.locid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); if (dtDet.Rows.Count > 1 && LT.allreq == "Y") { DataRow row = dtDet.NewRow(); row["leavetype"] = "All"; row["leavetypeid"] = 0; row["minleavedays"] = -1; row["allowexcessleave"] = -1; dtDet.Rows.InsertAt(row, 0); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetGatePassType(GatePassTypeObject GPT) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (GPT.apikey != strApiKey || GPT.secretkey != strSecretKey) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("gatepasstype", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("gatepasstypeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_GetGatePassType " + GPT.empid + "," + GPT.locid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); if (dtDet.Rows.Count > 1 && GPT.allreq == "Y") { DataRow row = dtDet.NewRow(); row["gatepasstype"] = "All"; row["gatepasstypeid"] = 0; dtDet.Rows.InsertAt(row, 0); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult LoginCheck(LoginObject LO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (LO.apikey != strApiKey || LO.secretkey != strSecretKey && (LO.username == "" || LO.username == null || LO.password == "" || LO.password == null)) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("username", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("password", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("employeename", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("employeeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("locationid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("gpsreqd", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("accesstoken", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("usercaption", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; strSQL = "Select EMI.EMI_LoginName As username, EMI.EMI_LoginPwd As password, EMI.EMI_Name As employeename, " + "EMI.EMI_Id As employeeid, EMI.EMI_CliId As locationid, EMI.EMI_GPSReqd AS gpsreqd, " + "'" + strSecretKey + "' As accesstoken, Case When EMI.EMI_Id < -1 Then 'User' Else 'Employee' End usercaption " + "From PDV_EMI EMI Where EMI.EMI_LoginName = '" + LO.username + "' And EMI.EMI_LoginPwd = '" + LO.password + "' "; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); Int32 intEMI_Id; if (dtDet.Rows.Count > 0) { for (int j = 0; j <= dtDet.Rows.Count - 1; j++) { intEMI_Id = Convert.ToInt32(dtDet.Rows[j]["employeeid"]); if (intEMI_Id > 0 || intEMI_Id == -1) { conUpd.Open(); cmd = new SqlCommand("Update MA_EMI Set EMI_DeviceId = '" + LO.device + "' Where EMI_Id = " + intEMI_Id, conUpd); cmd.ExecuteNonQuery(); conUpd.Close(); } else { conUpd.Open(); cmd = new SqlCommand("Update MSA_URD Set URD_DeviceId = '" + LO.device + "' Where URD_Id = " + intEMI_Id, conUpd); cmd.ExecuteNonQuery(); conUpd.Close(); } } } strSQL = "Select EMI.EMI_LoginName As username, EMI.EMI_LoginPwd As password, EMI.EMI_Name As employeename, " + "EMI.EMI_Id As employeeid, EMI.EMI_CliId As locationid, EMI.EMI_GPSReqd AS gpsreqd, " + "'" + strSecretKey + "' As accesstoken, Case When EMI.EMI_Id < -1 Then 'User' Else 'Employee' End usercaption " + "From PDV_EMI EMI Where EMI.EMI_LoginName = '" + LO.username + "' And EMI.EMI_LoginPwd = '" + LO.password + "' "; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); if (dtDet.Rows.Count == 0) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Check Username & Password !"; modelresult.ListDetails = lstReport; } else { modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetUserCompanyAccess(UserCompanyAccessObject UCAO) { var dataConversion = new dataConversiontoJson(); string strSQL; try { DataTable dtUserInfo = new DataTable(); if (UCAO.apikey != strApiKey || UCAO.secretkey != strSecretKey) { dataConversion.cpermission = "notgranted"; dataConversion.cresponse = "Failure"; dataConversion.error = "Credentials not matching"; } else { if (UCAO.roleid == -2) { strSQL = " SELECT cli.CLI_Id AS Location_Id,cli.CLI_Code AS Location_Code,cli.CLI_Name AS Location_Name " + " FROM pdv_cli cli "; } else { strSQL = " SELECT cli.CLI_Id AS Location_Id,cli.CLI_Code AS Location_Code,cli.CLI_Name AS Location_Name " + " FROM pdv_cli cli INNER JOIN (SELECT DISTINCT UAC_CliId AS UAC_CliId FROM MSA_UAC Where UAC_UId = " + UCAO.loginid + " ) uar ON uar.UAC_CliId = cli.CLI_Id; "; } dtUserInfo = new DataTable(); dtUserInfo = fnReturnDt(strSQL); List> lstUserInfo = GetTableRows(dtUserInfo); dataConversion.ListDetails = lstUserInfo; dataConversion.cpermission = "granted"; dataConversion.cresponse = "Success"; dataConversion.error = "Permission Granted Successfully !"; } } catch (Exception ex) { string errorMessage = ex.ToString(); dataConversion.cpermission = "notgranted"; dataConversion.cresponse = "Failure"; dataConversion.error = errorMessage; } var jsonResult = Json(dataConversion, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public JsonResult SendOTP(SendOTPObject SOO) //(string loginkey) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); dtDet = new DataTable(); DataColumn dcP; DataRow drP; dtDet = new DataTable(); dcP = new DataColumn("empid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcP); dcP = new DataColumn("response", Type.GetType("System.String")); dtDet.Columns.Add(dcP); dcP = new DataColumn("username", Type.GetType("System.String")); dtDet.Columns.Add(dcP); dcP = new DataColumn("phoneno", Type.GetType("System.String")); dtDet.Columns.Add(dcP); dcP = new DataColumn("otp", Type.GetType("System.String")); dtDet.Columns.Add(dcP); dcP = new DataColumn("message", Type.GetType("System.String")); dtDet.Columns.Add(dcP); drP = dtDet.NewRow(); drP["empid"] = 0; drP["username"] = ""; drP["phoneno"] = ""; drP["otp"] = ""; drP["response"] = ""; drP["message"] = ""; dtDet.Rows.Add(drP); if (SOO.apikey != strApiKey && SOO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } else { try { SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; SqlCommand cmd; DataTable dtDetSMS = new DataTable(); SqlDataAdapter sdaDet = new SqlDataAdapter(); cmd = new SqlCommand("EXEC TPP_GetSMST " + SOO.locid + ",1;", con); sdaDet.SelectCommand = cmd; dtDetSMS = new DataTable(); sdaDet.Fill(dtDetSMS); con.Close(); if (dtDetSMS.Rows.Count > 0) { DataTable dtDetSql = new DataTable(); string SQLText = Convert.ToString(dtDetSMS.Rows[0]["SMST_SQLText"]); string SMSText = Convert.ToString(dtDetSMS.Rows[0]["SMST_SMSText"]); string MapField = Convert.ToString(dtDetSMS.Rows[0]["SMST_MapField"]); SQLText = SQLText.Replace("{{UserName}}", SOO.username); SQLText = SQLText.Replace("{{Location}}", Convert.ToString(SOO.locid)); cmd = new SqlCommand("" + SQLText + ";", con); sdaDet.SelectCommand = cmd; dtDetSql = new DataTable(); sdaDet.Fill(dtDetSql); con.Close(); if (dtDetSql.Rows.Count > 0) { Int32 EMIId = Convert.ToInt32(dtDetSql.Rows[0]["EMIId"]); string LoginName = Convert.ToString(dtDetSql.Rows[0]["LoginName"]); string PhoneNo = Convert.ToString(dtDetSql.Rows[0]["PhoneNo"]); string OTPRandom = Convert.ToString(dtDetSql.Rows[0]["OTPRandom"]); string IsPhoneNo = Convert.ToString(dtDetSql.Rows[0]["IsPhoneNo"]); if (IsPhoneNo == "N") { dtDet.Rows[0]["empid"] = EMIId; dtDet.Rows[0]["username"] = SOO.username; dtDet.Rows[0]["phoneno"] = ""; dtDet.Rows[0]["otp"] = ""; dtDet.Rows[0]["message"] = "Phone No Does Not Exists"; dtDet.Rows[0]["response"] = "Failure"; List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Phone No Does Not Exists"; modelresult.ListDetails = lstReport; } else { string[] SplitMapField = MapField.Split(','); foreach (string FieldData in SplitMapField) { string[] SplitField = FieldData.Split(';'); string SMSField = "{{" + Convert.ToString(SplitField[0]) + "}}"; string SQLField = Convert.ToString(SplitField[1]); Boolean columnExists = dtDetSql.Columns.Contains(SQLField); if (columnExists == true) { string SQLFieldData = Convert.ToString(dtDetSql.Rows[0][SQLField]); SMSText = SMSText.Replace(SMSField, SQLFieldData); } } DataTable dtDetSMSS = new DataTable(); cmd = new SqlCommand("SELECT * FROM MSA_SMSS Where SMSS_CliId = " + SOO.locid + "; ", con); sdaDet.SelectCommand = cmd; dtDetSMSS = new DataTable(); sdaDet.Fill(dtDetSMSS); if (dtDetSMSS.Rows.Count > 0) { string URL = Convert.ToString(dtDetSMSS.Rows[0]["SMSS_URL"]); string UserName = Convert.ToString(dtDetSMSS.Rows[0]["SMSS_UserName"]); string UserPwd = Convert.ToString(dtDetSMSS.Rows[0]["SMSS_UserPwd"]); string SendFrom = Convert.ToString(dtDetSMSS.Rows[0]["SMSS_SenderName"]); string SendTo = Convert.ToString(dtDetSql.Rows[0]["PhoneNo"]); string SendSMSText = HttpUtility.UrlEncode(Convert.ToString(SMSText)); String SendSMSUrl = URL + '?' + "username=" + UserName + "&password=" + UserPwd + "&to=" + SendTo + "&from=" + SendFrom + "&text=" + SendSMSText + "&dlr-url "; string urlParameters = "username=" + UserName + "&password=" + UserPwd + "&to=" + SendTo + "&from=" + SendFrom + "&text=" + SendSMSText + "&dlr-url"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; var httpWebRequest = (HttpWebRequest)WebRequest.Create(SendSMSUrl); httpWebRequest.Method = "GET"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; // Skip validation of SSL/TLS certificate var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); if (httpResponse.StatusCode == HttpStatusCode.OK) { DataTable dtSMS = new DataTable(); dtSMS = new DataTable(); DataColumn dcSMS; DataRow drSMS; dtSMS = new DataTable(); dcSMS = new DataColumn("SMSL_EmiId", Type.GetType("System.String")); dtSMS.Columns.Add(dcSMS); dcSMS = new DataColumn("SMSL_ToPhoneNo", Type.GetType("System.String")); dtSMS.Columns.Add(dcSMS); dcSMS = new DataColumn("SMSL_Text", Type.GetType("System.String")); dtSMS.Columns.Add(dcSMS); dcSMS = new DataColumn("SMSL_Delivered", Type.GetType("System.String")); dtSMS.Columns.Add(dcSMS); dcSMS = new DataColumn("SMSL_TranNo", Type.GetType("System.String")); dtSMS.Columns.Add(dcSMS); drSMS = dtSMS.NewRow(); drSMS["SMSL_EmiId"] = EMIId; drSMS["SMSL_ToPhoneNo"] = SendTo; drSMS["SMSL_Text"] = SendSMSText; drSMS["SMSL_Delivered"] = "Y"; drSMS["SMSL_TranNo"] = ""; dtSMS.Rows.Add(drSMS); SqlParameter par; cmd = new SqlCommand("SMSL_Save", con); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@TVP_SMSL", SqlDbType.Structured); par.Value = dtSMS; cmd.Parameters.Add(par); con.Open(); cmd.ExecuteNonQuery(); con.Close(); dtDet.Rows[0]["empid"] = EMIId; dtDet.Rows[0]["username"] = LoginName; dtDet.Rows[0]["phoneno"] = PhoneNo; dtDet.Rows[0]["otp"] = OTPRandom; dtDet.Rows[0]["message"] = "OTP Send Sucessfully"; dtDet.Rows[0]["response"] = "Success"; List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "OTP Send Sucessfully"; modelresult.ListDetails = lstReport; } else { dtDet.Rows[0]["empid"] = 0; dtDet.Rows[0]["username"] = ""; dtDet.Rows[0]["phoneno"] = ""; dtDet.Rows[0]["otp"] = ""; dtDet.Rows[0]["message"] = "SMS URL Error"; dtDet.Rows[0]["response"] = "Failure"; List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "SMS URL Error"; modelresult.ListDetails = lstReport; } } else { dtDet.Rows[0]["empid"] = 0; dtDet.Rows[0]["username"] = ""; dtDet.Rows[0]["phoneno"] = ""; dtDet.Rows[0]["otp"] = ""; dtDet.Rows[0]["message"] = "SMS Setting Error"; dtDet.Rows[0]["response"] = "Failure"; List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "SMS Setting Error"; modelresult.ListDetails = lstReport; } } } else { dtDet.Rows[0]["empid"] = 0; dtDet.Rows[0]["username"] = SOO.username; dtDet.Rows[0]["phoneno"] = ""; dtDet.Rows[0]["otp"] = ""; dtDet.Rows[0]["message"] = "User Name Does Not Exists"; dtDet.Rows[0]["response"] = "Failure"; List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "User Name Does Not Exists"; modelresult.ListDetails = lstReport; } } else { dtDet.Rows[0]["empid"] = 0; dtDet.Rows[0]["username"] = ""; dtDet.Rows[0]["phoneno"] = ""; dtDet.Rows[0]["otp"] = ""; dtDet.Rows[0]["message"] = "SMS Template Does Not Exists Please Contact Admin"; dtDet.Rows[0]["response"] = "Failure"; List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "SMS Template Does Not Exists Please Contact Admin"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } catch (Exception ex) { string errMsg = ex.Message.ToString(); dtDet.Rows[0]["empid"] = 0; dtDet.Rows[0]["username"] = ""; dtDet.Rows[0]["phoneno"] = ""; dtDet.Rows[0]["otp"] = ""; dtDet.Rows[0]["message"] = errMsg; dtDet.Rows[0]["response"] = "Failure"; List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errMsg; modelresult.ListDetails = lstReport; var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } } } public JsonResult GetGlobalOptions(GlobalObject GO) { var data = new dataConversiontoJson(); string strSQL; DataTable dtOptions = new DataTable(); if (GO.apikey != strApiKey || GO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtOptions); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.ListDetails = lstReport; } else { strSQL = "EXEC PDV_GetGlobalOptions;"; dtOptions = new DataTable(); dtOptions = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtOptions); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; data.ListDetails = lstReport; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult EmployeeNotificationCount(EmployeeNotificationCountObject ENCO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (ENCO.apikey != strApiKey || ENCO.secretkey != strSecretKey) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("notificationcount", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "Select COUNT(CMD_Status) As notificationcount From MSA_CMD " + "Where CAST(GetDate() AS DATE) Between CAST(CMD_STDate AS Date) And CAST(CMD_EDDate AS DATE) " + "And CMD_Active = 1 AND CMD_EmiId =" + ENCO.loginid + " AND CMD_Status = 0 "; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public JsonResult PushEmployeeNotification(PushNotificationObject PNO) { var modelresult = new dataConversiontoJson(); if (PNO.apikey != strApiKey || PNO.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { String strSQL = " EXEC TPP_PushNotification " + PNO.loginid + ",'" + PNO.title + "','" + PNO.body + "','" + PNO.urllink + "','" + PNO.bodytype + "','" + PNO.startdate + "','" + PNO.enddate + "'," + PNO.locid + "; "; DataTable dtDetData = new DataTable(); dtDetData = new DataTable(); dtDetData = fnReturnDt(strSQL); PushNotifications(dtDetData,PNO.locid); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; //modelresult.ListDetails = pushobject; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public JsonResult EmployeeAuthToken(EmployeeAuthToken EAT) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; if (EAT.apikey != strApiKey || EAT.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { if (EAT.loginid > 0 || EAT.loginid == -1) { conUpd.Open(); cmd = new SqlCommand("Update MA_EMI Set EMI_AuthToken = '" + EAT.authtoken + "' Where EMI_Id = " + EAT.loginid, conUpd); cmd.ExecuteNonQuery(); conUpd.Close(); } modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public void PushNotifications(DataTable dtPushData,Int32 LocationId) { string strSQL = ""; strSQL = " Select OPT_FCMServerKey AS fcmserverkey, OPT_FCMSenderId as fcmsenderid, OPT_FCMUrl as fcmurl " + " From MSA_OPT Where OPT_CliId = "+ LocationId + ""; DataTable dtDetOpt = new DataTable(); dtDetOpt = new DataTable(); dtDetOpt = fnReturnDt(strSQL); string serverKey = Convert.ToString(dtDetOpt.Rows[0]["fcmserverkey"]); string senderId = Convert.ToString(dtDetOpt.Rows[0]["fcmsenderid"]); string webAddr = Convert.ToString(dtDetOpt.Rows[0]["fcmurl"]); if (webAddr != String.Empty && serverKey != String.Empty && webAddr != String.Empty) { for (Int32 i = 0; i < dtPushData.Rows.Count; i++) { string devicetoken = Convert.ToString(dtPushData.Rows[i]["authtoken"]); Int32 NotificationId = Convert.ToInt32(dtPushData.Rows[i]["notificationid"]); string pushresult; var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add(string.Format("Authorization: key={0}", serverKey)); httpWebRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); httpWebRequest.Method = "POST"; var payload = new { to = devicetoken, priority = "high", content_available = true, data = new { title = Convert.ToString(dtPushData.Rows[i]["title"]), body = Convert.ToString(dtPushData.Rows[i]["bodymessage"]), urllink = Convert.ToString(dtPushData.Rows[i]["bodyurl"]), islink = Convert.ToString(dtPushData.Rows[i]["isLink"]), menucode = Convert.ToString(dtPushData.Rows[i]["menucode"]), menuname = Convert.ToString(dtPushData.Rows[i]["menuname"]), transactionid = Convert.ToString(dtPushData.Rows[i]["transactionid"]) }, }; var serializer = new JavaScriptSerializer(); using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = serializer.Serialize(payload); streamWriter.Write(json); streamWriter.Flush(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { pushresult = streamReader.ReadToEnd(); FirebaseNotificationObject NotificationResult = JsonConvert.DeserializeObject(pushresult); if(Convert.ToBoolean(NotificationResult.success)) { SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; conUpd.Open(); cmd = new SqlCommand(" Update MSA_CMD Set CMD_Status = 1 Where CMD_Id = " + NotificationId, conUpd); cmd.ExecuteNonQuery(); conUpd.Close(); } } } } } /*public JsonResult AutoPushNotification(GlobalObject PNO) { var modelresult = new dataConversiontoJson(); if (PNO.apikey != strApiKey || PNO.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { string strSQL = ""; strSQL = " EXEC TPP_AutoPushNotification ; "; DataTable dtDetData = new DataTable(); dtDetData = new DataTable(); dtDetData = fnReturnDt(strSQL); PushNotifications(dtDetData); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; //modelresult.ListDetails = dictionary; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; }*/ public void AutoPushNotification(Int32 LocId) { string strSQL = ""; strSQL = " EXEC TPP_AutoPushNotification ; "; DataTable dtDetData = new DataTable(); dtDetData = new DataTable(); dtDetData = fnReturnDt(strSQL); PushNotifications(dtDetData,LocId); } public JsonResult ByModule(ModuleObject MO) { //var moduleResults = new List(); DataTable dtModules = new DataTable(); string strSQL; string strMainSQL; strMainSQL = ""; strSQL = "EXEC TPP_GetModules " + MO.empid + ", " + MO.locid + ";"; dtModules = new DataTable(); dtModules = fnReturnDt(strSQL); foreach (DataRow modulerow in dtModules.Rows) { strSQL = "" + modulerow["modulename"].ToString() + " = JSON_QUERY( " + "( " + "Select Distinct FLI.FLI_Id As menuid, " + "FLI.FLI_Code As menucode, FLIM.FLIM_Name As menuname, " + "UAR.UAR_View As viewmode, UAR.UAR_Add As addmode, " + "UAR.UAR_Edit As editmode, UAR.UAR_Delete As deletemode, " + "UAR.UAR_Print As printmode " + "From PDV_FLIM FLIM Inner Join PDV_FLI FLI On FLIM.FLIM_Id = FLI.FLI_FlimId " + "Inner Join PDV_UAR UAR On UAR.UAR_FliId = FLI.FLI_Id " + "Where UAR.UAR_UId = " + MO.empid.ToString() + " " + "And UAR.UAR_CliId = " + MO.locid.ToString() + " " + "And FLIM.FLIM_Name = '" + modulerow["modulename"].ToString() + "' " + "FOR JSON PATH " + ") " + "), "; if (strMainSQL == "") { strMainSQL = strSQL; } else { strMainSQL = strMainSQL + strSQL; } } strMainSQL = strMainSQL.Remove(strMainSQL.Length - 2); strMainSQL = "Select " + strMainSQL + " FOR JSON PATH, WITHOUT_ARRAY_WRAPPER;"; var result = fnReturnString(strMainSQL); var jsonResult = Json(result, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } private string SanitizeReceivedJson(string uglyJson) { var sb = new StringBuilder(uglyJson); sb.Replace("\\\t", "\t"); sb.Replace("\\\n", "\n"); sb.Replace("\\\r", "\r"); //sb.Replace("\", ""); return sb.ToString(); } [HttpPost] public JsonResult GetOption(OptionObject OO) { var data = new dataConversiontoJson(); try { string strSQL; DataTable dtOptions = new DataTable(); if (OO.apikey != strApiKey || OO.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { strSQL = "EXEC TPP_GetOptionInfo " + OO.locid + ";"; dtOptions = new DataTable(); dtOptions = fnReturnDt(strSQL); List> lstOptions = GetTableRows(dtOptions); data.ListDetails = lstOptions; data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; } } catch (Exception ex) { string errorMessage = ex.ToString(); data.cpermission = "granted"; data.cresponse = "Success"; data.error = errorMessage; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetUserInfo(UserInfoObject UIO) { var data = new dataConversiontoJson(); try { string strSQL; DataTable dtUserInfo = new DataTable(); if (UIO.apikey != strApiKey || UIO.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { strSQL = "EXEC TPP_GetUserInfo " + UIO.loginid + ";"; dtUserInfo = new DataTable(); dtUserInfo = fnReturnDt(strSQL); List> lstUserInfo = GetTableRows(dtUserInfo); data.ListDetails = lstUserInfo; data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; } } catch (Exception ex) { string errorMessage = ex.ToString(); data.cpermission = "granted"; data.cresponse = "Success"; data.error = errorMessage; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetUserRoleAccess(UserRoleAccessObject URAO) { var data = new dataConversiontoJson(); try { string strSQL; DataTable dtModules = new DataTable(); if (URAO.apikey != strApiKey || URAO.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { String ServerHostIPAddress = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_HOST"]; String ProtocolName = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTPS"]) == "off" ? "http" : "https"; String IconsPath = "" + ProtocolName + "://" + ServerHostIPAddress + "/icons/"; strSQL = "EXEC TPP_GetRoleAccess " + URAO.loginid + ","+URAO.locid +","+URAO.roleid+", 0;"; dtModules = new DataTable(); dtModules = fnReturnDt(strSQL); DataColumn dcModule; dcModule = new DataColumn("menudata", Type.GetType("System.String")); dtModules.Columns.Add(dcModule); foreach (DataRow drModules in dtModules.Rows) { Int32 ModulesId = Convert.ToInt32(drModules["moduleid"]); String ModulesIconFullPathName = String.IsNullOrEmpty(Convert.ToString(drModules["moduleicon"])) == true ? "" : IconsPath + "" + Convert.ToString(drModules["moduleicon"]); drModules["moduleicon"] = ModulesIconFullPathName; DataTable dtMenus = new DataTable(); strSQL = "EXEC TPP_GetRoleAccess " + URAO.loginid + "," + URAO.locid + "," + URAO.roleid + ","+ ModulesId + ";"; dtMenus = new DataTable(); dtMenus = fnReturnDt(strSQL); foreach (DataRow drMenu in dtMenus.Rows) { String IconFullPathName = String.IsNullOrEmpty(Convert.ToString(drMenu["menuicon"])) == true ? "" : IconsPath + "" + Convert.ToString(drMenu["menuicon"]); drMenu["menuicon"] = IconFullPathName; } List> MenuDetails = new List>(); MenuDetails = GetTableRows(dtMenus); var jsonserializer = new JavaScriptSerializer(); drModules["menudata"] = jsonserializer.Serialize(MenuDetails); } List> lstModuleInfo = GetTableRows(dtModules); data.ListDetails = lstModuleInfo; data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; } } catch (Exception ex) { string errorMessage = ex.ToString(); data.cpermission = "granted"; data.cresponse = "Success"; data.error = errorMessage; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetDashboard(DashboardObject DO) { var data = new DashBoardDetails(); string strSQL; DataTable dtImageSlider = new DataTable(); if (DO.apikey != strApiKey || DO.secretkey != strSecretKey) { List> lstImageSlider = GetTableRows(dtImageSlider); data.ImageSlider = lstImageSlider; data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { strSQL = "EXEC TPP_GetImageSlider " + DO.empid + ", " + DO.locid + ";"; dtImageSlider = new DataTable(); dtImageSlider = fnReturnDt(strSQL); List> lstImageSlider = GetTableRows(dtImageSlider); data.ImageSlider = lstImageSlider; data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public JsonResult NotificationInfo(NotificationObject NO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (NO.apikey != strApiKey || NO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { if (NO.status > 0) { SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; conUpd.Open(); cmd = new SqlCommand(" Update MSA_CMD Set CMD_Status = 1 Where CMD_Active = 1 AND CMD_Status = 0 AND CMD_EmiId =" + NO.loginid, conUpd); cmd.ExecuteNonQuery(); conUpd.Close(); } strSQL = "EXEC TPP_GetNotifications " + NO.loginid + ", " + NO.locid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult AttMonYear(GlobalObject GO) { var data = new AttMonthyearDetails(); string strSQL; DataTable dtAttMonYear = new DataTable(); if (GO.apikey != strApiKey || GO.secretkey != strSecretKey) { List> lstAttMonYear = GetTableRows(dtAttMonYear); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.AttMonthyear = lstAttMonYear; } else { strSQL = "EXEC TPP_MonthAndYear ;"; dtAttMonYear = new DataTable(); dtAttMonYear = fnReturnDt(strSQL); List> lstAttMonYear = GetTableRows(dtAttMonYear); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; data.AttMonthyear = lstAttMonYear; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult AttHashColor(GlobalObject GO) { var data = new dataConversiontoJson(); string strSQL; DataTable dtDet = new DataTable(); if (GO.apikey != strApiKey || GO.secretkey != strSecretKey) { List> lstData = GetTableRows(dtDet); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.ListDetails = lstData; } else { strSQL = "EXEC TPP_AttHashColor ;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstData = GetTableRows(dtDet); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; data.ListDetails = lstData; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult AttendanceInfo(AttInfoObject ATO) { var data = new AttendanceDetails(); string strSQL; DataTable dtAttInfo = new DataTable(); if (ATO.apikey != strApiKey || ATO.secretkey != strSecretKey) { List> lstAttInfo = GetTableRows(dtAttInfo); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.AttedanceInfo = lstAttInfo; } else { strSQL = "EXEC TPP_AttInfo " + ATO.loginid + "," + ATO.locid + ",'" + ATO.attmonth + "','" + ATO.attyear + "';"; dtAttInfo = new DataTable(); dtAttInfo = fnReturnDt(strSQL); List> lstAttInfo = GetTableRows(dtAttInfo); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; data.AttedanceInfo = lstAttInfo; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult AttendanceApprovalInfo(AttObject ATO) { var data = new AttendanceDetails(); string strSQL; DataTable dtAttInfo = new DataTable(); string startdate = GenerateDateFormat(ATO.startdate, ATO.locid); string enddate = GenerateDateFormat(ATO.enddate, ATO.locid); strSQL = "EXEC TPP_GetAttAppPending " + ATO.loginid + "," + ATO.locid + ",'" + startdate + "','" + enddate + "';"; dtAttInfo = new DataTable(); dtAttInfo = fnReturnDt(strSQL); List> lstAttInfo = GetTableRows(dtAttInfo); if (ATO.apikey != strApiKey || ATO.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; } data.AttedanceInfo = lstAttInfo; //var result = Newtonsoft.Json.JsonConvert.SerializeObject(data); var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult ApproveAttendance(AttAppObject ATA) { var data = new dataConversiontoJson(); if (ATA.apikey != strApiKey || ATA.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { data.cpermission = "granted"; data.cresponse = "Success"; //data.error = ATA.status + " Successfully !"; data.error = "Status changed Successfully."; SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; DataColumn dcDet; DataRow drDet; DataTable dtDet; dtDet = new DataTable(); dcDet = new DataColumn("empid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("locid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("loginid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("attid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("compname", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("status", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("remarks", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("appdate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); string[] leavedata1; string[] leavedata2; string[] leavedata3; if (ATA.attappdetails.Length > 0) { leavedata1 = ATA.attappdetails.Replace("},", "*").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "").Split('*'); for (int j = 0; j <= leavedata1.Count() - 1; j++) { leavedata2 = leavedata1[j].Split(','); drDet = dtDet.NewRow(); drDet["locid"] = ATA.locid; drDet["loginid"] = ATA.loginid; drDet["compname"] = Dns.GetHostName(); drDet["appdate"] = GenerateDateFormat(ATA.appdate, ATA.locid); for (int k = 0; k <= leavedata2.Count() - 1; k++) { leavedata3 = leavedata2[k].Replace("\"", "").Split(':'); if (leavedata3[0] == "empid") { drDet["empid"] = leavedata3[1]; } if (leavedata3[0] == "attid") { drDet["attid"] = leavedata3[1]; } if (leavedata3[0] == "status") { drDet["status"] = leavedata3[1]; } if (leavedata3[0] == "remarks") { drDet["remarks"] = leavedata3[1]; } } dtDet.Rows.Add(drDet); } } SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_ATTStatus", con); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@TVP_ATA", SqlDbType.Structured); par.Value = dtDet; cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@empid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = ATA.empid; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@loginid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = ATA.loginid; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@locid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = ATA.locid; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@Status";// Defining Name ////par.SqlDbType = SqlDbType.NVarChar; // Defining DataType ////par.Size = 10; ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = ATA.status; // Request.status; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@Remarks";// Defining Name ////par.SqlDbType = SqlDbType.NVarChar; // Defining DataType ////par.Size = 150; ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = ATA.remarks; // Request.remarks; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@Comp";// Defining Name ////par.SqlDbType = SqlDbType.NVarChar; // Defining DataType ////par.Size = 200; ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = Dns.GetHostName(); // Request.UserHostName; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@AppDate";// Defining Name ////par.SqlDbType = SqlDbType.DateTime; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = ATA.appdate; // Request.AppDate; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@AttDate";// Defining Name ////par.SqlDbType = SqlDbType.Date; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = ATA.attdate; // Request.AppDate; ////cmd.Parameters.Add(par); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } //var result = Newtonsoft.Json.JsonConvert.SerializeObject(data); var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetLeaveBal(LeaveBalanceObject LB) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (LB.apikey != strApiKey || LB.secretkey != strSecretKey) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("leavetypeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("leavetype", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("leavedays", Type.GetType("System.Decimal")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { string startdate = GenerateDateFormat(LB.startdate, LB.locid); string enddate = GenerateDateFormat(LB.enddate, LB.locid); strSQL = "EXEC TPP_GetLeaveBal " + LB.loginid + "," + LB.locid + "," + LB.leavetypeid + ",'" + startdate + "','" + enddate + "';"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult LeaveAppply(LeaveApplyObject LA) { var data = new dataConversiontoJson(); string strSQL; DataTable dtEmployeeInfo = new DataTable(); DataTable dtLeaveInfo = new DataTable(); DataTable dtAttInfo = new DataTable(); if (LA.apikey != strApiKey || LA.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { Int32 EmployeeReportingId = 0; strSQL = "select EMI_REmiId AS EMI_REmiId from PDV_EMI Where EMI_Id = " + LA.empid + ";"; dtEmployeeInfo = new DataTable(); dtEmployeeInfo = fnReturnDt(strSQL); if (dtEmployeeInfo.Rows.Count > 0) { EmployeeReportingId = Convert.ToInt32(dtEmployeeInfo.Rows[0]["EMI_REmiId"]); } if (EmployeeReportingId == 0) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = " Leave application not save please set Reporting Manager"; } else { string[] leave_data1; string[] leave_data2; string[] leave_data3; string fromdate = ""; string todate = ""; string isHD = ""; string isHDType = ""; string leave_appno = ""; string leave_attinfo = ""; if (LA.leaveappdetails.Length > 0) { leave_data1 = LA.leaveappdetails.Replace("},", "*").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "").Split('*'); for (int j = 0; j <= leave_data1.Count() - 1; j++) { leave_data2 = leave_data1[j].Split(','); for (int k = 0; k <= leave_data2.Count() - 1; k++) { leave_data3 = leave_data2[k].Replace("\"", "").Split(':'); if (leave_data3[0] == "fromdate") { fromdate = GenerateDateFormat(leave_data3[1], LA.locid); } if (leave_data3[0] == "todate") { todate = GenerateDateFormat(leave_data3[1], LA.locid); } if (leave_data3[0] == "halfaday") { isHD = leave_data3[1]; } if (leave_data3[0] == "halfadaytype") { isHDType = leave_data3[1]; } } int ldays = Convert.ToDateTime(todate).Subtract(Convert.ToDateTime(fromdate)).Days + 1; for (int ld = 0; ld <= ldays - 1; ld++) { fromdate = Convert.ToString(Convert.ToDateTime(fromdate).AddDays(ld).ToString("yyyy-MM-dd")); string leavedate = GenerateDateFormat(fromdate, LA.locid); strSQL = "EXEC TPP_GetLeaveApplied " + LA.empid + "," + LA.locid + ",'" + leavedate + "';"; dtLeaveInfo = new DataTable(); dtLeaveInfo = fnReturnDt(strSQL); if (dtLeaveInfo.Rows.Count > 0) { leave_appno = dtLeaveInfo.Rows[0]["leaveappno"].ToString(); } strSQL = "EXEC TPP_CheckAttExists " + LA.empid + "," + LA.locid + ",'" + leavedate + "','" + isHD + "','" + isHDType + "';"; dtAttInfo = new DataTable(); dtAttInfo = fnReturnDt(strSQL); if (dtAttInfo.Rows.Count > 0) { leave_attinfo = dtAttInfo.Rows[0]["attinfo"].ToString(); } } } } if (leave_appno != "" || leave_attinfo != "") { if (leave_appno != "") { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Leave application " + leave_appno + " is already available"; } else { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = leave_attinfo; } } else { string LeaveAppNo; LeaveAppNo = ""; LeaveAppNo = GenerateTrNo(LA.locid, "leaveapply"); DataColumn dcDet; DataRow drDet; DataTable dtDet; dtDet = new DataTable(); dcDet = new DataColumn("leaveno", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("leavedate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("reqdate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("empid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("locid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("compname", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("leavetypeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("fromdate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("todate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("leavereason", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("halfaday", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("halfadaytype", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); string[] leavedata1; string[] leavedata2; string[] leavedata3; if (LA.leaveappdetails.Length > 0) { leavedata1 = LA.leaveappdetails.Replace("},", "*").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "").Split('*'); for (int j = 0; j <= leavedata1.Count() - 1; j++) { leavedata2 = leavedata1[j].Split(','); drDet = dtDet.NewRow(); drDet["leaveno"] = LeaveAppNo; drDet["leavedate"] = GenerateDateFormat(LA.leavedate, LA.locid); drDet["reqdate"] = GenerateDateFormat(LA.reqdate, LA.locid); drDet["empid"] = LA.empid; drDet["locid"] = LA.locid; drDet["compname"] = Dns.GetHostName(); for (int k = 0; k <= leavedata2.Count() - 1; k++) { leavedata3 = leavedata2[k].Replace("\"", "").Split(':'); if (leavedata3[0] == "leavetypeid") { drDet["leavetypeid"] = leavedata3[1]; } if (leavedata3[0] == "fromdate") { drDet["fromdate"] = GenerateDateFormat(leavedata3[1], LA.locid); } if (leavedata3[0] == "todate") { drDet["todate"] = GenerateDateFormat(leavedata3[1], LA.locid); } if (leavedata3[0] == "leavereason") { drDet["leavereason"] = leavedata3[1]; } if (leavedata3[0] == "halfaday") { drDet["halfaday"] = leavedata3[1]; } if (leavedata3[0] == "halfadaytype") { drDet["halfadaytype"] = leavedata3[1]; } } dtDet.Rows.Add(drDet); } } else { drDet = dtDet.NewRow(); drDet["leaveno"] = LeaveAppNo; drDet["leavedate"] = GenerateDateFormat(LA.leavedate, LA.locid); drDet["reqdate"] = GenerateDateFormat(LA.reqdate, LA.locid); drDet["empid"] = LA.empid; drDet["locid"] = LA.locid; drDet["compname"] = Dns.GetHostName(); drDet["leavetypeid"] = 0; drDet["fromdate"] = ""; drDet["todate"] = ""; drDet["leavereason"] = ""; drDet["halfaday"] = ""; drDet["halfadaytype"] = ""; dtDet.Rows.Add(drDet); } SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_LeaveApply", con); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@TVP_LAP", SqlDbType.Structured); par.Value = dtDet; cmd.Parameters.Add(par); con.Open(); cmd.ExecuteNonQuery(); con.Close(); AutoPushNotification(LA.locid); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Saved Successfully !"; } } } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult LeaveApprovalInfo(AttObject LAO) { var data = new AttendanceDetails(); string strSQL; DataTable dtAppInfo = new DataTable(); string startdate = GenerateDateFormat(LAO.startdate, LAO.locid); string enddate = GenerateDateFormat(LAO.enddate, LAO.locid); if (LAO.apikey != strApiKey || LAO.secretkey != strSecretKey) { List> lstLeaveAppInfo = GetTableRows(dtAppInfo); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.AttedanceInfo = lstLeaveAppInfo; } else { strSQL = "EXEC TPP_GetLeaveAppPending " + LAO.loginid + "," + LAO.locid + ",'" + startdate + "','" + enddate + "';"; dtAppInfo = new DataTable(); dtAppInfo = fnReturnDt(strSQL); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; List> lstLeaveAppInfo = GetTableRows(dtAppInfo); data.AttedanceInfo = lstLeaveAppInfo; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult LeaveDetailsInfo(AttObject LAO) { var data = new CommonDetails(); string strSQL; DataTable dtAppInfo = new DataTable(); string startdate = GenerateDateFormat(LAO.startdate, LAO.locid); string enddate = GenerateDateFormat(LAO.enddate, LAO.locid); if (LAO.apikey != strApiKey || LAO.secretkey != strSecretKey) { List> lstLeaveDetInfo = GetTableRows(dtAppInfo); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.DataInfo = lstLeaveDetInfo; } else { strSQL = "EXEC TPP_GetLeaveAppDetails " + LAO.loginid + "," + LAO.locid + ",'" + startdate + "','" + enddate + "';"; dtAppInfo = new DataTable(); dtAppInfo = fnReturnDt(strSQL); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; List> lstLeaveDetInfo = GetTableRows(dtAppInfo); data.DataInfo = lstLeaveDetInfo; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult LeaveDetails(LeaveApprovalDetailsObject LPDO) { var data = new AttendanceDetails(); string strSQL; DataTable dtAppInfo = new DataTable(); if (LPDO.apikey != strApiKey || LPDO.secretkey != strSecretKey) { List> lstLeaveAppInfo = GetTableRows(dtAppInfo); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.AttedanceInfo = lstLeaveAppInfo; } else { strSQL = "EXEC TPP_GetLeaveDetails " + LPDO.loginid + "," + LPDO.locid + "," + LPDO.leaveid + ";"; dtAppInfo = new DataTable(); dtAppInfo = fnReturnDt(strSQL); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; List> lstLeaveAppInfo = GetTableRows(dtAppInfo); data.AttedanceInfo = lstLeaveAppInfo; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult ApproveLeave(LeaveAppObject LAA) { var data = new dataConversiontoJson(); //string strSQL; DataTable dtAttInfo = new DataTable(); //string leavedate = GenerateDateFormat(LAA.leavedate, 1); //strSQL = "EXEC TPP_GetLeaveAppPending " + LAA.loginid + ",'" + leavedate + "';"; //dtAttInfo = new DataTable(); //dtAttInfo = fnReturnDt(strSQL); if (LAA.apikey != strApiKey || LAA.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { data.cpermission = "granted"; data.cresponse = "Success"; //data.error = LAA.status + " Successfully !"; data.error = "Status changed Successfully !"; SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; DataColumn dcDet; DataRow drDet; DataTable dtDet; dtDet = new DataTable(); dcDet = new DataColumn("empid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("locid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("loginid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("lapid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("ladid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("compname", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("status", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("remarks", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("appdate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); string[] leavedata1; string[] leavedata2; string[] leavedata3; if (LAA.leaveappdetails.Length > 0) { leavedata1 = LAA.leaveappdetails.Replace("},", "*").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "").Split('*'); for (int j = 0; j <= leavedata1.Count() - 1; j++) { leavedata2 = leavedata1[j].Split(','); drDet = dtDet.NewRow(); drDet["locid"] = LAA.locid; drDet["loginid"] = LAA.loginid; drDet["compname"] = Dns.GetHostName(); drDet["appdate"] = GenerateDateFormat(LAA.appdate, LAA.locid); for (int k = 0; k <= leavedata2.Count() - 1; k++) { leavedata3 = leavedata2[k].Replace("\"", "").Split(':'); if (leavedata3[0] == "empid") { drDet["empid"] = leavedata3[1]; } if (leavedata3[0] == "lapid") { drDet["lapid"] = leavedata3[1]; } if (leavedata3[0] == "ladid") { drDet["ladid"] = leavedata3[1]; } if (leavedata3[0] == "status") { drDet["status"] = leavedata3[1]; } if (leavedata3[0] == "remarks") { drDet["remarks"] = leavedata3[1]; } } dtDet.Rows.Add(drDet); } } SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_LeaveStatus", con); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@TVP_LAA", SqlDbType.Structured); par.Value = dtDet; cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@empid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.empid; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@loginid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.loginid; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@locid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.locid; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@lapid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.lapid; // Request.AppDate; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@ladid";// Defining Name ////par.SqlDbType = SqlDbType.Int; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.ladid; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@Status";// Defining Name ////par.SqlDbType = SqlDbType.NVarChar; // Defining DataType ////par.Size = 10; ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.status; // Request.status; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@Remarks";// Defining Name ////par.SqlDbType = SqlDbType.NVarChar; // Defining DataType ////par.Size = 150; ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.remarks; // Request.remarks; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@Comp";// Defining Name ////par.SqlDbType = SqlDbType.NVarChar; // Defining DataType ////par.Size = 200; ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = Dns.GetHostName(); // Request.UserHostName; ////cmd.Parameters.Add(par); ////par = new SqlParameter(); ////par.ParameterName = "@AppDate";// Defining Name ////par.SqlDbType = SqlDbType.Date; // Defining DataType ////par.Direction = ParameterDirection.Input; // Setting the direction ////par.Value = LAA.appdate; // Request.AppDate; ////cmd.Parameters.Add(par); con.Open(); cmd.ExecuteNonQuery(); con.Close(); AutoPushNotification(LAA.locid); } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GatePassApply(GatePassApplyObject GPA) { var data = new dataConversiontoJson(); string strSQL; DataTable dtGatePassInfo = new DataTable(); DataTable dtEmployeeInfo = new DataTable(); if (GPA.apikey != strApiKey || GPA.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { string gpsdate = GenerateDateFormat(GPA.gpsdate, GPA.locid); /*strSQL = "EXEC TPP_GetGatePassApplied " + GPA.empid + "," + GPA.locid + ",'" + gpsdate + "';"; dtGatePassInfo = new DataTable(); dtGatePassInfo = fnReturnDt(strSQL); if (dtGatePassInfo.Rows.Count > 0) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Gatepass application is already available"; } else {*/ Int32 EmployeeReportingId = 0; strSQL = "select EMI_REmiId AS EMI_REmiId from PDV_EMI Where EMI_Id = " + GPA.empid + ";"; dtEmployeeInfo = new DataTable(); dtEmployeeInfo = fnReturnDt(strSQL); if (dtEmployeeInfo.Rows.Count > 0) { EmployeeReportingId = Convert.ToInt32(dtEmployeeInfo.Rows[0]["EMI_REmiId"]); } if (EmployeeReportingId == 0) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = " Gate pass not save please set Reporting Manager"; } else { string LeaveAppNo; LeaveAppNo = ""; LeaveAppNo = GenerateTrNo(GPA.locid, "gatepassapply"); DataColumn dcDet; DataRow drDet; DataTable dtDet; dtDet = new DataTable(); dcDet = new DataColumn("gatepassno", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("gatepassdate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("reqdate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("empid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("locid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("compname", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("gatepasstypeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("fromtime", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("totime", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("gatepassreason", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); string[] leavedata1; string[] leavedata2; string[] leavedata3; if (GPA.gatepassappdetails.Length > 0) { leavedata1 = GPA.gatepassappdetails.Replace("},", "*").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "").Split('*'); for (int j = 0; j <= leavedata1.Count() - 1; j++) { leavedata2 = leavedata1[j].Split(','); drDet = dtDet.NewRow(); drDet["gatepassno"] = LeaveAppNo; drDet["gatepassdate"] = GenerateDateFormat(GPA.gpsdate, GPA.locid); drDet["reqdate"] = GenerateDateFormat(GPA.reqdate, GPA.locid); drDet["empid"] = GPA.empid; drDet["locid"] = GPA.locid; drDet["compname"] = Dns.GetHostName(); for (int k = 0; k <= leavedata2.Count() - 1; k++) { leavedata3 = leavedata2[k].Replace("\"", "").Split(':'); if (leavedata3[0] == "gatepasstypeid") { drDet["gatepasstypeid"] = leavedata3[1]; } if (leavedata3[0] == "fromtime") { if (leavedata3.Length > 2) { drDet["fromtime"] = leavedata3[1] + ":" + leavedata3[2];// GenerateDateFormat(leavedata3[1], GPA.locid); } else { drDet["fromtime"] = leavedata3[1];// GenerateDateFormat(leavedata3[1], GPA.locid); } } if (leavedata3[0] == "totime") { if (leavedata3.Length > 2) { drDet["totime"] = leavedata3[1] + ":" + leavedata3[2];// GenerateDateFormat(leavedata3[1], GPA.locid); } else { drDet["totime"] = leavedata3[1];// GenerateDateFormat(leavedata3[1], GPA.locid); } } if (leavedata3[0] == "gatepassreason") { drDet["gatepassreason"] = leavedata3[1]; } } dtDet.Rows.Add(drDet); } } else { drDet = dtDet.NewRow(); drDet["gatepassno"] = LeaveAppNo; drDet["gatepassdate"] = GenerateDateFormat(GPA.gpsdate, GPA.locid); drDet["reqdate"] = GenerateDateFormat(GPA.reqdate, GPA.locid); drDet["empid"] = GPA.empid; drDet["locid"] = GPA.locid; drDet["compname"] = Dns.GetHostName(); drDet["gatepasstypeid"] = 0; drDet["fromtime"] = ""; drDet["totime"] = ""; drDet["gatepassreason"] = ""; dtDet.Rows.Add(drDet); } SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_GatePassApply", con); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@TVP_GPP", SqlDbType.Structured); par.Value = dtDet; cmd.Parameters.Add(par); con.Open(); cmd.ExecuteNonQuery(); con.Close(); AutoPushNotification(GPA.locid); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Saved Successfully !"; //} } } //var result = Newtonsoft.Json.JsonConvert.SerializeObject(dtGatePassInfo); var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GatePassInfo(AttObject GPI) { var data = new AttendanceDetails(); string strSQL; DataTable dtAppInfo = new DataTable(); if (GPI.apikey != strApiKey || GPI.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; List> lstLeaveAppInfo = GetTableRows(dtAppInfo); data.AttedanceInfo = lstLeaveAppInfo; } else { string startdate = GenerateDateFormat(GPI.startdate, GPI.locid); string enddate = GenerateDateFormat(GPI.enddate, GPI.locid); strSQL = "EXEC TPP_GetGatePassAppPending " + GPI.loginid + "," + GPI.locid + ",'" + startdate + "','" + enddate + "';"; dtAppInfo = new DataTable(); dtAppInfo = fnReturnDt(strSQL); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; List> lstLeaveAppInfo = GetTableRows(dtAppInfo); data.AttedanceInfo = lstLeaveAppInfo; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GatePassDetailsInfo(AttObject LAO) { var data = new CommonDetails(); string strSQL; DataTable dtAppInfo = new DataTable(); string startdate = GenerateDateFormat(LAO.startdate, LAO.locid); string enddate = GenerateDateFormat(LAO.enddate, LAO.locid); if (LAO.apikey != strApiKey || LAO.secretkey != strSecretKey) { List> lstDetInfo = GetTableRows(dtAppInfo); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.DataInfo = lstDetInfo; } else { strSQL = "EXEC TPP_GetGatePassAppDetails " + LAO.loginid + "," + LAO.locid + ",'" + startdate + "','" + enddate + "';"; dtAppInfo = new DataTable(); dtAppInfo = fnReturnDt(strSQL); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; List> lstDetInfo = GetTableRows(dtAppInfo); data.DataInfo = lstDetInfo; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GatepassDetails(GatepassApprovalDetailsObject GADO) { var data = new AttendanceDetails(); string strSQL; DataTable dtAppInfo = new DataTable(); if (GADO.apikey != strApiKey || GADO.secretkey != strSecretKey) { List> lstGatepassAppInfo = GetTableRows(dtAppInfo); data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; data.AttedanceInfo = lstGatepassAppInfo; } else { strSQL = "EXEC TPP_GetGatepassDetails " + GADO.loginid + "," + GADO.locid + "," + GADO.gatepassid + ";"; dtAppInfo = new DataTable(); dtAppInfo = fnReturnDt(strSQL); data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Permission Granted Successfully !"; List> lstGatepassAppInfo = GetTableRows(dtAppInfo); data.AttedanceInfo = lstGatepassAppInfo; } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult ApproveGatePass(GatePassAppObject GPA) { var data = new dataConversiontoJson(); //string strSQL; DataTable dtGatePassInfo = new DataTable(); if (GPA.apikey != strApiKey || GPA.secretkey != strSecretKey) { data.cpermission = "notgranted"; data.cresponse = "Failure"; data.error = "Credentials not matching"; } else { data.cpermission = "granted"; data.cresponse = "Success"; data.error = "Status changed Successfully !"; SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; con.ConnectionString = connectionstring; DataColumn dcDet; DataRow drDet; DataTable dtDet; dtDet = new DataTable(); dcDet = new DataColumn("empid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("locid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("loginid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("gppid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("gpdid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("compname", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("status", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("remarks", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("appdate", Type.GetType("System.DateTime")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); string[] leavedata1; string[] leavedata2; string[] leavedata3; if (GPA.gatepassappdetails.Length > 0) { leavedata1 = GPA.gatepassappdetails.Replace("},", "*").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "").Split('*'); for (int j = 0; j <= leavedata1.Count() - 1; j++) { leavedata2 = leavedata1[j].Split(','); drDet = dtDet.NewRow(); drDet["locid"] = GPA.locid; drDet["loginid"] = GPA.loginid; drDet["compname"] = Dns.GetHostName(); drDet["appdate"] = GenerateDateFormat(GPA.appdate, GPA.locid); for (int k = 0; k <= leavedata2.Count() - 1; k++) { leavedata3 = leavedata2[k].Replace("\"", "").Split(':'); if (leavedata3[0] == "empid") { drDet["empid"] = leavedata3[1]; } if (leavedata3[0] == "gppid") { drDet["gppid"] = leavedata3[1]; } if (leavedata3[0] == "gpdid") { drDet["gpdid"] = leavedata3[1]; } if (leavedata3[0] == "status") { drDet["status"] = leavedata3[1]; } if (leavedata3[0] == "remarks") { drDet["remarks"] = leavedata3[1]; } } dtDet.Rows.Add(drDet); } } SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_GatePassStatus", con); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@TVP_GPA", SqlDbType.Structured); par.Value = dtDet; cmd.Parameters.Add(par); con.Open(); cmd.ExecuteNonQuery(); con.Close(); AutoPushNotification(GPA.locid); } var jsonResult = Json(data, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public static void ErrorMessageSave(String psdetails, String ErrorMsg) { string strSQL = ""; strSQL = "EXEC TPP_MSALogSave '" + psdetails + "','" + ErrorMsg + "';"; SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; cmd = new SqlCommand(strSQL, conUpd); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); } public JsonResult PayslipGenerated(PayslipGeneratedObject PGO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (PGO.apikey != strApiKey || PGO.secretkey != strSecretKey || (Convert.ToInt32(PGO.empid) == 0)) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("payslipbase64", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("payslipbase64", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); DataTable dtPaySlip = new DataTable(); strSQL = "Select OPTHR_PayslipGenerateURL AS PayslipGeneratedURL From MSA_OPTHR Where OPTHR_CliId = "+PGO.locid+";"; dtPaySlip = new DataTable(); dtPaySlip = fnReturnDt(strSQL); if (dtPaySlip.Rows.Count > 0) { String PayslipGeneratedURL = ""; foreach (DataRow drPaySlip in dtPaySlip.Rows) { PayslipGeneratedURL = Convert.ToString(drPaySlip["PayslipGeneratedURL"]); } if (String.IsNullOrEmpty(PayslipGeneratedURL)) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Please set Payslip Generated URL"; } else { string webAddr = PayslipGeneratedURL; var data = new { SMONTH = PGO.slipmonth, EMPIds = PGO.empid, CLIId = PGO.locid }; var serializer = new JavaScriptSerializer(); string jsonData = serializer.Serialize(data); // Create a request object HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webAddr); // Set the request method to POST request.Method = "POST"; // Set the content type to application/json request.ContentType = "application/json"; // Convert the JSON data to a byte array byte[] byteData = Encoding.UTF8.GetBytes(jsonData); // Set the content length in the request headers request.ContentLength = byteData.Length; string responseText = String.Empty; // Get the request stream and write the data to it using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(byteData, 0, byteData.Length); } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { // Read the response stream using (Stream responseStream = response.GetResponseStream()) { if (responseStream != null) { using (StreamReader reader = new StreamReader(responseStream)) { // Read the entire response responseText = reader.ReadToEnd(); // Display the response Console.WriteLine("Response: " + responseText); } } } } drDet["payslipbase64"] = responseText; dtDet.Rows.Add(drDet); List> lstReport = GetTableRows(dtDet); modelresult.ListDetails = lstReport; modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Payslip Generated Successfully !"; } } else { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Please set Payslip Generated URL"; } } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult ChangePWD(CPWObject CPO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CPO.apikey != strApiKey || CPO.secretkey != strSecretKey || (CPO.loginid == 0)) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("username", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("password", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("employeename", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("employeeid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { if (CPO.oldpwd == "" || CPO.oldpwd == null) { strSQL = "Select EMI.EMI_LoginName As username, EMI.EMI_LoginPwd As password, " + "EMI.EMI_Name As employeename, EMI.EMI_Id As employeeid " + "From PDV_EMI EMI " + "Where EMI.EMI_Id = " + CPO.loginid + " "; } else { strSQL = "Select EMI.EMI_LoginName As username, EMI.EMI_LoginPwd As password, " + "EMI.EMI_Name As employeename, EMI.EMI_Id As employeeid " + "From PDV_EMI EMI " + "Where EMI.EMI_Id = " + CPO.loginid + " And EMI.EMI_LoginPwd = '" + CPO.oldpwd + "' "; } dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); if (dtDet.Rows.Count == 0) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Check your old password"; } else { SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("CPW_Save", conUpd); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter(); par.ParameterName = "@EmiId";// Defining Name par.SqlDbType = SqlDbType.Int; // Defining DataType par.Direction = ParameterDirection.Input; // Setting the direction par.Value = CPO.loginid; cmd.Parameters.Add(par); par = new SqlParameter(); par.ParameterName = "@Pw";// Defining Name par.SqlDbType = SqlDbType.NVarChar; // Defining DataType par.Size = 40; par.Direction = ParameterDirection.Input; // Setting the direction par.Value = CPO.newpwd; // Request.UserHostName; cmd.Parameters.Add(par); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Password Changed Successfully !"; } modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenNameList(CanteenNameListObject CLLO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CLLO.apikey != strApiKey || CLLO.secretkey != strSecretKey) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("canteenname", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("canteennameid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_GetCanteenName " + CLLO.empid + "," + CLLO.locid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); if (dtDet.Rows.Count > 1 && CLLO.allreq == "Y") { DataRow row = dtDet.NewRow(); row["canteenname"] = "All"; row["canteennameid"] = 0; dtDet.Rows.InsertAt(row, 0); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult CanteenNameList(CanteenNameListObject CLLO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CLLO.apikey != strApiKey || CLLO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "Select CTL_Id as canteenid,CTL_Code AS canteencode, CTL_Name AS canteenname,CTL_Description as description,CTL_Active as active,CTL_CliId as locationid from PDV_CTMCTL Where CTL_CliId = " + CLLO.locid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult SaveCanteenName(CanteenNameSaveObject CNSO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); string strSQL; if (CNSO.apikey != strApiKey || CNSO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_SaveCanteenName " + CNSO.canteenid + ",'" + CNSO.canteencode + "','" + CNSO.canteenname + "','" + CNSO.description + "'," + CNSO.active + "," + CNSO.empid + "," + CNSO.locid + ";"; SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; cmd = new SqlCommand(strSQL, conUpd); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Saved Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenName(CanteenNameObject CNO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CNO.apikey != strApiKey || CNO.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { strSQL = "Select CTL_Id as canteenid,CTL_Code AS canteencode, CTL_Name AS canteenname,CTL_Description as description,CTL_Active as active,CTL_CliId as locationid from PDV_CTMCTL Where CTL_Id = " + CNO.canteenid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult DeleteCanteenName(DeleteCanteenNameObject DCNO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); string strSQL; if (DCNO.apikey != strApiKey || DCNO.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { strSQL = "UPDATE CTM_CTL SET CTL_Deleted = 1 Where CTL_Id = " + DCNO.canteenid + ";"; SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; cmd = new SqlCommand(strSQL, conUpd); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Delete Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenItemList(CanteenItemListObject CILO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CILO.apikey != strApiKey || CILO.secretkey != strSecretKey) { DataColumn dcDet; DataRow drDet; dtDet = new DataTable(); dcDet = new DataColumn("itemname", Type.GetType("System.String")); dtDet.Columns.Add(dcDet); dcDet = new DataColumn("itemid", Type.GetType("System.Int32")); dtDet.Columns.Add(dcDet); drDet = dtDet.NewRow(); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "select CRAI_Id AS itemid,CRAI_Code+'| '+CRAI_Name AS itemname from PDV_CTMCRAI;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); if (dtDet.Rows.Count > 1 && CILO.allreq == "Y") { DataRow row = dtDet.NewRow(); row["itemname"] = "All"; row["itemid"] = 0; dtDet.Rows.InsertAt(row, 0); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult CanteenItemList(CanteenItemListObject CILO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CILO.apikey != strApiKey || CILO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "Select CRAI_Id as itemid,CRAI_Code AS itemcode, CRAI_Name AS itemname,CRAI_Description as description,CRAI_Price as price,CRAI_ImagePath as imagepath,CRAI_Image AS image,CRAI_IsDiscount AS isdiscount,CRAI_DLevelAmt1 AS leaveamt1,CRAI_DLevelAmt2 AS leaveamt2,CRAI_DLevelAmt3 AS leaveamt3,CRAI_DLevelAmt4 AS leaveamt4,CRAI_DLevelAmt5 AS leaveamt5,CAST((CRAI_DLevelAmt1 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc1,CAST((CRAI_DLevelAmt2 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc2,CAST((CRAI_DLevelAmt3 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc3,CAST((CRAI_DLevelAmt4 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc4,CAST((CRAI_DLevelAmt5 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc5 from PDV_CTMCRAI ;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenItem(CanteenItemObject CIO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CIO.apikey != strApiKey || CIO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "Select CRAI_Id as itemid,CRAI_Code AS itemcode, CRAI_Name AS itemname,CRAI_Description as description,CRAI_Price as price,CRAI_ImagePath as imagepath,CRAI_Image AS image,CRAI_IsDiscount AS isdiscount,CRAI_DLevelAmt1 AS leaveamt1,CRAI_DLevelAmt2 AS leaveamt2,CRAI_DLevelAmt3 AS leaveamt3,CRAI_DLevelAmt4 AS leaveamt4,CRAI_DLevelAmt5 AS leaveamt5,CAST((CRAI_DLevelAmt1 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc1,CAST((CRAI_DLevelAmt2 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc2,CAST((CRAI_DLevelAmt3 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc3,CAST((CRAI_DLevelAmt4 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc4,CAST((CRAI_DLevelAmt5 * 100)/CRAI_Price AS NUMERIC(18,2)) as leaveperc5 from PDV_CTMCRAI Where CRAI_Id = " + CIO.itemid + " ;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public static string GeneratedImage(byte[] data, string ImgFileName, string ImgFIlePath, string ServerFIlePath) { string serverip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_HOST"]; //string ImgfileNamePath = "http://" + serverip + ImgFIlePath + ImgFileName; using (var ms = new System.IO.MemoryStream(data)) { var image = System.Drawing.Image.FromStream(ms); var width = (int)(image.Width); var height = (int)(image.Height); var newImage = new Bitmap(width, height); Graphics.FromImage(newImage).DrawImage(image, 0, 0, width, height); Bitmap bmp = new Bitmap(newImage); ImageConverter converter = new ImageConverter(); var imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); //return Convert.ToBase64String(imageBytes); //set the image path string imgPath = Path.Combine(ServerFIlePath, ImgFileName); System.IO.File.WriteAllBytes(imgPath, imageBytes); return ServerFIlePath; } } [HttpPost] public JsonResult SaveCanteenItem(CanteenItemSaveObject SCIO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); string strSQL; if (SCIO.apikey != strApiKey || SCIO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { string ImagefilePath = "/CanteenImage/"; String imagepath = String.IsNullOrEmpty(SCIO.imagepath) == true ? ImagefilePath + "default_item.png" : SCIO.imagepath; if (SCIO.image != null && SCIO.image.Length > 0) { string ImagefileName = "Item_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".png"; string ServerfilePath = Server.MapPath("~" + ImagefilePath); //Check if directory exist if (!System.IO.Directory.Exists(ImagefilePath)) { System.IO.Directory.CreateDirectory(ImagefilePath); //Create directory if it doesn't exist } string myImageFilePath = GeneratedImage(SCIO.image, ImagefileName, ImagefilePath, ServerfilePath); imagepath = myImageFilePath; } else { SCIO.image = null; } strSQL = "EXEC TPP_SaveCanteenItem " + SCIO.itemid + ",'" + SCIO.itemcode + "','" + SCIO.itemname + "','" + SCIO.description + "'," + SCIO.active + ",'" + SCIO.price + "','" + imagepath + "','" + SCIO.image + "'," + SCIO.isdiscount + ",'" + SCIO.levelamt1 + "','" + SCIO.levelamt2 + "','" + SCIO.levelamt3 + "','" + SCIO.levelamt4 + "','" + SCIO.levelamt5 + "'," + SCIO.empid + "," + SCIO.locid + ";"; SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; cmd = new SqlCommand(strSQL, conUpd); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Saved Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult DeleteCanteenItem(DeleteCanteenItemObject DCIO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); string strSQL; if (DCIO.apikey != strApiKey || DCIO.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { strSQL = "UPDATE CTM_CRAI SET CRAI_Deleted = 1 Where CRAI_Id = " + DCIO.itemid + ";"; SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; cmd = new SqlCommand(strSQL, conUpd); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Delete Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult CanteenMenuList(CanteenMenuListObject CMLO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CMLO.apikey != strApiKey || CMLO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { String WhereCondition = " Where 1=1 "; WhereCondition += " AND CMI_CliId = " + CMLO.locid + ""; if (CMLO.canteenid > 0) { WhereCondition += " AND CMI_CtlId = "+ CMLO.canteenid + ""; } strSQL = "Select CMI_Id as canteenmenuid,CMI_CtlId as centeenid,CMI_Code AS canteenmenucode, CMI_Name AS canteenmenuname,CMI_Description as description,CMI_Active AS active,CMI_CliId as locationid from PDV_CTMCMI " + WhereCondition + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenMenu(CanteenMenuObject CMO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CMO.apikey != strApiKey || CMO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "Select CMI_Id as canteenmenuid,CMI_CtlId as centeenid,CMI_Code AS canteenmenucode, CMI_Name AS canteenmenuname,CMI_Description as description,CMI_Active AS active,CMI_CliId as locationid,'' AS itemdetails from PDV_CTMCMI Where CMI_Id = "+ CMO.canteenmenuid + " ;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); DataTable dtDetItem = new DataTable(); for (Int32 i = 0; i < dtDet.Rows.Count; i++) { strSQL = "Select CMR_Id as menuitemid,CMR_CmiId as canteenmenuid,CMR_CraiId AS itemid, CRAI.CRAI_Name AS itemname from PDV_CTMCMR CMR INNER JOIN PDV_CTMCRAI CRAI ON CRAI.CRAI_Id = CMR.CMR_CraiId Where CMR_CmiId = " + CMO.canteenmenuid + " ;"; dtDetItem = new DataTable(); dtDetItem = fnReturnDt(strSQL); List> MatListDetails = new List>(); MatListDetails = GetTableRows(dtDetItem); var serializer = new JavaScriptSerializer(); dtDet.Rows[i]["itemdetails"] = serializer.Serialize(MatListDetails); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult SaveCanteenMenu(CanteenMenuSaveObject CMSO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); if (CMSO.apikey != strApiKey || CMSO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { // DeSerializing string to json data JavaScriptSerializer js = new JavaScriptSerializer(); List itemlist = (List)js.Deserialize(CMSO.itemdata, typeof(List)); Int32 i; DataTable dtM; DataColumn dcM; DataRow drM; dtM = new DataTable(); dcM = new DataColumn("TCMR_Id", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCMR_CmiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCMR_CraiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); for (i = 0; i < itemlist.Count; i++) { drM = dtM.NewRow(); drM["TCMR_Id"] = itemlist[i].menuitemid; drM["TCMR_CmiId"] = itemlist[i].canteenmenuid; drM["TCMR_CraiId"] = itemlist[i].itemid; dtM.Rows.Add(drM); } SqlConnection conupd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conupd.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_SaveCanteenMenu", conupd); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@CMIId", SqlDbType.Int); par.Value = CMSO.canteenmenuid; cmd.Parameters.Add(par); par = new SqlParameter("@CMICtlId", SqlDbType.Int); par.Value = CMSO.canteenid; cmd.Parameters.Add(par); par = new SqlParameter("@CMICode", SqlDbType.NVarChar); par.Value = CMSO.menucode; cmd.Parameters.Add(par); par = new SqlParameter("@CMIName", SqlDbType.NVarChar); par.Value = CMSO.menuname; cmd.Parameters.Add(par); par = new SqlParameter("@CMIDescription", SqlDbType.NVarChar); par.Value = CMSO.description; cmd.Parameters.Add(par); par = new SqlParameter("@CMIActive", SqlDbType.Int); par.Value = CMSO.active; cmd.Parameters.Add(par); par = new SqlParameter("@TVP_CTMCMR", SqlDbType.Structured); par.Value = dtM; cmd.Parameters.Add(par); par = new SqlParameter("@LOGINId", SqlDbType.Int); par.Value = CMSO.empid; cmd.Parameters.Add(par); par = new SqlParameter("@CMICliId", SqlDbType.Int); par.Value = CMSO.locid; cmd.Parameters.Add(par); conupd.Open(); DataTable dtDetRes = new DataTable(); dtDetRes.Load(cmd.ExecuteReader()); List> lstReport = GetTableRows(dtDetRes); conupd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Saved Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult DeleteCanteenMenu(DeleteCanteenMenuObject DCMO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); string strSQL; if (DCMO.apikey != strApiKey || DCMO.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { strSQL = " UPDATE CTM_CMI SET CMI_Deleted = 1 Where CMI_Id = " + DCMO.canteenmenuid + ";" + " UPDATE CTM_CMR SET CMR_Deleted = 1 Where CMR_CmiId = " + DCMO.canteenmenuid + ""; SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; cmd = new SqlCommand(strSQL, conUpd); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Delete Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult CanteenScheduleMenuList(CanteenScheduleMenuListObject CSMLO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CSMLO.apikey != strApiKey || CSMLO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { String WhereCondition = " Where 1=1 "; WhereCondition += " AND CMSM_CliId = " + CSMLO.locid + ""; if (CSMLO.canteenid > 0) { WhereCondition += " AND CMSM_CtlId = " + CSMLO.canteenid + ""; } strSQL = "Select CMSM_Id as scheduleid,CMSM_CtlId as centeenid,CTL.CTL_Name AS canteenname,CMSM_CmiId AS canteenmenuid,CMI.CMI_Name AS canteenmenuname "+ " , CAST(CMSM_EffFrom AS NVARCHAR) AS effectivefrom,CAST(CMSM_EffTo AS NVARCHAR) as effectiveto,CAST(CAST(CMSM_FromTime AS TIME(0)) AS NVARCHAR(5)) AS fromtime "+ " ,CAST(CAST(CMSM_ToTime AS TIME(0)) AS NVARCHAR(5)) AS totime,CMSM_CliId as locationid "+ " ,(CASE WHEN CMSM_Mon = 1 THEN 'Mon_' ELSE '_' END)+(CASE WHEN CMSM_Tue = 1 THEN 'Tue_' ELSE '_' END)+(CASE WHEN CMSM_Wed = 1 THEN 'Wed_' ELSE '_' END)+"+ " (CASE WHEN CMSM_Thu = 1 THEN 'Thu_' ELSE '_' END) + (CASE WHEN CMSM_Fri = 1 THEN 'Fri_' ELSE '_' END)+(CASE WHEN CMSM_Sat = 1 THEN 'Sat_' ELSE '_' END)+ "+ " (CASE WHEN CMSM_Sun = 1 THEN 'Sun' ELSE '' END) AS weekassign "+ " from PDV_CTMCMSM CMSM "+ " LEFT JOIN PDV_CTMCTL CTL ON CTL.CTL_Id = CMSM.CMSM_CtlId "+ " LEFT JOIN PDV_CTMCMI CMI ON CMI.CMI_Id = CMSM.CMSM_CmiId " + WhereCondition + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenScheduleMenu(CanteenScheduleMenuObject CSMO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CSMO.apikey != strApiKey || CSMO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "Select CMSM_Id as scheduleid,CMSM_CtlId as centeenid,CTL.CTL_Name AS canteenname,CMSM_CmiId AS canteenmenuid,CMI.CMI_Name AS canteenmenuname, CAST(CMSM_EffFrom AS NVARCHAR) AS effectivefrom,CAST(CMSM_EffTo AS NVARCHAR) as effectiveto,CAST(CAST(CMSM_FromTime AS TIME(0)) AS NVARCHAR(5)) AS fromtime,CAST(CAST(CMSM_ToTime AS TIME(0)) AS NVARCHAR(5)) AS totime,CMSM_Mon AS mon,CMSM_Tue AS tue,CMSM_Wed AS wed,CMSM_Thu AS thu,CMSM_Fri AS fri,CMSM_Sat as sat,CMSM_Sun AS sun,CMSM_CliId as locationid,'' AS itemdetails from PDV_CTMCMSM CMSM LEFT JOIN PDV_CTMCTL CTL ON CTL.CTL_Id = CMSM.CMSM_CtlId LEFT JOIN PDV_CTMCMI CMI ON CMI.CMI_Id = CMSM.CMSM_CmiId Where CMSM_Id = " + CSMO.scheduleid + " ;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); DataTable dtDetItem = new DataTable(); for (Int32 i = 0; i < dtDet.Rows.Count; i++) { strSQL = "Select CMSD_Id as scheduleitemid,CMSD_CmsmId as scheduleid,CMSD_CraiId AS itemid, CRAI.CRAI_Name AS itemname " + " from PDV_CTMCMSD CMSD INNER JOIN PDV_CTMCRAI CRAI ON CRAI.CRAI_Id = CMSD.CMSD_CraiId Where CMSD.CMSD_CmsmId = " + CSMO.scheduleid + " ;"; dtDetItem = new DataTable(); dtDetItem = fnReturnDt(strSQL); List> MatListDetails = new List>(); MatListDetails = GetTableRows(dtDetItem); var serializer = new JavaScriptSerializer(); dtDet.Rows[i]["itemdetails"] = serializer.Serialize(MatListDetails); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult SaveScheduleCanteenMenu(CanteenScheduleMenuSaveObject CSMSO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); if (CSMSO.apikey != strApiKey || CSMSO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { // DeSerializing string to json data JavaScriptSerializer js = new JavaScriptSerializer(); List itemlist = (List)js.Deserialize(CSMSO.itemdata, typeof(List)); Int32 i; DataTable dtM; DataColumn dcM; DataRow drM; dtM = new DataTable(); dcM = new DataColumn("TCMSD_Id", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCMSD_CmsmId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCMSD_CraiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); for (i = 0; i < itemlist.Count; i++) { drM = dtM.NewRow(); drM["TCMSD_Id"] = itemlist[i].scheduleitemid; drM["TCMSD_CmsmId"] = itemlist[i].scheduleid; drM["TCMSD_CraiId"] = itemlist[i].itemid; dtM.Rows.Add(drM); } SqlConnection conupd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conupd.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_SaveCanteenScheduleMenu", conupd); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@CMSMId", SqlDbType.Int); par.Value = CSMSO.scheduleid; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMCtlId", SqlDbType.Int); par.Value = CSMSO.canteenid; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMCmiId", SqlDbType.Int); par.Value = CSMSO.canteenmenuid; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMEffFrom", SqlDbType.NVarChar); // Check if the value is null or empty if (string.IsNullOrEmpty(CSMSO.effectivefrom)) { par.Value = DBNull.Value; // Assign DBNull if the value is null or empty } else { par.Value = CSMSO.effectivefrom; // Assign the value if it is valid } cmd.Parameters.Add(par); par = new SqlParameter("@CMSMEffTo", SqlDbType.NVarChar); // Check if the value is null or empty if (string.IsNullOrEmpty(CSMSO.effectiveto)) { par.Value = DBNull.Value; // Assign DBNull if the value is null or empty } else { par.Value = CSMSO.effectiveto; // Assign the value if it is valid } cmd.Parameters.Add(par); par = new SqlParameter("@CMSMFromTime", SqlDbType.NVarChar); par.Value = CSMSO.fromtime; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMToTime", SqlDbType.NVarChar); par.Value = CSMSO.totime; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMMon", SqlDbType.Int); par.Value = CSMSO.mon; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMTue", SqlDbType.Int); par.Value = CSMSO.tue; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMWed", SqlDbType.Int); par.Value = CSMSO.wed; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMThu", SqlDbType.Int); par.Value = CSMSO.thu; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMFri", SqlDbType.Int); par.Value = CSMSO.fri; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMSat", SqlDbType.Int); par.Value = CSMSO.sat; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMSun", SqlDbType.Int); par.Value = CSMSO.sun; cmd.Parameters.Add(par); par = new SqlParameter("@TVP_CTMCMSD", SqlDbType.Structured); par.Value = dtM; cmd.Parameters.Add(par); par = new SqlParameter("@LOGINId", SqlDbType.Int); par.Value = CSMSO.empid; cmd.Parameters.Add(par); par = new SqlParameter("@CMSMCliId", SqlDbType.Int); par.Value = CSMSO.locid; cmd.Parameters.Add(par); conupd.Open(); DataTable dtDetRes = new DataTable(); dtDetRes.Load(cmd.ExecuteReader()); List> lstReport = GetTableRows(dtDetRes); conupd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Saved Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult DeleteCanteenScheduleMenu(DeleteCanteenScheduleMenuObject DCSMO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); string strSQL; if (DCSMO.apikey != strApiKey || DCSMO.secretkey != strSecretKey) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; } else { strSQL = " UPDATE CTM_CMSM SET CMSM_Deleted = 1 Where CMSM_Id = " + DCSMO.scheduleid + ";" + " UPDATE CTM_CMSD SET CMSD_Deleted = 1 Where CMSD_CmsmId = " + DCSMO.scheduleid + ""; SqlConnection conUpd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conUpd.ConnectionString = connectionstring; SqlCommand cmd; cmd = new SqlCommand(strSQL, conUpd); conUpd.Open(); cmd.ExecuteNonQuery(); conUpd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Delete Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } public int RandomNumber(int min, int max) { Random random = new Random(); return random.Next(min, max); } public JsonResult GetCanteenMenuItemList(CanteenMenuItemObject CMIO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CMIO.apikey != strApiKey || CMIO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = " Select CMI.CMI_Id as canteenmenuid,CMR.CMR_Id as menuitemid,CMR.CMR_CraiId AS itemid, CRAI.CRAI_Name AS itemname " + " ,CRAI.CRAI_Description as description,CRAI.CRAI_Price as stdprice,CRAI.CRAI_ImagePath as imagepath " + " ,CRAI.CRAI_IsDiscount as isdiscount,CRAI_DLevelAmt1 as discount,0 as discountlevel " + " ,CRAI.CRAI_Price as actualprice " + " from PDV_CTMCMI CMI " + " INNER JOIN PDV_CTMCMR CMR ON CMR.CMR_CmiId = CMI.CMI_Id " + " INNER JOIN PDV_CTMCRAI CRAI ON CRAI.CRAI_Id = CMR.CMR_CraiId " + " Where CMI.CMI_Id = "+ CMIO.canteenmenuid + " AND CMI.CMI_CtlId = "+ CMIO.canteenid + " AND CMI.CMI_Active = 1 AND CMI.CMI_CliId = "+ CMIO.locid + " ;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult CanteenPreorderMealList(CanteenPreorderMealListObject CPMLO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CPMLO.apikey != strApiKey || CPMLO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_CanteenPreorderMealList '"+ CPMLO.fromdate + "','" + CPMLO.todate + "'," + CPMLO.employeeid + "," + CPMLO.canteenid + "," + CPMLO.loginid + "," + CPMLO.locid + ",0;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); DataTable dtDetItem = new DataTable(); for (Int32 i = 0; i < dtDet.Rows.Count; i++) { Int32 preorderId = Convert.ToInt32(dtDet.Rows[i]["preorderid"]); strSQL = "EXEC TPP_CanteenPreorderMealList '" + CPMLO.fromdate + "','" + CPMLO.todate + "'," + CPMLO.employeeid + "," + CPMLO.canteenid + "," + CPMLO.loginid + "," + CPMLO.locid + ","+ preorderId + ";"; dtDetItem = new DataTable(); dtDetItem = fnReturnDt(strSQL); List> MatListDetails = new List>(); MatListDetails = GetTableRows(dtDetItem); var serializer = new JavaScriptSerializer(); dtDet.Rows[i]["itemdetails"] = serializer.Serialize(MatListDetails); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenPreorderMeal(CanteenPreorderMealObject CPMO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CPMO.apikey != strApiKey || CPMO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_CanteenPreorderMeal " + CPMO.preorderid + ",0"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); DataTable dtDetItem = new DataTable(); for (Int32 i = 0; i < dtDet.Rows.Count; i++) { Int32 preorderId = Convert.ToInt32(dtDet.Rows[i]["preorderid"]); strSQL = "EXEC TPP_CanteenPreorderMeal " + CPMO.preorderid + ",1"; dtDetItem = new DataTable(); dtDetItem = fnReturnDt(strSQL); List> MatListDetails = new List>(); MatListDetails = GetTableRows(dtDetItem); var serializer = new JavaScriptSerializer(); dtDet.Rows[i]["itemdetails"] = serializer.Serialize(MatListDetails); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult SaveCanteenPreorderMeal(CanteenPreorderMealSaveObject CPMO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); if (CPMO.apikey != strApiKey || CPMO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { // DeSerializing string to json data JavaScriptSerializer js = new JavaScriptSerializer(); List itemlist = (List)js.Deserialize(CPMO.itemdata, typeof(List)); Int32 i; DataTable dtM; DataColumn dcM; DataRow drM; dtM = new DataTable(); dcM = new DataColumn("TCPOD_CmiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_CraiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_Qty", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_Price", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_Discount", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_DiscountLevel", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); for (i = 0; i < itemlist.Count; i++) { drM = dtM.NewRow(); drM["TCPOD_CmiId"] = itemlist[i].canteenmenuid; drM["TCPOD_CraiId"] = itemlist[i].itemid; drM["TCPOD_Qty"] = itemlist[i].qty; drM["TCPOD_Price"] = itemlist[i].price; drM["TCPOD_Discount"] = itemlist[i].discount; drM["TCPOD_DiscountLevel"] = itemlist[i].discountlevel; dtM.Rows.Add(drM); } String CanteenTrNumber = ""; CanteenTrNumber = GenerateTrNo(CPMO.locid, "canteenmeal"); int min = 1; int max = 99999; int RandNo = RandomNumber(min, max); String strBarcode = "PM" + Convert.ToString(DateTime.Now.ToString("yy") + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd")) + "" + RandNo.ToString("00000"); SqlConnection conupd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conupd.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_SaveCanteenPreorderMeal", conupd); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@CPOMNo", SqlDbType.NVarChar); par.Value = CanteenTrNumber; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMDate", SqlDbType.NVarChar); par.Value = CPMO.mealdate; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMCtlId", SqlDbType.Int); par.Value = CPMO.canteenid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMEmiId", SqlDbType.Int); par.Value = CPMO.employeeid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMDpiId", SqlDbType.Int); par.Value = CPMO.departmentid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMBarocde", SqlDbType.NVarChar); par.Value = strBarcode; cmd.Parameters.Add(par); par = new SqlParameter("@CCPOMRemark", SqlDbType.NVarChar); if (string.IsNullOrEmpty(CPMO.remark)) { par.Value = "Applied Pre-order meal"; } else { par.Value = CPMO.remark; } cmd.Parameters.Add(par); par = new SqlParameter("@TVP_CTRCPOD", SqlDbType.Structured); par.Value = dtM; cmd.Parameters.Add(par); par = new SqlParameter("@LOGINId", SqlDbType.Int); par.Value = CPMO.loginid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMCliId", SqlDbType.Int); par.Value = CPMO.locid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMFlihId", SqlDbType.Int); par.Value = CPMO.featuremenuid; cmd.Parameters.Add(par); conupd.Open(); DataTable dtDetRes = new DataTable(); dtDetRes.Load(cmd.ExecuteReader()); List> lstReport = GetTableRows(dtDetRes); conupd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Saved Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult CanteenGuestMealList(CanteenGuestMealListObject CGMLO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CGMLO.apikey != strApiKey || CGMLO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_CanteenGuestMealList '" + CGMLO.fromdate + "','" + CGMLO.todate + "'," + CGMLO.employeeid + "," + CGMLO.canteenid + "," + CGMLO.loginid + "," + CGMLO.locid + ",0;"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); DataTable dtDetItem = new DataTable(); for (Int32 i = 0; i < dtDet.Rows.Count; i++) { Int32 preorderId = Convert.ToInt32(dtDet.Rows[i]["preorderid"]); strSQL = "EXEC TPP_CanteenGuestMealList '" + CGMLO.fromdate + "','" + CGMLO.todate + "'," + CGMLO.employeeid + "," + CGMLO.canteenid + "," + CGMLO.loginid + "," + CGMLO.locid + "," + preorderId + ";"; dtDetItem = new DataTable(); dtDetItem = fnReturnDt(strSQL); List> MatListDetails = new List>(); MatListDetails = GetTableRows(dtDetItem); var serializer = new JavaScriptSerializer(); dtDet.Rows[i]["itemdetails"] = serializer.Serialize(MatListDetails); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenGuestMeal(CanteenGuestMealObject CGMO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CGMO.apikey != strApiKey || CGMO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "EXEC TPP_CanteenGuestMeal " + CGMO.preorderid + ",0"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); DataTable dtDetItem = new DataTable(); for (Int32 i = 0; i < dtDet.Rows.Count; i++) { Int32 preorderId = Convert.ToInt32(dtDet.Rows[i]["preorderid"]); strSQL = "EXEC TPP_CanteenGuestMeal " + CGMO.preorderid + ",1"; dtDetItem = new DataTable(); dtDetItem = fnReturnDt(strSQL); List> MatListDetails = new List>(); MatListDetails = GetTableRows(dtDetItem); var serializer = new JavaScriptSerializer(); dtDet.Rows[i]["itemdetails"] = serializer.Serialize(MatListDetails); } List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult GetCanteenEmployee(CanteenEmployeeObject CEO) { var modelresult = new dataConversiontoJson(); DataTable dtDet = new DataTable(); string strSQL; if (CEO.apikey != strApiKey || CEO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { strSQL = "SELECT * FROM PDV_EMCAN Where EMCAN_EmiId = " + CEO.loginid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Permission Granted Successfully !"; modelresult.ListDetails = lstReport; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult SaveCanteenGuestMeal(CanteenGuestMealSaveObject CGMO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); if (CGMO.apikey != strApiKey || CGMO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { // DeSerializing string to json data JavaScriptSerializer js = new JavaScriptSerializer(); List itemlist = (List)js.Deserialize(CGMO.itemdata, typeof(List)); if (String.IsNullOrEmpty(CGMO.remark)) { CGMO.remark = "Applied Guest Meal Order "; } Int32 i; DataTable dtM; DataColumn dcM; DataRow drM; dtM = new DataTable(); dcM = new DataColumn("TCPOD_CmiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_CraiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_Qty", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_Price", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_Discount", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCPOD_DiscountLevel", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); for (i = 0; i < itemlist.Count; i++) { drM = dtM.NewRow(); drM["TCPOD_CmiId"] = itemlist[i].canteenmenuid; drM["TCPOD_CraiId"] = itemlist[i].itemid; drM["TCPOD_Qty"] = itemlist[i].qty; drM["TCPOD_Price"] = itemlist[i].price; drM["TCPOD_Discount"] = itemlist[i].discount; drM["TCPOD_DiscountLevel"] = itemlist[i].discountlevel; dtM.Rows.Add(drM); } String CanteenTrNumber = ""; CanteenTrNumber = GenerateTrNo(CGMO.locid, "canteenmeal"); int min = 1; int max = 99999; int RandNo = RandomNumber(min, max); String strBarcode = "GM" + Convert.ToString(DateTime.Now.ToString("yy") + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd")) + "" + RandNo.ToString("00000"); SqlConnection conupd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conupd.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_SaveCanteenGuestMeal", conupd); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@CPOMNo", SqlDbType.NVarChar); par.Value = CanteenTrNumber; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMDate", SqlDbType.NVarChar); par.Value = CGMO.mealdate; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMCtlId", SqlDbType.Int); par.Value = CGMO.canteenid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMEmiId", SqlDbType.Int); par.Value = CGMO.employeeid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMDpiId", SqlDbType.Int); par.Value = CGMO.departmentid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMBarocde", SqlDbType.NVarChar); par.Value = strBarcode; cmd.Parameters.Add(par); par = new SqlParameter("@CCPOMRemark", SqlDbType.NVarChar); par.Value = CGMO.remark; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMPurpose", SqlDbType.NVarChar); par.Value = CGMO.purpose; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMPersonName", SqlDbType.NVarChar); par.Value = CGMO.personname; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMPersonEmail", SqlDbType.NVarChar); par.Value = CGMO.personemail; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMPersonPhNo", SqlDbType.NVarChar); par.Value = CGMO.personphno; cmd.Parameters.Add(par); par = new SqlParameter("@TVP_CTRCPOD", SqlDbType.Structured); par.Value = dtM; cmd.Parameters.Add(par); par = new SqlParameter("@LOGINId", SqlDbType.Int); par.Value = CGMO.loginid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMCliId", SqlDbType.Int); par.Value = CGMO.locid; cmd.Parameters.Add(par); par = new SqlParameter("@CPOMFlihId", SqlDbType.Int); par.Value = CGMO.featuremenuid; cmd.Parameters.Add(par); conupd.Open(); DataTable dtDetRes = new DataTable(); dtDetRes.Load(cmd.ExecuteReader()); List> lstReport = GetTableRows(dtDetRes); conupd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "Saved Successfully !"; } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } [HttpPost] public JsonResult SaveCanteenPos(CanteenPosSaveObject CGMO) { var modelresult = new dataConversiontoJson(); try { DataTable dtDet = new DataTable(); string strSQL; if (CGMO.apikey != strApiKey || CGMO.secretkey != strSecretKey) { List> lstReport = GetTableRows(dtDet); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Credentials not matching"; modelresult.ListDetails = lstReport; } else { String strBarcode = CGMO.barcode; strSQL = " EXEC TPP_CanteenBarcode '" + CGMO.barcode + "',"+ CGMO.locid + ";"; dtDet = new DataTable(); dtDet = fnReturnDt(strSQL); if (dtDet.Rows.Count == 0) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "Invalid QR Code Or Scan Again"; } else { DataTable dtDetTrs = new DataTable(); strSQL = " SELECT CONVERT(VARCHAR,CTRS.CTRS_EntryDateTime,120) AS EntryDateTime " + " FROM PDV_CTRCPOM CPOM " + " INNER JOIN PDV_CTRCPOD CPOD ON CPOD.CPOD_CpomId = CPOM.CPOM_Id " + " INNER JOIN PDV_CTRCTRS CTRS ON CTRS.CTRS_CpodId = CPOD.CPOD_Id AND CTRS.CTRS_CpomId = CPOD.CPOD_CpomId " + " Where CPOM.CPOM_Barocde = '" + strBarcode + "' AND CPOM.CPOM_CliId = " + CGMO.locid + " GROUP BY CTRS.CTRS_EntryDateTime "; dtDetTrs = new DataTable(); dtDetTrs = fnReturnDt(strSQL); if (dtDetTrs.Rows.Count != 0) { modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = "QR Code is already scanned Log Datetime : " + dtDetTrs.Rows[0]["EntryDateTime"] + ""; } else { Int32 i; DataTable dtM; DataColumn dcM; DataRow drM; dtM = new DataTable(); dcM = new DataColumn("TCTRS_CtlId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_EmiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_DpiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_CmiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_CraiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_DrCr", Type.GetType("System.String")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_Amount", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_Remark", Type.GetType("System.String")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_RefFlihId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_CpomId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_CpodId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_Qty", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_Price", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_Discount", Type.GetType("System.Decimal")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_DiscountLevel", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_FlihId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_CliId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); dcM = new DataColumn("TCTRS_EntryEmiId", Type.GetType("System.Int32")); dtM.Columns.Add(dcM); for (i = 0; i < dtDet.Rows.Count; i++) { drM = dtM.NewRow(); drM["TCTRS_CtlId"] = Convert.ToInt32(dtDet.Rows[i]["CPOM_CtlId"]); drM["TCTRS_EmiId"] = Convert.ToInt32(dtDet.Rows[i]["CPOM_EmiId"]); drM["TCTRS_DpiId"] = Convert.ToInt32(dtDet.Rows[i]["EMI_DpiId"]); drM["TCTRS_CmiId"] = Convert.ToInt32(dtDet.Rows[i]["CPOD_CmiId"]); drM["TCTRS_CraiId"] = Convert.ToInt32(dtDet.Rows[i]["CPOD_CraiId"]); drM["TCTRS_DrCr"] = "Cr"; drM["TCTRS_Amount"] = Convert.ToDecimal(dtDet.Rows[i]["CPOD_Amount"]); drM["TCTRS_Remark"] = "Appplied canteen successfully "; drM["TCTRS_RefFlihId"] = Convert.ToInt32(dtDet.Rows[i]["CPOM_FlihId"]); drM["TCTRS_CpomId"] = Convert.ToInt32(dtDet.Rows[i]["CPOM_Id"]); drM["TCTRS_CpodId"] = Convert.ToInt32(dtDet.Rows[i]["CPOD_Id"]); drM["TCTRS_Qty"] = Convert.ToDecimal(dtDet.Rows[i]["CPOD_Qty"]); drM["TCTRS_Price"] = Convert.ToDecimal(dtDet.Rows[i]["CPOD_Price"]); drM["TCTRS_Discount"] = Convert.ToDecimal(dtDet.Rows[i]["CPOD_Discount"]); drM["TCTRS_DiscountLevel"] = Convert.ToInt32(dtDet.Rows[i]["CPOD_DiscountLevel"]); drM["TCTRS_FlihId"] = CGMO.featuremenuid; drM["TCTRS_CliId"] = CGMO.locid; drM["TCTRS_EntryEmiId"] = CGMO.loginid; dtM.Rows.Add(drM); } SqlConnection conupd = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings["MANTRI"].ConnectionString; conupd.ConnectionString = connectionstring; SqlCommand cmd; SqlParameter par; cmd = new SqlCommand("TPP_SaveCanteenPos", conupd); cmd.CommandType = CommandType.StoredProcedure; par = new SqlParameter("@TVP_CTRCTRS", SqlDbType.Structured); par.Value = dtM; cmd.Parameters.Add(par); par = new SqlParameter("@LOGINId", SqlDbType.Int); par.Value = CGMO.loginid; cmd.Parameters.Add(par); par = new SqlParameter("@CTRSCliId", SqlDbType.Int); par.Value = CGMO.locid; cmd.Parameters.Add(par); conupd.Open(); cmd.ExecuteNonQuery(); conupd.Close(); modelresult.cpermission = "granted"; modelresult.cresponse = "Success"; modelresult.error = "QR Code scanned successfully."; } } } } catch (Exception ex) { String errorMessage = ex.ToString(); modelresult.cpermission = "notgranted"; modelresult.cresponse = "Failure"; modelresult.error = errorMessage; } var jsonResult = Json(modelresult, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } } }