Facebook
From easwar, 7 Months ago, written in C#.
Embed
Download Paste or View Raw
Hits: 440
  1. //business
  2.    public string AddRecordFeedback(JObject RecordfdJsonvalue)
  3.         {
  4.             string Status = string.Empty;
  5.             string Msg = string.Empty;
  6.             string strResult = string.Empty;
  7.             string strProjectKey = string.Empty, strSectionkey = string.Empty, strLeasekey = string.Empty, fkeyFeedbacksource = string.Empty,
  8.             fkeyFeedbacktype = string.Empty, feedbackDescription = string.Empty, feedbackResponsecomments = string.Empty, strUserKey = string.Empty,
  9.             strReporteddate = string.Empty;
  10.  
  11.             List<string> lstQuery = new List<string>();
  12.             try
  13.             {
  14.                 dynamic lstfld = JsonConvert.DeserializeObject(RecordfdJsonvalue.ToString());
  15.                 dynamic JSONValue = lstfld.CurrentRow;
  16.                 //dynamic JSONValue = JArray.Parse("[" + RecordfdJsonvalue + "]");
  17.                 DBConnection dbcMaster = new DBConnection(_configuration.GetSection("REmaapSettings").GetSection("MasterConnectionString").Value);
  18.                 if (JSONValue.Count > 0)
  19.                 {
  20.                     strProjectKey = Convert.ToString(JSONValue[0].strProjectKey);
  21.                     strSectionkey = Convert.ToString(JSONValue[0].strSectionkey);
  22.                     strLeasekey = Convert.ToString(JSONValue[0].strLeasekey);
  23.                     fkeyFeedbacksource = Convert.ToString(JSONValue[0].fkeyFeedbacksource);
  24.                     fkeyFeedbacktype = Convert.ToString(JSONValue[0].fkeyFeedbacktype);
  25.                     strReporteddate = Convert.ToString(JSONValue[0].strReporteddate);
  26.                     feedbackDescription = Convert.ToString(JSONValue[0].feedbackDescription);
  27.                     feedbackResponsecomments = Convert.ToString(JSONValue[0].feedbackResponsecomments);
  28.                     strUserKey = Convert.ToString(JSONValue[0].addedBy);
  29.                 }
  30.                 if (!string.IsNullOrEmpty(strProjectKey) && !string.IsNullOrEmpty(strLeasekey) && !string.IsNullOrEmpty(strSectionkey)
  31.                     && !string.IsNullOrEmpty(feedbackDescription) && !string.IsNullOrEmpty(strUserKey) && !string.IsNullOrEmpty(strReporteddate))
  32.                 {
  33.                     lstQuery.Add("INSERT INTO Report_Feedback_Details(FKEY_PROJECT,FKEY_SECTIONKEY,FKEY_LEASEKEY,FKEY_FEEDBACK_SOURCE,FKEY_FEEDBACK_TYPE,REPORTED_DATE,FEEDBACK_DESCRIPTION,FEEDBACK_RESPONSE_COMMENTS,Added_by,Added_On,Modified_By,Modified_On) " +
  34.                                             "VALUES ('" + strProjectKey + "','" + strSectionkey + "','" + strLeasekey + "','" + fkeyFeedbacksource + "','" + fkeyFeedbacktype + "','" + strReporteddate + "','" + _DAL.stripQuotes(feedbackDescription) + "','" + _DAL.stripQuotes(feedbackResponsecomments) + "','" + strUserKey + "', NOW(),'"   + strUserKey + "',NOW() )");
  35.                     if (lstQuery.Count > 0)
  36.                     {
  37.                         dbcMaster.executeNonQuery(lstQuery.ToArray());
  38.                         Status = "\"Status\" : " + "\"Success\"";
  39.                         Msg = "\"Message\" : \"Saved Succesfully\"";
  40.                     }
  41.                 }
  42.                 else
  43.                 {
  44.                     Status = "\"Status\" : " + "\"Error\"";
  45.                     Msg = "\"Message\" : \"Insert values are empty\"";
  46.                 }
  47.                 bool Audittrail = SaveAuditTrail(RecordfdJsonvalue);
  48.             }
  49.  
  50.             catch (Exception ex)
  51.             {
  52.                 _logDetails.strprojkey = strProjectKey;
  53.                 Log.WriteLog(ex, _logDetails);
  54.                 Status = "\"Status\" : " + "\"Error\"";
  55.                 Msg = "\"Message\" : \"" + ex.Message.ToString() + "\"";
  56.             }
  57.             strResult = "{" + Status + "," + Msg + "}";
  58.             return strResult;
  59.         }
  60.         public string UpdateRecordFeedback(JObject RecordfdJsonvalue)
  61.         {
  62.             string Status = string.Empty;
  63.             string Msg = string.Empty;
  64.             string strResult = string.Empty;
  65.             string strProjectKey = string.Empty, strPkey = string.Empty, strSectionkey = string.Empty, strLeasekey = string.Empty, fkeyFeedbacksource = string.Empty,
  66.             strUserKey = string.Empty, fkeyFeedbacktype = string.Empty, feedbackDescription = string.Empty, feedbackResponsecomments = string.Empty,
  67.              strReporteddate = string.Empty;
  68.  
  69.             List<string> lstQuery = new List<string>();
  70.             try
  71.             {
  72.                 dynamic lstfld = JsonConvert.DeserializeObject(RecordfdJsonvalue.ToString());
  73.                 dynamic JSONValue = lstfld.CurrentRow;
  74.                 //dynamic JSONValue = JArray.Parse("[" + RecordfdJsonvalue + "]");
  75.                 DBConnection dbcMaster = new DBConnection(_configuration.GetSection("REmaapSettings").GetSection("MasterConnectionString").Value);
  76.                 if (JSONValue.Count > 0)
  77.                 {
  78.                     strPkey = Convert.ToString(JSONValue[0].strPkey);
  79.                     strSectionkey = Convert.ToString(JSONValue[0].strSectionkey);                    
  80.                     fkeyFeedbacksource = Convert.ToString(JSONValue[0].fkeyFeedbacksource);
  81.                     fkeyFeedbacktype = Convert.ToString(JSONValue[0].fkeyFeedbacktype);
  82.                     strReporteddate = Convert.ToString(JSONValue[0].strReporteddate);
  83.                     feedbackDescription = Convert.ToString(JSONValue[0].feedbackDescription);
  84.                     feedbackResponsecomments = Convert.ToString(JSONValue[0].feedbackResponsecomments);
  85.                     strUserKey = Convert.ToString(JSONValue[0].modifiedby);
  86.                 }
  87.                 if (!string.IsNullOrEmpty(strPkey) && !string.IsNullOrEmpty(strSectionkey) && !string.IsNullOrEmpty(feedbackDescription)
  88.                     && !string.IsNullOrEmpty(strUserKey) && !string.IsNullOrEmpty(strReporteddate))
  89.                 {                    
  90.                     lstQuery.Add("UPDATE Report_Feedback_Details SET FKEY_SECTIONKEY = '" + strSectionkey + "',FKEY_FEEDBACK_SOURCE = '" + fkeyFeedbacksource + "',FKEY_FEEDBACK_TYPE = '" + fkeyFeedbacktype +
  91.                                     "',REPORTED_DATE = '" + strReporteddate + "',FEEDBACK_DESCRIPTION ='" + _DAL.stripQuotes(feedbackDescription) + "'," +
  92.                                     "FEEDBACK_RESPONSE_COMMENTS = '" + _DAL.stripQuotes(feedbackResponsecomments) + "',Modified_By = '" + strUserKey + "',Modified_On = NOW() WHERE PKEY = '" + strPkey + "'");
  93.                     if (lstQuery.Count > 0)
  94.                     {
  95.                         dbcMaster.executeNonQuery(lstQuery.ToArray());
  96.                         Status = "\"Status\" : " + "\"Success\"";
  97.                         Msg = "\"Message\" : \"Updated Succesfully\"";
  98.                     }
  99.                 }
  100.                 else
  101.                 {
  102.                     Status = "\"Status\" : " + "\"Error\"";
  103.                     Msg = "\"Message\" : \"Error on Updating the Values\"";
  104.                 }
  105.                 bool Audittrail = SaveAuditTrail(RecordfdJsonvalue);
  106.             }
  107.  
  108.             catch (Exception ex)
  109.             {
  110.                 _logDetails.strprojkey = strProjectKey;
  111.                 Log.WriteLog(ex, _logDetails);
  112.                 Status = "\"Status\" : " + "\"Error\"";
  113.                 Msg = "\"Message\" : \"" + ex.Message.ToString() + "\"";
  114.             }
  115.             strResult = "{" + Status + "," + Msg + "}";
  116.             return strResult;
  117.         }
  118.  
  119.         public string DeleteRecordFeedback(JObject RecordfdJsonvalue)
  120.         {
  121.             string Status = string.Empty;
  122.             string Msg = string.Empty;
  123.             string strResult = string.Empty;
  124.             List<string> lstQuery = new List<string>();
  125.             DBConnection dbcMaster = new DBConnection(_configuration.GetSection("REmaapSettings").GetSection("MasterConnectionString").Value);
  126.             try
  127.             {
  128.                 dynamic lstfld = JsonConvert.DeserializeObject(RecordfdJsonvalue.ToString());
  129.                 dynamic JSONValue = lstfld.CurrentRow;
  130.                 string RecordPkey = Convert.ToString(JSONValue[0].strPkey);
  131.                 if (!string.IsNullOrEmpty(RecordPkey))
  132.                 {
  133.                     lstQuery.Add(" DELETE FROM report_feedback_details WHERE pkey ='" + RecordPkey + "' ");
  134.                     if (lstQuery.Count > 0)
  135.                     {
  136.                         dbcMaster.executeNonQuery(lstQuery.ToArray());
  137.                         Status = "\"Status\" : " + "\"Success\"";
  138.                         Msg = "\"Message\" : \"Deleted Succesfully\"";
  139.                     }
  140.                 }
  141.                 else
  142.                 {
  143.                     Status = "\"Status\" : " + "\"Error\"";
  144.                     Msg = "\"Message\" : \"Error on Deleting the records\"";
  145.                 }
  146.  
  147.                bool Audittrail =  SaveAuditTrail(RecordfdJsonvalue);
  148.             }
  149.             catch(Exception ex)
  150.             {
  151.                 //dynamic JSONValue = JArray.Parse("[" + lstfld.CurrentRow + "]");
  152.                 //dynamic JSONValue = lstfld.RecordFeedbackHeader;
  153.                 //Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonObj);
  154.                 //var NewValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonObj[OldValue]);
  155.                 //Dictionary<string, string> t = NewValues;
  156.                 //Dictionary<string, string> k = OldValues;
  157.                 Log.WriteLog(ex, _logDetails);
  158.                 Status = "\"Status\" : " + "\"Error\"";
  159.                 Msg = "\"Message\" : \"" + ex.Message.ToString() + "\"";
  160.             }
  161.             strResult = "{" + Status + "," + Msg + "}";
  162.             return strResult;
  163.         }
  164.         public bool SaveAuditTrail(JObject RecordfdJsonvalue)
  165.         {
  166.             bool flg = false;
  167.             string strProjectKey = string.Empty, strPkey = string.Empty, strSectionkey = string.Empty, strLeasekey = string.Empty, fkeyFeedbacksource = string.Empty,
  168.            strUserKey = string.Empty, fkeyFeedbacktype = string.Empty, feedbackDescription = string.Empty, feedbackResponsecomments = string.Empty,
  169.             strReporteddate = string.Empty , strRecordpkey = string.Empty,strAction = string.Empty,strModifieduser = string.Empty;
  170.             List<string> lstQuery = new List<string>();
  171.             DBConnection dbcMaster = new DBConnection(_configuration.GetSection("REmaapSettings").GetSection("MasterConnectionString").Value);
  172.             try
  173.             {
  174.                 dynamic lstfld = JsonConvert.DeserializeObject(RecordfdJsonvalue.ToString());
  175.                 //JObject jsonObj = RecordfdJsonvalue;
  176.                 dynamic RecordFeedbackHeader= lstfld.RecordFeedbackHeader;
  177.                 dynamic CurrentRow = lstfld.CurrentRow;
  178.  
  179.                 JArray oldValueArray = lstfld.OldValue;
  180.                 JArray newValueArray = lstfld.NewValue;
  181.  
  182.                 Dictionary<string, string> oldValueDic = new Dictionary<string, string>();
  183.                 Dictionary<string, string> newValueDic = new Dictionary<string, string>();
  184.                 if (oldValueArray != null)
  185.                 {
  186.                     foreach (var item in oldValueArray.First())
  187.                     {
  188.                         var property = item as JProperty;
  189.                         if (property != null)
  190.                             oldValueDic.Add(property.Name, property.Value.ToString());
  191.                     }
  192.                 }
  193.                 if (newValueArray != null)
  194.                 {
  195.                     foreach (var item in newValueArray.First())
  196.                     {
  197.                         var property = item as JProperty;
  198.                         if (property != null)
  199.                             newValueDic.Add(property.Name, property.Value.ToString());
  200.                     }
  201.                 }
  202.  
  203.                 List<string> lstquery = new List<string>();
  204.                 strProjectKey = Convert.ToString(CurrentRow[0].strProjectKey);
  205.                 strSectionkey = Convert.ToString(CurrentRow[0].strSectionkey);
  206.                 strLeasekey = Convert.ToString(CurrentRow[0].strLeasekey);
  207.                 fkeyFeedbacksource = Convert.ToString(CurrentRow[0].fkeyFeedbacksource);
  208.                 fkeyFeedbacktype = Convert.ToString(CurrentRow[0].fkeyFeedbacktype);
  209.                 strReporteddate = Convert.ToString(CurrentRow[0].strReporteddate);
  210.                 feedbackDescription = Convert.ToString(CurrentRow[0].feedbackDescription);
  211.                 feedbackResponsecomments = Convert.ToString(CurrentRow[0].feedbackResponsecomments);
  212.                 strUserKey = Convert.ToString(CurrentRow[0].addedBy);
  213.                 strModifieduser = Convert.ToString(CurrentRow[0].modifiedby);
  214.                 strRecordpkey = Convert.ToString(CurrentRow[0].strPkey);
  215.                 strAction = Convert.ToString(CurrentRow[0].actionType);
  216.                 if (strAction.Trim().ToUpper() == "A")
  217.                 {
  218.                     foreach (var _Field in RecordFeedbackHeader)
  219.                     {
  220.                         if (newValueDic.ContainsKey(Convert.ToString(_Field.columnName)))
  221.                             lstquery.Add("INSERT INTO `REPORT_FEEDBACK_AUDIT_TRIAL` (`FKEY_PROJECT`,`FKEY_LEASEKEY`,`FKEY_RECORDKEY`,`FKEY_FIELDKEY`,`OLD_VALUE`,`NEW_VALUE`,`OLD_USER`,`NEW_USER`,`ACTION_TYPE`,`CHANGE_DATE`)" +
  222.                                 "VALUES('" + strProjectKey + "','" + strLeasekey + "','" + strRecordpkey + "','" + _Field.pkey + "',NULL,'" + stripQuotes(newValueDic[Convert.ToString(_Field.columnName)]) + "','" + strUserKey + "','" + strUserKey + "','A',now()); ");
  223.                     }
  224.                     flg = dbcMaster.executeNonQuery(lstquery.ToArray());
  225.                 }
  226.                 else if (strAction.Trim().ToUpper() == "E")
  227.                 {
  228.                     foreach (var _Field in RecordFeedbackHeader)
  229.                     {
  230.                         string aa = Convert.ToString(_Field.columnName);
  231.                         if ((oldValueDic.ContainsKey(Convert.ToString(_Field.columnName)) && newValueDic.ContainsKey(Convert.ToString(_Field.columnName))) && (Convert.ToString(oldValueDic[Convert.ToString(_Field.columnName)]) != newValueDic[Convert.ToString(_Field.columnName)]))
  232.                         {
  233.                             lstquery.Add("INSERT INTO `REPORT_FEEDBACK_AUDIT_TRIAL` (`FKEY_PROJECT`,`FKEY_LEASEKEY`,`FKEY_RECORDKEY`,`FKEY_FIELDKEY`,`OLD_VALUE`,`NEW_VALUE`,`OLD_USER`,`NEW_USER`,`ACTION_TYPE`,`CHANGE_DATE`)" +
  234.                                "VALUES('" + strProjectKey + "','" + strLeasekey + "','" + strRecordpkey + "','" + _Field.pkey + "','" + stripQuotes(oldValueDic[Convert.ToString(_Field.columnName)]) + "','" + stripQuotes(newValueDic[Convert.ToString(_Field.columnName)]) + "','" + strUserKey + "','" + strModifieduser + "','E',now()); ");
  235.                         }
  236.                     }
  237.                     flg = dbcMaster.executeNonQuery(lstquery.ToArray());
  238.                 }
  239.                 else if (strAction.Trim().ToUpper() == "D")
  240.                 {
  241.                     foreach (var _Field in RecordFeedbackHeader)
  242.                     {
  243.                         if (oldValueDic.ContainsKey(Convert.ToString(_Field.columnName)))
  244.                             lstquery.Add("INSERT INTO `REPORT_FEEDBACK_AUDIT_TRIAL` (`FKEY_PROJECT`,`FKEY_LEASEKEY`,`FKEY_RECORDKEY`,`FKEY_FIELDKEY`,`OLD_VALUE`,`NEW_VALUE`,`OLD_USER`,`NEW_USER`,`ACTION_TYPE`,`CHANGE_DATE`)" +
  245.                                 "VALUES('" + strProjectKey + "','" + strLeasekey + "','" + strRecordpkey + "','" + _Field.pkey + "','"+  stripQuotes(oldValueDic[Convert.ToString(_Field.columnName)]) + "',NULL,'" + strUserKey + "','" + strUserKey + "','D',now()); ");
  246.                     }
  247.                     flg = dbcMaster.executeNonQuery(lstquery.ToArray());
  248.                 }
  249.  
  250.             }
  251.             catch (Exception ex)
  252.             {
  253.                 Log.WriteLog(ex, _logDetails);
  254.             }
  255.             return flg;
  256.         }
  257.  
  258.  
  259.  
  260.  
  261. //controller
  262.  
  263.  [Route("~/api/REmaapClassicView/DeleteRecordFeedback")]
  264.         [HttpPost]
  265.         public string DeleteRecordFeedback(JObject RecordfdJsonvalue)
  266.         {
  267.             string StrResult = string.Empty;
  268.             strIPAddressError = IsallowedIPAddress();
  269.             try
  270.             {
  271.                 if (strIPAddressError.ToUpper() == "TRUE")
  272.                 {
  273.                     StrResult = _BLL.DeleteRecordFeedback(RecordfdJsonvalue);
  274.                 }
  275.                 else
  276.                 {
  277.                     return strIPAddressError;
  278.                 }
  279.             }
  280.             catch (Exception ex)
  281.             {
  282.                 Log.WriteLog(ex, _logdetails);
  283.             }
  284.             return StrResult;
  285.         }