Пример #1
0
        public static BaseCalendar GetUserCalendar(this BaseCalendar calendar, UserViewSettings userViewSettings)
        {
            var cal = (BaseCalendar)calendar.Clone();

            if (userViewSettings == null)
                return cal;
            
            //name             
            if (!String.IsNullOrEmpty(userViewSettings.Name))
                cal.Name = userViewSettings.Name;

            //backgroundColor
            if (!String.IsNullOrEmpty(userViewSettings.BackgroundColor))
                cal.Context.HtmlBackgroundColor = userViewSettings.BackgroundColor;

            //textColor
            if (!String.IsNullOrEmpty(userViewSettings.TextColor))
                cal.Context.HtmlTextColor = userViewSettings.TextColor;

            //TimeZoneInfo      
            if (userViewSettings.TimeZone!= null)
                cal.TimeZone = userViewSettings.TimeZone;

            //alert type            
            cal.EventAlertType = userViewSettings.EventAlertType;

            return cal;
        }
Пример #2
0
        public CalendarWrapper(BaseCalendar calendar, UserViewSettings userViewSettings)
        {
            _userViewSettings = userViewSettings;
            if (_userViewSettings == null && calendar is ASC.Api.Calendar.BusinessObjects.Calendar)
            { 
                _userViewSettings = (calendar as ASC.Api.Calendar.BusinessObjects.Calendar)
                                    .ViewSettings.Find(s=> s.UserId == SecurityContext.CurrentAccount.ID);
            }

            if (_userViewSettings == null)
            {
                UserCalendar = calendar;
                _userId = SecurityContext.CurrentAccount.ID;
            }
            else
            {
                UserCalendar = calendar.GetUserCalendar(_userViewSettings);
                _userId = _userViewSettings.UserId;
            }
        }
 public SubscriptionWrapper(BaseCalendar calendar, UserViewSettings userViewSettings)
     : base(calendar, userViewSettings) { }
Пример #4
0
        public void UpdateCalendarUserView(UserViewSettings viewSettings)
        {
            int calendarId;
            var cc = new ColumnCollection();
            var eId = cc.RegistryColumn("e.id");
            var eStartDate = cc.RegistryColumn("e.start_date");
            var eAlertType = cc.RegistryColumn("e.alert_type");
            var eRRule = cc.RegistryColumn("e.rrule");
            var eCalId = cc.RegistryColumn("e.calendar_id");

            if (int.TryParse(viewSettings.CalendarId, out calendarId))
            {
                DbManager.ExecuteNonQuery(new SqlInsert("calendar_calendar_user", true)
                                                        .InColumnValue("calendar_id", calendarId)
                                                        .InColumnValue("user_id", viewSettings.UserId)
                                                        .InColumnValue("hide_events", viewSettings.IsHideEvents)
                                                        .InColumnValue("text_color", viewSettings.TextColor)
                                                        .InColumnValue("background_color", viewSettings.BackgroundColor)
                                                        .InColumnValue("is_accepted", viewSettings.IsAccepted)
                                                        .InColumnValue("alert_type", (int)viewSettings.EventAlertType)
                                                        .InColumnValue("name", viewSettings.Name ?? "")
                                                        .InColumnValue("time_zone", viewSettings.TimeZone != null ? viewSettings.TimeZone.Id : null)
                                                        );



                //update notifications
                var eventsData = DbManager.ExecuteList(
                    new SqlQuery("calendar_events e")
                    .Select(cc.SelectQuery)
                    .Where("e.calendar_id", calendarId)
                    .Where("e.tenant", CoreContext.TenantManager.GetCurrentTenant().TenantId));

                foreach (var r in eventsData)
                {
                    UpdateEventNotifications(eId.Parse<int>(r), calendarId,
                                            eStartDate.Parse<DateTime>(r),
                                           (EventAlertType)eAlertType.Parse<int>(r),
                                           eRRule.Parse<RecurrenceRule>(r), null, null);
                }

            }
            else
            {
                DbManager.ExecuteNonQuery(new SqlInsert("calendar_calendar_user", true)
                                                        .InColumnValue("ext_calendar_id", viewSettings.CalendarId)
                                                        .InColumnValue("user_id", viewSettings.UserId)
                                                        .InColumnValue("hide_events", viewSettings.IsHideEvents)
                                                        .InColumnValue("text_color", viewSettings.TextColor)
                                                        .InColumnValue("background_color", viewSettings.BackgroundColor)
                                                        .InColumnValue("alert_type", (int)viewSettings.EventAlertType)
                                                        .InColumnValue("is_accepted", viewSettings.IsAccepted)
                                                        .InColumnValue("name", viewSettings.Name ?? "")
                                                        .InColumnValue("time_zone", viewSettings.TimeZone != null ? viewSettings.TimeZone.Id : null)
                                                        );

                if (String.Equals(viewSettings.CalendarId, SharedEventsCalendar.CalendarId, StringComparison.InvariantCultureIgnoreCase))
                {
                    //update notifications
                    var groups = CoreContext.UserManager.GetUserGroups(viewSettings.UserId).Select(g => g.ID).ToList();
                    groups.AddRange(CoreContext.UserManager.GetUserGroups(viewSettings.UserId, ASC.Core.Users.Constants.SysGroupCategoryId).Select(g => g.ID));

                    var q = new SqlQuery("calendar_events e")
                        .Select(cc.SelectQuery)
                        .InnerJoin("calendar_event_item ei", Exp.EqColumns("ei.event_id", eId.Name))
                        .Where("e.tenant", CoreContext.TenantManager.GetCurrentTenant().TenantId)
                        .Where((Exp.Eq("ei.is_group", false) & Exp.Eq("ei.item_id", viewSettings.UserId)) | (Exp.Eq("ei.is_group", true) & Exp.In("ei.item_id", groups.ToArray())));
                    var eventsData = DbManager.ExecuteList(q);

                    foreach (var r in eventsData)
                    {
                        UpdateEventNotifications(eId.Parse<int>(r), eCalId.Parse<int>(r),
                                                 eStartDate.Parse<DateTime>(r),
                                                 (EventAlertType)eAlertType.Parse<int>(r),
                                                 eRRule.Parse<RecurrenceRule>(r), null, null);
                    }
                }
            }
        }
