public IActionResult SaveshareJointMembersandNomineeData([FromBody] savejointandnomiee _JointandNomineeSave) { try { if (objshareApplication.SaveshareJointMembersandNomineeData(_JointandNomineeSave, Con)) { return(Ok(true)); } else { return(StatusCode(StatusCodes.Status304NotModified)); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public bool SaveshareJointMembersandNomineeData(savejointandnomiee JointandNomineeSaveDTO, string ConnectionString) { StringBuilder SbsaveReferences = new StringBuilder(); bool IsSaved = false; try { con = new NpgsqlConnection(ConnectionString); if (con.State != ConnectionState.Open) { con.Open(); } trans = con.BeginTransaction(); StringBuilder sbUpdate = new StringBuilder(); string RecordId = string.Empty; string JointRecordid = string.Empty; if (JointandNomineeSaveDTO.paccounttype == "share") { SbsaveReferences.AppendLine("Update Share_Account_creation set isjointapplicable='" + JointandNomineeSaveDTO.pIsjointapplicableorNot + "',isnomineesapplicable='" + JointandNomineeSaveDTO.pIsNomineesApplicableorNot + "' where share_Account_id=" + JointandNomineeSaveDTO.pAccountId + " and share_Account_number='" + JointandNomineeSaveDTO.paccountNo + "';"); } else if (JointandNomineeSaveDTO.paccounttype == "RD Transaction") { SbsaveReferences.AppendLine("Update tbltransrdcreation set isjointapplicable='" + JointandNomineeSaveDTO.pIsjointapplicableorNot + "',isnomineesapplicable='" + JointandNomineeSaveDTO.pIsNomineesApplicableorNot + "' where rdaccountid=" + JointandNomineeSaveDTO.pAccountId + " and rdaccountno='" + JointandNomineeSaveDTO.paccountNo + "';"); } else if (JointandNomineeSaveDTO.paccounttype == "FD Transaction") { SbsaveReferences.AppendLine("Update tbltransfdcreation set isjointapplicable='" + JointandNomineeSaveDTO.pIsjointapplicableorNot + "',isnomineesapplicable='" + JointandNomineeSaveDTO.pIsNomineesApplicableorNot + "' where fdaccountid=" + JointandNomineeSaveDTO.pAccountId + " and fdaccountno='" + JointandNomineeSaveDTO.paccountNo + "';"); } else if (JointandNomineeSaveDTO.paccounttype == "Savings Transaction") { SbsaveReferences.Append("update tbltranssavingaccountcreation set isjointapplicable=" + JointandNomineeSaveDTO.pIsjointapplicableorNot + ",isnomineedetailsapplicable='" + JointandNomineeSaveDTO.pIsNomineesApplicableorNot + "' where savingaccountid=" + JointandNomineeSaveDTO.pAccountId + " and savingaccountno='" + JointandNomineeSaveDTO.paccountNo + "';"); } if (JointandNomineeSaveDTO.JointDetailsList != null && JointandNomineeSaveDTO.JointDetailsList.Count > 0) { for (int i = 0; i < JointandNomineeSaveDTO.JointDetailsList.Count; i++) { if (Convert.ToString(JointandNomineeSaveDTO.JointDetailsList[i].pTypeofOperation) != "CREATE") { if (string.IsNullOrEmpty(JointRecordid)) { JointRecordid = Convert.ToString(JointandNomineeSaveDTO.JointDetailsList[i].precordid); } else { JointRecordid = JointRecordid + "," + Convert.ToString(JointandNomineeSaveDTO.JointDetailsList[i].precordid); } } } for (int i = 0; i < JointandNomineeSaveDTO.JointDetailsList.Count; i++) { if (Convert.ToString(JointandNomineeSaveDTO.JointDetailsList[i].pTypeofOperation) == "CREATE") { SbsaveReferences.AppendLine("INSERT INTO tbltransjointdetails(accounttype, accountid, accountno, memberid, statusid, createdby, createddate) VALUES ( '" + JointandNomineeSaveDTO.paccounttype + "'," + JointandNomineeSaveDTO.pAccountId + ", '" + JointandNomineeSaveDTO.paccountNo + "', " + JointandNomineeSaveDTO.JointDetailsList[i].pMemberId + "," + Convert.ToInt32(Status.Active) + ", " + JointandNomineeSaveDTO.pCreatedby + ", current_timestamp);"); } else if (Convert.ToString(JointandNomineeSaveDTO.JointDetailsList[i].pTypeofOperation) == "UPDATE") { SbsaveReferences.AppendLine("Update tbltransjointdetails set memberid=" + JointandNomineeSaveDTO.JointDetailsList[i].pMemberId + ",statusid=" + Convert.ToInt32(Status.Active) + " where accountid=" + JointandNomineeSaveDTO.pAccountId + " and accountno='" + JointandNomineeSaveDTO.paccountNo + "' and jointdetailsid=" + JointandNomineeSaveDTO.JointDetailsList[i].precordid + ";"); } } if (!string.IsNullOrEmpty(JointRecordid)) { sbUpdate.AppendLine("UPDATE tbltransjointdetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE accountid=" + JointandNomineeSaveDTO.pAccountId + " and accountno='" + JointandNomineeSaveDTO.paccountNo + "' and accounttype='" + JointandNomineeSaveDTO.paccounttype + "' AND jointdetailsid not in(" + JointRecordid + ") ; "); } else { if (JointandNomineeSaveDTO.JointDetailsList == null || JointandNomineeSaveDTO.JointDetailsList.Count == 0) { sbUpdate.AppendLine("UPDATE tbltransjointdetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE accountid=" + JointandNomineeSaveDTO.pAccountId + " and accounttype='" + JointandNomineeSaveDTO.paccounttype + "' and accountno='" + JointandNomineeSaveDTO.paccountNo + "' ; "); } } } if (!string.IsNullOrEmpty(JointRecordid)) { sbUpdate.AppendLine("UPDATE tbltransjointdetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE accountid=" + JointandNomineeSaveDTO.pAccountId + " and accountno='" + JointandNomineeSaveDTO.paccountNo + "' and accounttype='" + JointandNomineeSaveDTO.paccounttype + "' AND jointdetailsid not in(" + JointRecordid + ") ; "); } else { if (JointandNomineeSaveDTO.JointDetailsList == null || JointandNomineeSaveDTO.JointDetailsList.Count == 0) { sbUpdate.AppendLine("UPDATE tbltransjointdetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE accountid=" + JointandNomineeSaveDTO.pAccountId + " and accounttype='" + JointandNomineeSaveDTO.paccounttype + "' and accountno='" + JointandNomineeSaveDTO.paccountNo + "'; "); } } // Nominee Details if (JointandNomineeSaveDTO.NomineeDetailsList != null && JointandNomineeSaveDTO.NomineeDetailsList.Count > 0) { for (int i = 0; i < JointandNomineeSaveDTO.NomineeDetailsList.Count; i++) { if (Convert.ToString(JointandNomineeSaveDTO.NomineeDetailsList[i].ptypeofoperation) != "CREATE") { if (string.IsNullOrEmpty(RecordId)) { RecordId = Convert.ToString(JointandNomineeSaveDTO.NomineeDetailsList[i].precordid); } else { RecordId = RecordId + "," + Convert.ToString(JointandNomineeSaveDTO.NomineeDetailsList[i].precordid); } } } for (int i = 0; i < JointandNomineeSaveDTO.NomineeDetailsList.Count; i++) { if (string.IsNullOrEmpty(JointandNomineeSaveDTO.NomineeDetailsList[i].pdateofbirth)) { JointandNomineeSaveDTO.NomineeDetailsList[i].pdateofbirth = "null"; } else { JointandNomineeSaveDTO.NomineeDetailsList[i].pdateofbirth = "'" + FormatDate(JointandNomineeSaveDTO.NomineeDetailsList[i].pdateofbirth) + "'"; } if (Convert.ToString(JointandNomineeSaveDTO.NomineeDetailsList[i].ptypeofoperation) == "CREATE") { SbsaveReferences.AppendLine("insert into tabapplicationpersonalnomineedetails(applicationid, vchapplicationid, contactreferenceid, nomineename, relationship, dateofbirth, contactno, idprooftype, idproofname, referencenumber, docidproofpath, statusid, createdby, createddate,applicantype,isprimarynominee,percentage) values ('" + JointandNomineeSaveDTO.pAccountId + "', '" + JointandNomineeSaveDTO.paccountNo + "','" + JointandNomineeSaveDTO.NomineeDetailsList[i].pcontactno + "', '" + JointandNomineeSaveDTO.NomineeDetailsList[i].pnomineename + "', '" + JointandNomineeSaveDTO.NomineeDetailsList[i].prelationship + "', " + JointandNomineeSaveDTO.NomineeDetailsList[i].pdateofbirth + ", '" + JointandNomineeSaveDTO.NomineeDetailsList[i].pcontactno + "', '" + JointandNomineeSaveDTO.NomineeDetailsList[i].pidprooftype + "', '" + JointandNomineeSaveDTO.NomineeDetailsList[i].pidproofname + "', '" + JointandNomineeSaveDTO.NomineeDetailsList[i].preferencenumber + "', '" + JointandNomineeSaveDTO.NomineeDetailsList[i].pdocidproofpath + "', " + Convert.ToInt32(Status.Active) + ", '" + JointandNomineeSaveDTO.pCreatedby + "', current_timestamp,'" + JointandNomineeSaveDTO.paccounttype + "'," + JointandNomineeSaveDTO.NomineeDetailsList[i].pisprimarynominee + "," + JointandNomineeSaveDTO.NomineeDetailsList[i].pPercentage + ");"); } else if (Convert.ToString(JointandNomineeSaveDTO.NomineeDetailsList[i].ptypeofoperation) == "UPDATE") { SbsaveReferences.AppendLine("Update tabapplicationpersonalnomineedetails set contactreferenceid='" + JointandNomineeSaveDTO.NomineeDetailsList[i].pcontactno + "',nomineename='" + JointandNomineeSaveDTO.NomineeDetailsList[i].pnomineename + "',relationship='" + JointandNomineeSaveDTO.NomineeDetailsList[i].prelationship + "',dateofbirth=" + JointandNomineeSaveDTO.NomineeDetailsList[i].pdateofbirth + ",contactno='" + JointandNomineeSaveDTO.NomineeDetailsList[i].pcontactno + "',idprooftype='" + JointandNomineeSaveDTO.NomineeDetailsList[i].pidprooftype + "',idproofname='" + JointandNomineeSaveDTO.NomineeDetailsList[i].pidproofname + "',referencenumber='" + JointandNomineeSaveDTO.NomineeDetailsList[i].preferencenumber + "',docidproofpath='" + JointandNomineeSaveDTO.NomineeDetailsList[i].pdocidproofpath + "',statusid=" + Convert.ToInt32(Status.Active) + ",modifieddate=current_timestamp,modifiedby=" + JointandNomineeSaveDTO.pCreatedby + ",percentage=" + JointandNomineeSaveDTO.NomineeDetailsList[i].pPercentage + ",isprimarynominee=" + JointandNomineeSaveDTO.NomineeDetailsList[i].pisprimarynominee + " where applicantype='" + JointandNomineeSaveDTO.paccounttype + "' and applicationid=" + JointandNomineeSaveDTO.pAccountId + " and recordid=" + JointandNomineeSaveDTO.NomineeDetailsList[i].precordid + "; "); } } if (!string.IsNullOrEmpty(RecordId)) { sbUpdate.AppendLine("UPDATE tabapplicationpersonalnomineedetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE applicationid=" + JointandNomineeSaveDTO.pAccountId + " and vchapplicationid='" + JointandNomineeSaveDTO.paccountNo + "' AND RECORDID not in(" + RecordId + ") and applicantype='" + JointandNomineeSaveDTO.paccounttype + "'; "); } else { if (JointandNomineeSaveDTO.NomineeDetailsList == null || JointandNomineeSaveDTO.NomineeDetailsList.Count == 0) { sbUpdate.AppendLine("UPDATE tabapplicationpersonalnomineedetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE applicationid=" + JointandNomineeSaveDTO.pAccountId + " and vchapplicationid='" + JointandNomineeSaveDTO.paccountNo + "' and applicantype='" + JointandNomineeSaveDTO.paccounttype + "'; "); } } } if (!string.IsNullOrEmpty(RecordId)) { sbUpdate.AppendLine("UPDATE tabapplicationpersonalnomineedetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE applicationid=" + JointandNomineeSaveDTO.pAccountId + " and vchapplicationid='" + JointandNomineeSaveDTO.paccountNo + "' AND RECORDID not in(" + RecordId + ") and applicantype='" + JointandNomineeSaveDTO.paccounttype + "'; "); } else { if (JointandNomineeSaveDTO.NomineeDetailsList == null || JointandNomineeSaveDTO.NomineeDetailsList.Count == 0) { sbUpdate.AppendLine("UPDATE tabapplicationpersonalnomineedetails SET STATUSID=" + Convert.ToInt32(Status.Inactive) + ", modifiedby = " + JointandNomineeSaveDTO.pCreatedby + ", modifieddate = CURRENT_TIMESTAMP WHERE applicationid=" + JointandNomineeSaveDTO.pAccountId + " and vchapplicationid='" + JointandNomineeSaveDTO.paccountNo + "' and applicantype='" + JointandNomineeSaveDTO.paccounttype + "'; "); } } if (!string.IsNullOrEmpty(SbsaveReferences.ToString())) { NPGSqlHelper.ExecuteNonQuery(trans, CommandType.Text, Convert.ToString(sbUpdate) + " " + Convert.ToString(SbsaveReferences)); trans.Commit(); IsSaved = true; } } catch (Exception Ex) { trans.Rollback(); throw Ex; } finally { if (con.State == ConnectionState.Open) { con.Dispose(); con.Close(); con.ClearPool(); trans.Dispose(); } } return(IsSaved); }