Пример #1
0
        public async Task <JsonResult> GetUserEventsByTimeLine(Guid?userId, DateTime?origin,
                                                               CalendarTimeLineType timeLineType = CalendarTimeLineType.Month, int expandDayPrecision = 0)
        {
            var response = new ResultModel <IEnumerable <GetEventViewModel> >();

            if (!await _organizationService.IsUserPartOfOrganizationAsync(userId, _userManager.CurrentUserTenantId))
            {
                response.Errors.Add(new ErrorModel(string.Empty, "User not found or not assigned to this organization"));
                return(Json(response));
            }

            var eventRequest = await _calendarManager.GetUserEventsByTimeLineAsync(userId, origin, timeLineType, expandDayPrecision);

            return(Json(EventMapper.MapWithHelpers(eventRequest), _serializeSettings));
        }
Пример #2
0
        /// <inheritdoc />
        /// <summary>
        /// Get events
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="origin">Default is today date</param>
        /// <param name="timeLineType">Specify the interval of time</param>
        /// <param name="expandDayPrecision">Specify the expand interval in days, default is zero</param>
        /// <returns></returns>
        public async Task <ResultModel <IEnumerable <CalendarEvent> > > GetUserEventsByTimeLineAsync(Guid?userId, DateTime?origin,
                                                                                                     CalendarTimeLineType timeLineType = CalendarTimeLineType.Month,
                                                                                                     int expandDayPrecision            = 0)
        {
            var response = new ResultModel <IEnumerable <CalendarEvent> >();

            if (!userId.HasValue)
            {
                response.Errors.Add(new ErrorModel(string.Empty, "User not specified"));
                return(response);
            }
            var today = origin ?? DateTime.Now;

            switch (timeLineType)
            {
            case CalendarTimeLineType.Day:
                response = await GetEventsAsync(userId, today.StartOfDay(), today.EndOfDay());

                break;

            case CalendarTimeLineType.Week:
                var weekStart = today.AddDays(-(today.DayIndex() + expandDayPrecision));
                var weekEnd   = weekStart.AddDays(7 + expandDayPrecision * 2).AddSeconds(-1);
                response = await GetEventsAsync(userId, weekStart, weekEnd);

                break;

            case CalendarTimeLineType.Month:
                var monthStart = today.AddDays(-(today.Day + expandDayPrecision));
                var monthEnd   = monthStart.AddMonths(1).AddDays(expandDayPrecision * 2).AddSeconds(-1);
                response = await GetEventsAsync(userId, monthStart, monthEnd);

                break;

            default:
                response.Errors.Add(new ErrorModel(string.Empty, "No line type indicated"));
                break;
            }

            return(response);
        }