Project

General

Profile

Feature #280 » 3-CsFile.cs

Junaid M, 03/14/2024 02:46 PM

 
???File Path
==========
***...\Src\Travel\SetTarget.cs




???Check the points
==================



// ??? IMPORT:- Add the items top - Duplcation Avoid
using System;
using System.Data;
using System.Collections.Generic;
using Npgsql;
using NpgsqlTypes;

using TAAS.Db;
using TAAS.Models;
using TAAS.Models.Travel;
using TAAS.Helpers;


// ??? CLASS ATTRIBUTES:- The code past top of the class(Attributes) - Duplcation Avoid
public GlobalFunctions insGlobalFunctions = new GlobalFunctions();
DbService insDbService = new();


public List<MdlBaseIntId> FnGetAllSetTargetBaseData()
{
List<MdlBaseIntId> lstMdlSetTargetBaseIntId = new List<MdlBaseIntId>();

// Get Data from DB
DataSet objDataSet = this.insDbService.FnExcecuteSqlCommand("SELECT * FROM fn_get_all_set_target()");
if (objDataSet != null)
{
foreach (DataRow objRecord in objDataSet.Tables[0].Rows)
{
MdlBaseIntId mdlBaseIntId = new MdlBaseIntId();

mdlBaseIntId.binPkId = (DBNull.Value != objRecord["pk_set_target_id"]) ? (long)Convert.ToUInt64(objRecord["pk_set_target_id"]) : mdlBaseIntId.binPkId;
mdlBaseIntId.strCode = (DBNull.Value != objRecord[""]) ? Convert.ToString(objRecord[""]) : mdlBaseIntId.strCode;
mdlBaseIntId.strName = (DBNull.Value != objRecord[""]) ? Convert.ToString(objRecord[""]) : mdlBaseIntId.strName;
lstMdlSetTargetBaseIntId.Add(mdlBaseIntId);
}
}

return lstMdlSetTargetBaseIntId;
}


