Пример #1
0
        public GetContentTypeResult GetContentTypeByRosterId(GetContentTypeQuery query)
        {
            DisableCaching();
            var result = new GetContentTypeResult();

            try
            {
                var dataService = new RosterDataService();
                {
                    var roster = dataService.GetRosterEvent(query.RosterId);
                    if (roster != null)
                    {
                        var rosterProps = roster.RosterEventDictionary;
                        if (rosterProps.ContainsKey(FieldNames.CONTENT_TYPE_ID))
                        {
                            int ctId = rosterProps[FieldNames.CONTENT_TYPE_ID].ToInt();

                            var ct = new RosterConfigService().GetContentType(ctId);
                            if (ct != null)
                            {
                                result.DispItemUrl   = ct.DispItemUrl;
                                result.EditItemUrl   = ct.EditItemUrl;
                                result.NewItemUrl    = ct.NewItemUrl;
                                result.Name          = ct.Name;
                                result.Id            = ct.Id;
                                result.IsDefault     = ct.IsDefault;
                                result.IsOnNewAction = ct.IsOnNewAction;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                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);
        }
Пример #3
0
        public static void PublishRosterEvent(Guid itemId, int daysAhead)
        {
            var dataService = new RosterDataService();
            var item        = dataService.GetRosterEvent(itemId);

            if (item == null)
            {
                throw new Exception(string.Format("Roster with ID '{0}' does not exists!", itemId));
            }
            if (!item.GetIsRecurrence())
            {
                throw new Exception(string.Format("Unable to publish non recurrent Roster Event with ID '{0}'!", itemId));
            }
            var wrListFields = new RosterConfigService().GetList(TableIDs.WORKING_ROSTERS).ListMetadataFields;

            var plannedRosterProps = item.RosterEventDictionary;
            var publishPeriodStart = DateTime.Today;
            var publishPeriodEnd   = DateTime.Today.AddDays(daysAhead);
            var expandedEvents     = RecurrenceItemExpander.Expand(new List <RosterEvent> {
                item
            },
                                                                   null, publishPeriodStart, publishPeriodEnd,
                                                                   FieldNames.START_DATE, FieldNames.END_DATE,
                                                                   SPContext.Current.Web.RegionalSettings.TimeZone);
            var skipProps = new[]
            {
                FieldNames.START_DATE, FieldNames.END_DATE,
                FieldNames.RECURRENCE, FieldNames.ROSTER_EVENT_ID,
                FieldNames.ID, FieldNames.PARENT_ROSTER_ID
            };
            var expandedRosterEvents = expandedEvents as IList <ExpandedRosterEvent> ?? expandedEvents.ToList();

            publishPeriodStart = expandedRosterEvents.Min(expandedEvent => expandedEvent.StartDate);
            publishPeriodEnd   = expandedRosterEvents.Max(expandedEvent => expandedEvent.StartDate);

            #region Get Working Rosters from period to avoid duplicates

            // get required fields
            var startDateFld = wrListFields.FirstOrDefault(itm => itm.InternalName == FieldNames.START_DATE);
            var endDateFld   = wrListFields.FirstOrDefault(itm => itm.InternalName == FieldNames.END_DATE);
            var parentIdFld  = wrListFields.FirstOrDefault(itm => itm.InternalName == FieldNames.PARENT_ROSTER_ID);
            var rEventIdFld  = wrListFields.FirstOrDefault(itm => itm.InternalName == FieldNames.ROSTER_EVENT_ID);

            var qp = new QueryParams {
                SkipRows = 0, TakeRows = 500
            };
            qp.SelectCriteria.Add(startDateFld);
            qp.SelectCriteria.Add(rEventIdFld);
            qp.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>
                                     (parentIdFld, CompareType.Equal, ConcateOperator.And, itemId, null));
            qp.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>
                                     (startDateFld, CompareType.LessOrEqual, ConcateOperator.And, publishPeriodEnd, null));
            qp.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>
                                     (endDateFld, CompareType.MoreOrEqual, ConcateOperator.And, publishPeriodStart, null));

            var existingWorkRosters = dataService.ListRosterEventProperties(TableIDs.WORKING_ROSTERS, qp);
            var existingKeys        = existingWorkRosters.Select(wrProps => wrProps.FirstOrDefault(ff =>
                                                                                                   ff.Key == FieldNames.START_DATE)).Select(stKey => (DateTime)stKey.Value).ToList();

            #endregion

            foreach (var expEvent in expandedRosterEvents)
            {
                var startDate = expEvent.StartDate;
                var endDate   = expEvent.EndDate;
                if (existingKeys.Contains(startDate))
                {
                    continue;
                }                                                   // this WorkingRoster instance already published
                var newRoEv = dataService.CreateRosterEvent(TableIDs.WORKING_ROSTERS, (int)RosterEventType.WorkingRosterEvent);
                newRoEv.RosterEventDictionary[FieldNames.START_DATE]       = startDate;
                newRoEv.RosterEventDictionary[FieldNames.END_DATE]         = endDate;
                newRoEv.RosterEventDictionary[FieldNames.END_DATE]         = endDate;
                newRoEv.RosterEventDictionary[FieldNames.RECURRENCE]       = null;
                newRoEv.RosterEventDictionary[FieldNames.PARENT_ROSTER_ID] = itemId;
                foreach (var propName in plannedRosterProps.Keys.Where(propName => !skipProps.Contains(propName)))
                {
                    newRoEv.RosterEventDictionary[propName] = plannedRosterProps[propName];
                }
                dataService.SaveRosterEvent(newRoEv, TableIDs.WORKING_ROSTERS);
            }
        }
Пример #4
0
        private List <VersionDetails> _getDataSource()
        {
            var versions    = new List <VersionDetails>();
            var dataService = new RosterDataService();
            var rosterEvent = dataService.GetRosterEvent(this.ItemId.Value);
            var listId      = ListId.HasValue ? ListId.Value :
                              (rosterEvent.EventTypeId == 0) ? TableIDs.PLANNED_ROSTERS : TableIDs.WORKING_ROSTERS;
            var allListFields = new RosterConfigService().GetList(listId).ListMetadataFields.Select(fld => fld.GetDbField());
            // get history items
            var historyInfo = dataService.ListTrackData(this.ItemId.Value);

            string[] excludeFields = new string[] { FieldNames.ID, FieldNames.ROSTER_EVENT_ID,
                                                    FieldNames.CONTENT_TYPE_ID, FieldNames.MODIFIED, FieldNames.MODIFIED_BY };
            for (int k = 0; k < historyInfo.Count; k++)
            {
                var currentVersionTrackData = historyInfo[k].TrackDataDictionary;
                var fldModifiedByText       = string.Empty;
                var fldModifiedBy           = allListFields.FirstOrDefault(f => f.InternalName.Equals(FieldNames.MODIFIED_BY));
                if (fldModifiedBy != null)
                {
                    if (currentVersionTrackData.ContainsKey(FieldNames.MODIFIED_BY))
                    {
                        fldModifiedByText = fldModifiedBy.GetFieldValueAsText(currentVersionTrackData[FieldNames.MODIFIED_BY]);
                    }
                }
                var vd = new VersionDetails(historyInfo[k], fldModifiedByText);
                if (k == historyInfo.Count - 1)
                {
                    foreach (string fldName in currentVersionTrackData.Keys.Where(ke => !excludeFields.Contains(ke)))
                    {
                        var fld = allListFields.FirstOrDefault(f => f.InternalName.Equals(fldName));
                        if (fld == null)
                        {
                            continue;
                        }
                        vd.Changes.Add(new ChangeInfo
                        {
                            FieldName  = fld.DisplayName,
                            FieldValue = fld.GetFieldValueAsText(currentVersionTrackData[fldName])
                        });
                    }
                }
                else
                {
                    var prevVersionTrackData = historyInfo[k + 1].TrackDataDictionary;
                    foreach (string fldName in currentVersionTrackData.Keys.Where(ke => !excludeFields.Contains(ke)))
                    {
                        if (!prevVersionTrackData.ContainsKey(fldName) || (prevVersionTrackData.ContainsKey(fldName) &&
                                                                           prevVersionTrackData.GetValue(fldName).ToSafeString() != currentVersionTrackData[fldName].ToSafeString()))
                        {
                            var fld = allListFields.FirstOrDefault(f => f.InternalName.Equals(fldName));
                            if (fld == null)
                            {
                                continue;
                            }
                            vd.Changes.Add(new ChangeInfo
                            {
                                FieldName  = fld.DisplayName,
                                FieldValue = fld.GetFieldValueAsText(currentVersionTrackData[fldName])
                            });
                        }
                    }
                }
                if (vd.Changes.Count() == 0)
                {
                    vd.Changes.Add(new ChangeInfo {
                        FieldName = "No changes", FieldValue = string.Empty
                    });
                }
                versions.Add(vd);
            }
            return(versions);
        }