I have scoured the internet for this answer and asked several developers and have come up short. I have a Class called StaffingPositionsDataContract that I am loading mock data (for now) into a List<> and returning to a page. This is working great, but now I need to filter the list based on another list of values that are inputted on the screen, send to this service as JSON, then deserialized into a list of the same class. Note that the user can filter on any one of these class members, so all may be null, or one may be null, etc. Here is the service method:
public List<StaffingPositionsDataContract> GetStaffingPosition(string searchFilters)
{
var filters = JsonConvert.DeserializeObject<List<StaffingPositionsDataContract>>(searchFilters);
IList<StaffingPositionsDataContract> contracts = new StaffingPositionsDataContract().LoadMockData();
if (searchFilters.Length > 4)
{
//Filter contracts here!
}
return contracts;
}
Here is the Data Contract Class with Mock data to load:
[DataContract] [Serializable]
public class StaffingPositionsDataContract
{
[DataMember(Order = 1)] public int PositionId { get; set; }
[DataMember(Order = 2)] public string Series { get; set; }
[DataMember(Order = 3)] public string BFY { get; set; }
[DataMember(Order = 4)] public string BudgetStatus { get; set; }
[DataMember(Order = 5)] public string DutyStation { get; set; }
[DataMember(Order = 6)] public string OrgLocation { get; set; }
[DataMember(Order = 7)] public string BudgetingEntity { get; set; }
[DataMember(Order = 8)] public string SeriesTitle { get; set; }
[DataMember(Order = 9)] public int PersonnelId { get; set; }
[DataMember(Order = 10)] public string PositionStatus { get; set; }
[DataMember] public int RecId { get; set; }
public List<StaffingPositionsDataContract> LoadMockData()
{
List<StaffingPositionsDataContract> staffingposition = new List<StaffingPositionsDataContract>()
{
new StaffingPositionsDataContract() {RecId=1, PositionId = 12345, Series="", BFY="FY2010", BudgetStatus="Actual", DutyStation="", OrgLocation="", BudgetingEntity=""},
new StaffingPositionsDataContract() {RecId=2, PositionId = 67891, Series="", BFY="FY2011", BudgetStatus="Actual", DutyStation="", OrgLocation="", BudgetingEntity=""},
new StaffingPositionsDataContract() {RecId=3,PositionId = 12345, Series="", BFY="FY2010", BudgetStatus="Projected", DutyStation="", OrgLocation="", BudgetingEntity=""},
new StaffingPositionsDataContract() {RecId=4,PositionId = 67892, Series="", BFY="FY2011", BudgetStatus="Projected", DutyStation="", OrgLocation="", BudgetingEntity=""},
new StaffingPositionsDataContract() {RecId=5,PositionId = 987654, Series="", BFY="FY2010", BudgetStatus="Projected", DutyStation="", OrgLocation="", BudgetingEntity=""}
};
return staffingposition;
}
}
Note that filters will always be a list of one, some or all values being populated. Please save my sanity and help if you can! THANKS!
I should have noted earlier that I REALLY want this to be a generic function that can be used by any of these similar data classes(there are many).