public List<MdlSetTarget> FnGetAllSetTargetWithActionUser()
{
List<MdlSetTarget> lstMdlSetTarget = new List<MdlSetTarget>();
// Get Data from DB
DataSet objDataSet = this.insDbService.FnExcecuteSqlCommand("SELECT * FROM fn_get_all_set_target_with_action_user()");
if (objDataSet != null)
{
foreach (DataRow objRecord in objDataSet.Tables[0].Rows)
{
MdlSetTarget mdlSetTarget = new MdlSetTarget();

mdlSetTarget.binSetTargetId = (DBNull.Value != objRecord["pk_set_target_id"]) ? (long)Convert.ToInt64(objRecord["pk_set_target_id"]) : mdlSetTarget.binSetTargetId;

mdlSetTarget.sinTargetType = (DBNull.Value != objRecord["sin_target_type"]) ? (short)Convert.ToInt16(objRecord["sin_target_type"]) : mdlSetTarget.sinTargetType;
mdlSetTarget.binAccountId = (DBNull.Value != objRecord["fk_account_id"]) ? (long)Convert.ToInt64(objRecord["fk_account_id"]) : mdlSetTarget.binAccountId;
mdlSetTarget.binCounterStaffId = (DBNull.Value != objRecord["fk_counter_staff_id"]) ? (long)Convert.ToInt64(objRecord["fk_counter_staff_id"]) : mdlSetTarget.binCounterStaffId;
mdlSetTarget.binBranchId = (DBNull.Value != objRecord["fk_branch_id"]) ? (long)Convert.ToInt64(objRecord["fk_branch_id"]) : mdlSetTarget.binBranchId;
mdlSetTarget.binAirlineMasterId = (DBNull.Value != objRecord["fk_airline_master_id"]) ? (long)Convert.ToInt64(objRecord["fk_airline_master_id"]) : mdlSetTarget.binAirlineMasterId;
mdlSetTarget.binHotelMasterId = (DBNull.Value != objRecord["fk_hotel_master_id"]) ? (long)Convert.ToInt64(objRecord["fk_hotel_master_id"]) : mdlSetTarget.binHotelMasterId;

mdlSetTarget.binFinancialYearId = (DBNull.Value != objRecord["fk_financial_year_id"]) ? (long)Convert.ToInt64(objRecord["fk_financial_year_id"]) : mdlSetTarget.binFinancialYearId;

mdlSetTarget.dblRevenueTarget = (DBNull.Value != objRecord["dbl_revenue_target"]) ? (double)Convert.ToDouble(objRecord["dbl_revenue_target"]) : mdlSetTarget.dblRevenueTarget;
mdlSetTarget.strRevenueTargetBasedOn = (DBNull.Value != objRecord["vhr_revenue_target_based_on"]) ? Convert.ToString(objRecord["vhr_revenue_target_based_on"]) : mdlSetTarget.strRevenueTargetBasedOn;
mdlSetTarget.dblYieldTarget = (DBNull.Value != objRecord["dbl_yield_target"]) ? (double)Convert.ToDouble(objRecord["dbl_yield_target"]) : mdlSetTarget.dblYieldTarget;
mdlSetTarget.strYieldTargetBasedOn = (DBNull.Value != objRecord["vhr_yield_target_based_on"]) ? Convert.ToString(objRecord["vhr_yield_target_based_on"]) : mdlSetTarget.strYieldTargetBasedOn;

mdlSetTarget.arlConsiderFkBranchIds = (DBNull.Value != objRecord["arb_consider_fk_branch_ids"]) ? (long[])objRecord["arb_consider_fk_branch_ids"] : mdlSetTarget.arlConsiderFkBranchIds;
mdlSetTarget.arlConsiderFkServiceIds = (DBNull.Value != objRecord["arb_consider_fk_service_ids"]) ? (long[])objRecord["arb_consider_fk_service_ids"] : mdlSetTarget.arlConsiderFkServiceIds;
mdlSetTarget.arlFkPackageCategoryIds = (DBNull.Value != objRecord["arb_fk_package_category_ids"]) ? (long[])objRecord["arb_fk_package_category_ids"] : mdlSetTarget.arlFkPackageCategoryIds;

mdlSetTarget.sinLessRefund = (DBNull.Value != objRecord["sin_less_refund"]) ? (short)Convert.ToInt16(objRecord["sin_less_refund"]) : mdlSetTarget.sinLessRefund;

mdlSetTarget.sinSplitupType = (DBNull.Value != objRecord["sin_splitup_type"]) ? (short)Convert.ToInt16(objRecord["sin_splitup_type"]) : mdlSetTarget.sinSplitupType;
mdlSetTarget.sinMonthWiseSplitup = (DBNull.Value != objRecord["sin_month_wise_splitup"]) ? (short)Convert.ToInt16(objRecord["sin_month_wise_splitup"]) : mdlSetTarget.sinMonthWiseSplitup;


mdlSetTarget.intSysActionId = (DBNull.Value != objRecord["int_sys_action_id"]) ? (int)Convert.ToInt32(objRecord["int_sys_action_id"]) : mdlSetTarget.intSysActionId;
mdlSetTarget.binCreatedUserId = (DBNull.Value != objRecord["fk_created_user_id"]) ? (long)Convert.ToInt64(objRecord["fk_created_user_id"]) : mdlSetTarget.binCreatedUserId;
mdlSetTarget.strCreatedUser = this.insDbService.FnGetValue(objRecord["vhr_created_user"], mdlSetTarget.strCreatedUser);
mdlSetTarget.dtmCreated = (DBNull.Value != objRecord["dtm_created"]) ? (DateTime)Convert.ToDateTime(objRecord["dtm_created"]) : mdlSetTarget.dtmCreated;
mdlSetTarget.binLastModifiedUserId = (DBNull.Value != objRecord["fk_last_modified_user_id"]) ? (long)Convert.ToInt64(objRecord["fk_last_modified_user_id"]) : mdlSetTarget.binLastModifiedUserId;
mdlSetTarget.strLastModifiedUser = this.insDbService.FnGetValue(objRecord["vhr_last_modified_user"], mdlSetTarget.strLastModifiedUser);
mdlSetTarget.dtmLastModified = (DBNull.Value != objRecord["dtm_last_modified"]) ? (DateTime)Convert.ToDateTime(objRecord["dtm_last_modified"]) : mdlSetTarget.dtmLastModified;
mdlSetTarget.binDeletedUserId = (DBNull.Value != objRecord["fk_deleted_user_id"]) ? (long)Convert.ToInt64(objRecord["fk_deleted_user_id"]) : mdlSetTarget.binDeletedUserId;
mdlSetTarget.strDeletedUser = this.insDbService.FnGetValue(objRecord["vhr_deleted_user"], mdlSetTarget.strDeletedUser);
mdlSetTarget.dtmDeleted = (DBNull.Value != objRecord["dtm_deleted"]) ? (DateTime)Convert.ToDateTime(objRecord["dtm_deleted"]) : mdlSetTarget.dtmDeleted;

lstMdlSetTarget.Add(mdlSetTarget);
}
}

return lstMdlSetTarget;
}


