Exemple #1
0
        private List <Schedule> GetAllScheduleFiltered(bool byUser, string start_date = null, string end_date = null)
        {
            List <Schedule> scheduleList = new List <Schedule>();

            scheduleList = Session["FilterSchedules"] as List <Schedule>;
            Session["FilterSchedules"] = scheduleList; // Set again to renew Session

            using (ScheduleManager schManager = new ScheduleManager())
                using (SubjectManager subManager = new SubjectManager())
                {
                    if (scheduleList == null)
                    {
                        scheduleList = schManager.GetAllSchedules().ToList();
                        // Set filtered list to full list
                        Session["FilterSchedules"] = scheduleList;
                    }

                    // filter by start and end date
                    if (start_date != null && end_date != null)
                    {
                        DateTime startDate = DateTime.Parse(start_date.ToString());
                        DateTime endDate   = DateTime.Parse(end_date.ToString());

                        scheduleList = scheduleList.Where(a => ((DateTime)a.StartDate >= startDate && (DateTime)a.EndDate <= endDate) || ((DateTime)a.EndDate >= startDate && (DateTime)a.EndDate <= endDate) || (DateTime)a.StartDate <= startDate && (DateTime)a.EndDate >= endDate).ToList();
                    }
                    else if (start_date != null && end_date == null)
                    {
                        DateTime startDate = DateTime.Parse(start_date.ToString());

                        scheduleList = scheduleList.Where(a => ((DateTime)a.EndDate >= startDate)).ToList();
                    }

                    if (byUser == true)
                    {
                        User user = subManager.Subjects.Where(a => a.Name == HttpContext.User.Identity.Name).FirstOrDefault() as User;

                        var scheduleListNew = FilterSchedulesByUser(scheduleList, user.Id).Concat(FilterSchedulesForUser(scheduleList, user.Id)).ToList();
                        scheduleList = scheduleListNew.Distinct().ToList();
                    }

                    return(scheduleList);
                }
        }
Exemple #2
0
 public IEnumerable <DtoScheduleListItem> List()
 {
     return(scheduleManager.GetAllSchedules());
 }
Exemple #3
0
        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());
                    }
            }
        }