public static bool CheckTreeDomainModel(ResourceAttributeValueModel model, Dictionary <long, List <string> > filters) { foreach (KeyValuePair <long, List <string> > kp in filters) { if (IsResult(model, kp.Key, kp.Value) == false) { return(false); } } return(true); }
//checks if is a filter result private bool IsResult(ResourceAttributeValueModel model, long id, List <string> values) { bool temp = false; foreach (string value in values) { //int index = model.AttributeIds.IndexOf(id); //if (model.Values.ElementAt(index).Equals(value)) if (model.Values.Contains(value)) { temp = true; } } return(temp); }
private List <Schedule> GetAffectedSchedules(Dictionary <long, List <string> > dictionary, DateTime startDate, DateTime endDate) { using (ScheduleManager sManager = new ScheduleManager()) using (ResourceManager srManager = new ResourceManager()) { List <ResourceAttributeValueModel> resourceAttributeValueModels = new List <ResourceAttributeValueModel>(); //get all resources List <SingleResource> resources = srManager.GetAllResources().ToList(); //Create for each Resource ResourceAttributeValueModel witch includes all Attribute Ids and all values foreach (SingleResource r in resources) { ResourceAttributeValueModel treeDomainModel = new ResourceAttributeValueModel(r); resourceAttributeValueModels.Add(treeDomainModel); } List <ResourceAttributeValueModel> temp = new List <ResourceAttributeValueModel>(); List <ResourceModel> resultResourceList = new List <ResourceModel>(); //check for every TreeDomainModel (resource) if fits the filter foreach (ResourceAttributeValueModel m in resourceAttributeValueModels) { if (CheckTreeDomainModel(m, dictionary)) { resultResourceList.Add(new ResourceModel(m.Resource)); } } //get all schedules in the selected time period List <Schedule> tempSchedules = sManager.GetSchedulesBetweenStartAndEndDate(startDate, endDate); List <Schedule> affectedSchedules = new List <Schedule>(); //go through all resource which have the selected filter a check if there are schedules foreach (ResourceModel resource in resultResourceList) { List <Schedule> s = tempSchedules.Where(a => a.Resource.Id == resource.Id).ToList(); if (s.Count() > 0) { affectedSchedules.AddRange(s); } } return(affectedSchedules); } }
public ActionResult OnSelectTreeViewItemFilter(string selectedItems) { if (selectedItems == null) { Session["FilterSchedules"] = null; return(new EmptyResult()); } else { using (ScheduleManager schManager = new ScheduleManager()) using (ResourceManager srManager = new ResourceManager()) { //results after filtering List <Schedule> resultScheduleList = new List <Schedule>(); //result resource list after filtering List <long> resultResourceIDList = new List <long>(); //Filter is this format: AttrID_DomainItem, AttrID_Domain List <string> items = selectedItems.Split(',').ToList(); //get all schedules List <Schedule> allSchedules = schManager.GetAllSchedules().ToList(); //get all scheduled resources List <SingleResource> resourcesList; if (Session["resourcesList"] == null) { resourcesList = srManager.GetAllResources().ToList(); Session["resourcesList"] = resourcesList; } else { resourcesList = (List <SingleResource>)Session["resourcesList"]; } List <ResourceFilterHelper.FilterTreeItem> filterList = new List <ResourceFilterHelper.FilterTreeItem>(); //split Id and DomainItem and add it to a FilterItem list foreach (string item in items) { //index 0 = attrbute id, index1 domainvalue List <string> i = item.Split('_').ToList(); ResourceFilterHelper.FilterTreeItem filterItem = new ResourceFilterHelper.FilterTreeItem(); try { filterItem.Id = Convert.ToInt64(i[0]); } catch (Exception e) { Console.WriteLine(e); throw; } try { filterItem.Value = i[1].ToString(); } catch (Exception e) { Console.WriteLine(e); throw; } filterList.Add(filterItem); } List <ResourceAttributeValueModel> treeDomainList = new List <ResourceAttributeValueModel>(); if (Session["treeDomainModel"] == null) { //Create for each Resource TreeDomainModel witch includes all Attribute Ids and all values foreach (SingleResource r in resourcesList) { ResourceAttributeValueModel treeDomainModel = new ResourceAttributeValueModel(r); treeDomainList.Add(treeDomainModel); } Session["treeDomainModel"] = treeDomainList; } else { treeDomainList = (List <ResourceAttributeValueModel>)Session["treeDomainModel"]; } //Dictionary to save every Filter (domain items) to one attr Dictionary <long, List <string> > filterDic = ResourceFilterHelper.GetFilterDic(filterList); List <ResourceAttributeValueModel> temp = new List <ResourceAttributeValueModel>(); //check for every TreeDomainModel (resource) if fits the filter foreach (ResourceAttributeValueModel m in treeDomainList) { if (ResourceFilterHelper.CheckTreeDomainModel(m, filterDic)) { resultResourceIDList.Add(m.Resource.Id); } } //create schedule resource list with selected resources foreach (Schedule s in allSchedules) { if (resultResourceIDList.Contains(s.Resource.Id)) { resultScheduleList.Add(s); } } Session["FilterSchedules"] = resultScheduleList; //return Redirect(Request.UrlReferrer.ToString()); return(new EmptyResult()); } } }