public MdlResSetTarget FnInsertOrUpdateSetTarget(MdlReqSetTarget mdlReqSetTarget)
{
// *** Input Validation INSERT and UPDATE Case[not duplicate model validation]
// ??? Duplication Checking in DB FUCTION(Insert and Update) - CODE, NAME [, other unique fields] Already exists
// ??? Count Exced or other checking License related in DB FUCTION(Insert)
// ??? UPDATE Check already update another users in DB FUCTION(Update and Delete)

// Set Create or modified User in DB FUCTION(Insert, Update and Delete)
if (mdlReqSetTarget.mdlSetTarget.binSetTargetId == 0)
{
mdlReqSetTarget.mdlSetTarget.intSysActionId = 0;
mdlReqSetTarget.mdlSetTarget.binCreatedUserId = mdlReqSetTarget.linLoginUserId;
mdlReqSetTarget.mdlSetTarget.strCreatedUser = mdlReqSetTarget.strLoginUserName;
mdlReqSetTarget.mdlSetTarget.dtmCreated = mdlReqSetTarget.dtmCurrentDateTime;
}
else {
mdlReqSetTarget.mdlSetTarget.binLastModifiedUserId = mdlReqSetTarget.linLoginUserId;
mdlReqSetTarget.mdlSetTarget.strLastModifiedUser = mdlReqSetTarget.strLoginUserName;
mdlReqSetTarget.mdlSetTarget.dtmLastModified = mdlReqSetTarget.dtmCurrentDateTime;
}

// DB Actions
NpgsqlParameter[] lstSqlParameter = {
new NpgsqlParameter("mdlSetTarget", NpgsqlDbType.Jsonb) { Value = mdlReqSetTarget.mdlSetTarget, DataTypeName = "jsnSetTarget"},
new NpgsqlParameter("jsnSqlRes", NpgsqlDbType.Json) { DataTypeName = "jsnSqlRes", Direction = ParameterDirection.Output }
};
MdlDbResponse mdlDbResponse = this.insDbService.FnExcecuteOutSqlCommand("CALL sp_insert_or_update_setTarget(:mdlSetTarget, NULL)", lstSqlParameter);
// DB Error
if (mdlDbResponse.sinSqlCustomStatus != 1)
{
if (mdlDbResponse.strSqlCustomErrorType == "DATABASE_ERROR")
{
throw (new TaasDatabaseException(this.insGlobalFunctions.FnGetExceptionResponseString(mdlDbResponse.strSqlCustomMessage, "SETTARGET.CS#004", mdlDbResponse.strSqlSysMessage)));
}
else if (mdlDbResponse.strSqlCustomErrorType == "DATABASE_VALIDATION_ERROR")
{
throw (new TaasDatabaseValidationException(this.insGlobalFunctions.FnGetExceptionResponseString(mdlDbResponse.strSqlCustomMessage, "SETTARGET.CS#002", mdlDbResponse.strSqlSysMessage)));
}
else if (mdlDbResponse.strSqlCustomErrorType == "DATABASE_SYSTEM_ERROR")
{
throw (new TaasDatabaseException(this.insGlobalFunctions.FnGetExceptionResponseString(mdlDbResponse.strSqlCustomMessage, "SETTARGET.CS#003", mdlDbResponse.strSqlSysMessage)));
}
}

// Saved
MdlResSetTarget mdlResSetTarget = new MdlResSetTarget();
mdlResSetTarget.mdlSetTarget = mdlSetTargetReq.mdlSetTarget;
if (mdlReqSetTarget.mdlSetTarget.binSetTargetId == 0)
{
mdlResSetTarget.mdlSetTarget.binSetTargetId = mdlDbResponse.binSqlPk ?? 0;
mdlResSetTarget.mdlSetTarget.dtmCreated = mdlDbResponse.dtmCurrent;
}
else
{
mdlResSetTarget.mdlSetTarget.intSysActionId += 1;
mdlResSetTarget.mdlSetTarget.dtmLastModified = mdlDbResponse.dtmCurrent;
}
mdlResSetTarget.sinStatus = 1;
mdlResSetTarget.strStatusCode = "SUCCESS";
mdlResSetTarget.strMessage = "SETTARGET has been Saved.";
return mdlResSetTarget;
}


