public List <dynamic> AddUpdateApproverData(ApproverSetting approverSetting) { List <dynamic> objDynamic = new List <dynamic>(); ApproverSettingDTO approverSettingDTO = new ApproverSettingDTO(); try { switch (approverSetting.Type) { case 1: { var Data = JsonConvert.DeserializeObject <List <ApproverSettingDTO> >(approverSetting.ApproverData); for (int i = 0; i < Data.Count; i++) { approverSettingDTO = Data[i]; if (!string.IsNullOrEmpty(UserID)) { approverSettingDTO.UserID = Convert.ToInt64(UserID); } approverSettingDTO.CustId = approverSetting.CustId; if (approverSettingDTO.Ischange == 1) { if (approverSettingDTO.CustApproverId == 0) { approverSettingDTO.Type = 1; approverSettingDTO.IsActive = true; } else { approverSettingDTO.Type = 2; approverSettingDTO.IsActive = true; } if (approverSettingDTO.IsDelete) { approverSettingDTO.Type = 3; approverSettingDTO.IsActive = false; } AddUpdateApprover(approverSettingDTO); if (approverSetting.Status == -99) { break; } } } break; } } } catch (Exception ex) { } objDynamic.Add(approverSetting.Status); objDynamic.Add(GetApproverData(approverSetting.CustId)); return(objDynamic); }
private ApproverSettingDTO AddUpdateApprover(ApproverSettingDTO approverSettingDTO) { string insertProcedure = "[CreateCustomerApproverSetting]"; SqlCommand insertCommand = new SqlCommand(insertProcedure, connection); insertCommand.CommandType = CommandType.StoredProcedure; if (approverSettingDTO.CustApproverId != 0) { insertCommand.Parameters.AddWithValue("@CustApproverId ", approverSettingDTO.CustApproverId); } else { insertCommand.Parameters.AddWithValue("@CustApproverId ", 0); } if (approverSettingDTO.CustId != 0) { insertCommand.Parameters.AddWithValue("@CustId ", approverSettingDTO.CustId); } else { insertCommand.Parameters.AddWithValue("@CustId ", 0); } if (approverSettingDTO.ApproverSerial != 0) { insertCommand.Parameters.AddWithValue("@ApproverSerial ", approverSettingDTO.ApproverSerial); } else { insertCommand.Parameters.AddWithValue("@ApproverSerial ", 0); } if (!string.IsNullOrEmpty(approverSettingDTO.ApproverNameDisplay)) { insertCommand.Parameters.AddWithValue("@ApproverNameDisplay ", approverSettingDTO.ApproverNameDisplay); } else { insertCommand.Parameters.AddWithValue("@ApproverNameDisplay", 0); } if (approverSettingDTO.UserID != 0) { insertCommand.Parameters.AddWithValue("@UserId ", approverSettingDTO.UserID); } else { insertCommand.Parameters.AddWithValue("@UserId", 0); } if (approverSettingDTO.IsActive) { insertCommand.Parameters.AddWithValue("@IsActive", approverSettingDTO.IsActive); } else { insertCommand.Parameters.AddWithValue("@IsActive", 0); } if (approverSettingDTO.Type != 0) { insertCommand.Parameters.AddWithValue("@StatementType", approverSettingDTO.Type); } else { insertCommand.Parameters.AddWithValue("@StatementType", 0); } insertCommand.Parameters.Add("@CustApproverIdout", System.Data.SqlDbType.Int); insertCommand.Parameters["@CustApproverIdout"].Direction = ParameterDirection.Output; insertCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int); insertCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output; try { int count = 0; connection.Open(); insertCommand.ExecuteNonQuery(); if (insertCommand.Parameters["@ReturnValue"].Value != DBNull.Value) { count = System.Convert.ToInt32(insertCommand.Parameters["@ReturnValue"].Value); approverSettingDTO.Status = count; } if (count != 0 && approverSettingDTO.CustApproverId == 0) { approverSettingDTO.CustApproverId = System.Convert.ToInt32(insertCommand.Parameters["@CustApproverIdout"].Value); } return(approverSettingDTO); } catch (Exception ex) { log.logErrorMessage("ApproverSettingData.AddUpdateApprover"); log.logErrorMessage(ex.StackTrace); return(approverSettingDTO); } finally { connection.Close(); } }