Пример #5
0
        public List<Calendar> GetCalendarsByIds(object[] calIds)
        {
            var cc = new ColumnCollection();

            var calId = cc.RegistryColumn("cal.id");
            var calName = cc.RegistryColumn("cal.name");
            var calDescription = cc.RegistryColumn("cal.description");
            var calTenant = cc.RegistryColumn("cal.tenant");
            var calTextColor = cc.RegistryColumn("cal.text_color");
            var calBackground = cc.RegistryColumn("cal.background_color");
            var calOwner = cc.RegistryColumn("cal.owner_id");
            var calAlertType = cc.RegistryColumn("cal.alert_type");
            var calTimeZone = cc.RegistryColumn("cal.time_zone");
            var iCalUrl = cc.RegistryColumn("cal.ical_url");

            var usrId = cc.RegistryColumn("cal_usr.user_id");
            var usrHideEvents = cc.RegistryColumn("cal_usr.hide_events");
            var usrIsAccepted = cc.RegistryColumn("cal_usr.is_accepted");
            var usrTextColor = cc.RegistryColumn("cal_usr.text_color");
            var usrBackground = cc.RegistryColumn("cal_usr.background_color");
            var usrAlertType = cc.RegistryColumn("cal_usr.alert_type");
            var usrCalName = cc.RegistryColumn("cal_usr.name");
            var usrTimeZone = cc.RegistryColumn("cal_usr.time_zone");

            var data = DbManager.ExecuteList(new SqlQuery(_calendarTable).Select(cc.SelectQuery)
                                            .LeftOuterJoin(_calendarUserTable, Exp.EqColumns(calId.Name, "cal_usr.calendar_id"))
                                            .Where(Exp.In(calId.Name, calIds)));

            var cc1 = new ColumnCollection();

            var itemCalId = cc1.RegistryColumn("cal_itm.calendar_id");
            var itemId = cc1.RegistryColumn("cal_itm.item_id");
            var itemIsGroup = cc1.RegistryColumn("cal_itm.is_group");

            var sharingData = DbManager.ExecuteList(new SqlQuery(_calendarItemTable).Select(cc1.SelectQuery)
                                                    .Where(Exp.In(itemCalId.Name, calIds)));


            //parsing
            var calendars = new List<Calendar>();
            foreach (var r in data)
            {
                var calendar = calendars.Find(c => string.Equals(c.Id, calId.Parse<int>(r).ToString(), StringComparison.InvariantCultureIgnoreCase));
                if (calendar == null)
                {
                    calendar = new Calendar()
                    {
                        Id = calId.Parse<int>(r).ToString(),
                        Name = calName.Parse<string>(r),
                        Description = calDescription.Parse<string>(r),
                        TenantId = calTenant.Parse<int>(r),
                        OwnerId = calOwner.Parse<Guid>(r),
                        EventAlertType = (EventAlertType)calAlertType.Parse<int>(r),
                        TimeZone = calTimeZone.Parse<TimeZoneInfo>(r),
                        iCalUrl = iCalUrl.Parse<string>(r),
                    };
                    calendar.Context.HtmlTextColor = calTextColor.Parse<string>(r);
                    calendar.Context.HtmlBackgroundColor = calBackground.Parse<string>(r);
                    if (!String.IsNullOrEmpty(calendar.iCalUrl))
                    {
                        calendar.Context.CanChangeTimeZone = false;
                        calendar.Context.CanChangeAlertType = false;
                    }

                    calendars.Add(calendar);

                    foreach (var row in sharingData)
                    {
                        var _calId = itemCalId.Parse<int>(row).ToString();
                        if (String.Equals(_calId, calendar.Id, StringComparison.InvariantCultureIgnoreCase))
                        {
                            calendar.SharingOptions.PublicItems.Add(new ASC.Web.Core.Calendars.SharingOptions.PublicItem()
                            {
                                Id = itemId.Parse<Guid>(row),
                                IsGroup = itemIsGroup.Parse<bool>(row)
                            });
                        }
                    }
                }

                if (!usrId.IsNull(r))
                {
                    var uvs = new UserViewSettings()
                    {
                        CalendarId = calendar.Id.ToString(),
                        UserId = usrId.Parse<Guid>(r),
                        IsHideEvents = usrHideEvents.Parse<bool>(r),
                        IsAccepted = usrIsAccepted.Parse<bool>(r),
                        TextColor = usrTextColor.Parse<string>(r),
                        BackgroundColor = usrBackground.Parse<string>(r),
                        EventAlertType = (EventAlertType)usrAlertType.Parse<int>(r),
                        Name = usrCalName.Parse<string>(r),
                        TimeZone = usrTimeZone.Parse<TimeZoneInfo>(r)
                    };

                    calendar.ViewSettings.Add(uvs);
                }
            }

            return calendars;
        }
