The 2 Methods below use exactly the same parameters
The first method-1 users the method to generate a list from database
records using a stored procedure
The second Method-2 uses the same parameters but this time to write or
delete a record
Method-1
[]public static List<LocationModel> GetUsers_Filtered(string locationid,string locationdes,string thecompany,string dummyidx ,string dowhat)
{
var p = new
{
locationidx = locationid,
locdescriptionx = locationdes,
companycodex = thecompany,
idx = Convert.ToInt32(dummyidx),
dowhatx = dowhat
};
return NewDataAccess.ReadData<LocationModel>("public.splocationcode_search", p);
}[/code]
Method-2
[] public static void CreateLocation(string locationvalue, string locdescriptionvalue, string companycodevalue, int idvalue, string dowhatvalue)
{
// Note This parameter definition is good for inserts and updates and delete into/From the database
var p = new
{
locationidx = locationvalue,
locdescriptionx = locdescriptionvalue,
companycodex = companycodevalue,
idx = idvalue,
dowhatx = dowhatvalue // Can be UI DM or DP ie UpdateInsert, DeleteMarked or DeletePermanent
};
switch (LoginDetails.staticinsertupdatedeletetag)
{
case "IU": // Update and Inserts Stored Procedure
NewDataAccess.WriteData("public.splocationcode_updateinsert", p);
break;
case "DM": // Delete Marked
NewDataAccess.WriteData("public.splocationcode_delete", p);
break;
default:
break;
}
}[/code]
The 2 methods work as required but i would if possible not like to
repeat the same set of parameters twice.
How can I refactor this code to ensure that the portion below is not repeated twice
var p = new
{
locationidx = locationid,
locdescriptionx = locationdes,
companycodex = thecompany,
idx = Convert.ToInt32(dummyidx),
dowhatx = dowhat
};
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.