public listView <Entity> RosterEventView(string version, ICollection <abstractSearch> filter, QueryDisplayParams query) { DisableCaching(); var result = new listView <Entity>(); try { var viewId = filter.filterTextValue("viewId").ToGuid(); result.page = new pager <Entity>(); var service = new RosterDataService(); var content = service.ViewRosterEvents(viewId).ToList(); result.total = content.Count(); content.Take(query.currentPageSize).Skip(query.currentPageNum * query.currentPageSize).ToList().ForEach(item => { result.page.pageItems.Add(new Entity { Key = item.Id.ToSafeString(), Fields = item.RosterEventProperties.ExpandoToNamed() }); }); } catch (Exception ex) { result.message.message = ex.Message; result.message.messageLevel = messageLevelEnum.critical; //HandleException(ex); } return(result); }
public SPCalendarItemCollection SelectDataForCalendar(short calendarType, Tuple <DateTime, DateTime> calendarPeriod, string calendarScope, out object rostersForColoring) { var query = new QueryParams(); var listFields = this.m_view.ListMetadata.ListMetadataFields; var startDateFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.START_DATE); var endDateFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.END_DATE); // set filter according period displayed by Calendar query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(startDateFld, CompareType.LessOrEqual, ConcateOperator.And, calendarPeriod.Item2, null)); query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(endDateFld, CompareType.MoreOrEqual, ConcateOperator.And, calendarPeriod.Item1, null)); // add filter if (this.m_GridFilterExpression != null && this.m_GridFilterExpression.WhereCriteria.Any()) { query.WhereCriteria.AddRange(this.m_GridFilterExpression.WhereCriteria); } // extract Roster data RosterDataService _dataSrv = new RosterDataService(); //List<RosterEvent> rosters = (this.m_view.ListMetadataId == Roster.Common.TableIDs.TIMESHEET_ROSTERS && this.displayPrepopulatedRosters) ? // _dataSrv.ViewTimesheetEvents(this.m_view.Id, query, calendarPeriod) : _dataSrv.ViewRosterEvents(this.m_view.Id, query); List <RosterEvent> rosters = _dataSrv.ViewRosterEvents(this.m_view.Id, query); // expant recurrent events var tZone = SPContext.Current.Web.RegionalSettings.TimeZone; List <ExpandedRosterEvent> expandedEvents = RecurrenceItemExpander.Expand(rosters, null, calendarPeriod.Item1, calendarPeriod.Item2, FieldNames.START_DATE, FieldNames.END_DATE, tZone).ToList(); // send Object to output for coloring if (!this.m_view.GetDerializedDynamicColourSettings().IsEmpty) { if (this.dynColoring_OriginalRosterId != Guid.Empty && !rosters.Any(r => r.Id == this.dynColoring_OriginalRosterId)) { List <RosterEvent> rosters_dynColor = rosters; RosterEvent origRoster = _dataSrv.GetRosterEvent(this.dynColoring_OriginalRosterId); // !! don't return all properties // get events around Orig.Roster var queryDyn = new QueryParams(); queryDyn.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(startDateFld, CompareType.LessOrEqual, ConcateOperator.And, origRoster.GetEndDate(), null)); queryDyn.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(endDateFld, CompareType.MoreOrEqual, ConcateOperator.And, origRoster.GetStartDate(), null)); rosters_dynColor.AddRange(_dataSrv.ViewRosterEvents(this.m_view.Id, queryDyn)); rosters_dynColor = rosters_dynColor.GroupBy(r => r.Id).Select(g => g.First()).ToList(); // remove duplicates rostersForColoring = RecurrenceItemExpander.Expand(rosters_dynColor, null, calendarPeriod.Item1, calendarPeriod.Item2, FieldNames.START_DATE, FieldNames.END_DATE, tZone); // for dynamic coloring // add original Roster (only for Dynamic colour-coding) expandedEvents.Add(new ExpandedRosterEvent(rosters_dynColor.First(r => r.Id == this.dynColoring_OriginalRosterId), true, tZone)); } else { rostersForColoring = expandedEvents; // for dynamic coloring } } else { rostersForColoring = rosters; // for static coloring } // get default DispForm url and default EventTypeId for rosters string defaultDispFormUrl = string.Format("{0}/{1}&ListId={2}", SPContext.Current.Web.ServerRelativeUrl.TrimEnd('/'), this.m_view.ListMetadata.DispItemUrl.TrimStart('/'), SPEncode.UrlEncode(this.m_view.ListMetadataId.ToString("B").ToUpper())); var matchEventType = Regex.Match(defaultDispFormUrl, @"EventType=(?<eType>\d+)"); int defaultEventType = matchEventType.Success ? matchEventType.Groups["eType"].Value.ToInt() : -1; string eventTitleFieldName = this.m_view.GetEventTitleFieldName(calendarScope); string eventLocationFieldName = this.m_view.GetEventLocationFieldName(calendarScope); // init some variables for Working Rosters which are displayed on TIMESHEET view string workingRoster_DispFormUrl = string.Empty; string workingRosterEventTitleFieldName = string.Empty; string workingRosterEventLocationFieldName = string.Empty; if (this.m_view.ListMetadataId == Roster.Common.TableIDs.TIMESHEET_ROSTERS) { var workingRosterList = new RosterConfigService().GetList(Roster.Common.TableIDs.WORKING_ROSTERS); workingRoster_DispFormUrl = string.Format("{0}/{1}&ListId={2}", SPContext.Current.Web.ServerRelativeUrl.TrimEnd('/'), workingRosterList.DispItemUrl.TrimStart('/'), SPEncode.UrlEncode(workingRosterList.Id.ToString("B").ToUpper())); var workingRosterView = workingRosterList.ViewMetadatas.FirstOrDefault(x => x.Name == ViewNames.WORKING_ROSTERS_FOR_TIMESHEETS); workingRosterEventTitleFieldName = (workingRosterView != null) ? workingRosterView.GetEventTitleFieldName(calendarScope) : FieldNames.START_DATE; workingRosterEventLocationFieldName = (workingRosterView != null) ? workingRosterView.GetEventLocationFieldName(calendarScope) : FieldNames.END_DATE; } // init Calendar Items var items = new SPCalendarItemCollection(); items.AddRange(expandedEvents.Select(x => new SPCalendarItem() { DisplayFormUrl = (defaultEventType == x.EventTypeId) ? defaultDispFormUrl : workingRoster_DispFormUrl, CalendarType = calendarType, ItemID = x.InstanceID, StartDate = x.StartDate, EndDate = x.EndDate, hasEndDate = true, Title = ((IDictionary <string, object>)x.OriginalItem.RosterEventProperties)[(defaultEventType == x.EventTypeId) ? eventTitleFieldName : workingRosterEventTitleFieldName].ToString(), Location = ((IDictionary <string, object>)x.OriginalItem.RosterEventProperties)[(defaultEventType == x.EventTypeId) ? eventLocationFieldName : workingRosterEventLocationFieldName].ToString(), IsAllDayEvent = x.OriginalItem.GetIsAllDayEvent(), IsRecurrence = x.OriginalItem.GetIsRecurrence() }).ToList()); return(items); }