Пример #6
0
        public CalendarWrapper UpdateCalendarView(string calendarId, string name, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, bool hideEvents)
        {
            TimeZoneInfo timeZoneInfo = TimeZoneConverter.GetTimeZone(timeZone);
            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);

            var settings = new UserViewSettings()
            {
                BackgroundColor = backgroundColor,
                CalendarId = calendarId,
                IsHideEvents = hideEvents,
                TextColor = textColor,
                EventAlertType = alertType,
                IsAccepted = true,
                UserId = SecurityContext.CurrentAccount.ID,
                Name = name,
                TimeZone = timeZoneInfo
            };

            _dataProvider.UpdateCalendarUserView(settings);
            return GetCalendarById(calendarId);
        }
Пример #7
0
        public void ManageSubscriptions(IEnumerable<SubscriptionState> states)
        {
            var viewSettings = _dataProvider.GetUserViewSettings(SecurityContext.CurrentAccount.ID, states.Select(s => s.id).ToList());

            var settingsCollection = new List<UserViewSettings>();
            foreach (var s in states)
            {
                var settings = viewSettings.Find(vs => vs.CalendarId.Equals(s.id, StringComparison.InvariantCultureIgnoreCase));
                if (settings == null)
                {
                    settings = new UserViewSettings()
                    {
                        CalendarId = s.id,
                        UserId = SecurityContext.CurrentAccount.ID
                    };
                }
                settings.IsAccepted = s.isAccepted;
                settingsCollection.Add(settings);

            }
            _dataProvider.UpdateCalendarUserView(settingsCollection);
        }