public MdlResBaseIntId FnDeleteSetTarget(MdlReqBaseIntId mdlReqSetTargetBaseIntId)
{
// *** Input Validation DELETE Case[not duplicate model validation]
// ??? FOREIGN KEY REFERENCES Ching in DB FUCTION(Delete)
// ??? UPDATE Check already update another users in DB FUCTION(Update and Delete)
// ??? Set Create or modified User in DB FUCTION(Insert, Update and Delete)

// DB Actions
NpgsqlParameter[] lstSqlParameter = {
new NpgsqlParameter("binSetTargetId", NpgsqlDbType.Bigint) { Value = mdlReqSetTargetBaseIntId.mdlBaseIntId.binPkId, DataTypeName = "binSetTargetId"},
new NpgsqlParameter("intSysActionId", NpgsqlDbType.Integer) { Value = mdlReqSetTargetBaseIntId.mdlBaseIntId.binCustomValue, DataTypeName = "intSysActionId"},
new NpgsqlParameter("binDeletedUserId", NpgsqlDbType.Bigint) { Value = mdlReqSetTargetBaseIntId.linLoginUserId, DataTypeName = "binDeletedUserId"},
new NpgsqlParameter("jsnSqlRes", NpgsqlDbType.Json) { DataTypeName = "jsnSqlRes", Direction = ParameterDirection.Output }
};
MdlDbResponse mdlDbResponse = this.insDbService.FnExcecuteOutSqlCommand("CALL sp_delete_setTarget(:binSetTargetId, :intSysActionId, :binDeletedUserId, NULL)", lstSqlParameter);
// DB Error
if (mdlDbResponse.sinSqlCustomStatus != 1)
{
if (mdlDbResponse.strSqlCustomErrorType == "DATABASE_ERROR")
{
throw (new TaasDatabaseException(this.insGlobalFunctions.FnGetExceptionResponseString(mdlDbResponse.strSqlCustomMessage, "SETTARGET.CS#004", mdlDbResponse.strSqlSysMessage)));
}
else if (mdlDbResponse.strSqlCustomErrorType == "DATABASE_VALIDATION_ERROR")
{
throw (new TaasDatabaseValidationException(this.insGlobalFunctions.FnGetExceptionResponseString(mdlDbResponse.strSqlCustomMessage, "SETTARGET.CS#005", mdlDbResponse.strSqlSysMessage)));
}
else if (mdlDbResponse.strSqlCustomErrorType == "DATABASE_SYSTEM_ERROR")
{
throw (new TaasDatabaseException(this.insGlobalFunctions.FnGetExceptionResponseString(mdlDbResponse.strSqlCustomMessage, "SETTARGET.CS#006", mdlDbResponse.strSqlSysMessage)));
}
}

// Deleted
MdlResBaseIntId mdlResSetTargetIntId = new MdlResBaseIntId();

mdlResSetTargetIntId.mdlBaseIntId = mdlReqSetTargetBaseIntId.mdlBaseIntId;
mdlResSetTargetIntId.sinStatus = 1;
mdlResSetTargetIntId.strStatusCode = "SUCCESS";
mdlResSetTargetIntId.strMessage = "SETTARGET has been deleted.";

return mdlResSetTargetIntId;
}

(4-4/11)