Esempio n. 1
0
        public IEnumerable <Calendar> GetCalendars(string loginedUserId)
        {
            var dataUser = serviceHelper.GetUserByIdentityId(loginedUserId);

            if (dataUser != null)
            {
                var userCalendars = serviceHelper.WrapMethodWithReturn(() => calendarRepos.GetUserCalendars(dataUser.IdUser),
                                                                       new List <Data.Models.Calendar>());
                var calendars = userCalendars
                                .Select(c => Mapper.Map <Data.Models.Calendar, Calendar>(c))
                                .OrderBy(c => c.Id)
                                .ToList();

                for (var i = 0; i < calendars.Count(); ++i)
                {
                    var calendar = calendars[i];
                    var(isOwner, isDefault) = serviceHelper.GetCalendarData(calendar, dataUser);
                    calendar.IsOwner        = isOwner;
                    calendar.IsDefault      = isDefault;
                }

                return(calendars);
            }
            return(new List <Calendar>());
        }
Esempio n. 2
0
        public (Data.Models.User dataUser, Data.Models.Calendar dataCalendar) IsUserHasAccessToCalendar(string loginedUserId, int calendarId)
        {
            var dataUser = GetUserByIdentityId(loginedUserId);

            if (dataUser != null)
            {
                var dataCalendars = WrapMethodWithReturn(() => calendarRepos.GetUserCalendars(dataUser.IdUser), null);
                if (dataCalendars != null)
                {
                    return(dataUser, dataCalendars.SingleOrDefault(c => c.Id == calendarId));
                }
            }
            return(null, null);
        }
Esempio n. 3
0
        public IEnumerable <BaseEvent> GetEvents(string loginedUserId, DateTime beginning, DateUnit dateUnit, int[] calendarIds, int timeOffset)
        {
            var dataUser = serviceHelper.GetUserByIdentityId(loginedUserId);

            if (dataUser != null)
            {
                var utcTime       = beginning;
                var userTime      = utcTime.AddMinutes(-timeOffset);
                var userCalendars = serviceHelper.WrapMethodWithReturn(() => calendarRepos.GetUserCalendars(dataUser.IdUser), new List <Data.Models.Calendar>())
                                    .Where(uc => calendarIds.Any(ci => ci.Equals(uc.Id)));

                if (userCalendars.Any())
                {
                    var(start, finish) = GetDateRange(utcTime, dateUnit);
                    var events = serviceHelper.WrapMethodWithReturn(() => bigEventRepos.GetDataEvents(dataUser.IdUser, userCalendars, start, finish),
                                                                    new List <Data.Models.AllData>());
                    events = events.Concat(GetInfinityEvents(dataUser.IdUser, userCalendars, userTime, dateUnit, finish));
                    foreach (var _event in events)
                    {
                        AddTimeOffset(_event, timeOffset);
                    }
                    return(events.Select(e => Mapper.Map <Data.Models.AllData, BaseEvent>(e)));
                }
            }
            return(new List <BaseEvent>());
        }