Esempio n. 1
0
 public static CalendarWrapper GetSample()
 {
     return(new CalendarWrapper
     {
         CanEditTimeZone = false,
         TimeZoneInfo = TimeZoneWrapper.GetSample(),
         DefaultAlertType = EventAlertWrapper.GetSample(),
         Events = new List <EventWrapper>()
         {
             EventWrapper.GetSample()
         },
         Owner = UserParams.GetSample(),
         Id = "1",
         Title = "Calendar Name",
         Description = "Calendar Description",
         BackgroundColor = "#000000",
         TextColor = "#ffffff",
         IsEditable = true,
         Permissions = CalendarPermissions.GetSample(),
         IsShared = true,
         CanAlertModify = true,
         IsHidden = false,
         IsiCalStream = false,
         IsSubscription = false
     });
 }
Esempio n. 2
0
 public static object GetSample()
 {
     return(new
     {
         canEditTimeZone = false,
         timeZone = TimeZoneWrapper.GetSample(),
         defaultAlert = EventAlertWrapper.GetSample(),
         events = new List <object>()
         {
             EventWrapper.GetSample()
         },
         owner = UserParams.GetSample(),
         objectId = "1",
         title = "Calendar Name",
         description = "Calendar Description",
         backgroundColor = "#000000",
         textColor = "#ffffff",
         isEditable = true,
         permissions = CalendarPermissions.GetSample(),
         isShared = true,
         canAlertModify = true,
         isHidden = false,
         isiCalStream = false,
         isSubscription = false
     });
 }
Esempio n. 3
0
 public static EventWrapper GetSample()
 {
     return(new EventWrapper
     {
         Owner = UserParams.GetSample(),
         Permissions = Permissions.GetSample(),
         IsEditable = false,
         CanUnsubscribe = true,
         IsShared = true,
         Alert = EventAlertWrapper.GetSample(),
         RepeatRule = "",
         Start = new ApiDateTime(DateTime.Now.AddDays(1), TimeZoneInfo.Utc.GetOffset()),
         End = new ApiDateTime(DateTime.Now.AddDays(1), TimeZoneInfo.Utc.GetOffset()),
         AllDayLong = false,
         Description = "Event Description",
         Name = "Event Name",
         Id = "1",
         CalendarId = "calendarID",
         Status = (int)EventStatus.Tentative
     });
 }
Esempio n. 4
0
        public CalendarWrapper Get(BaseCalendar calendar, UserViewSettings userViewSettings)
        {
            var calendarWraper = new CalendarWrapper();

            calendarWraper._userViewSettings = userViewSettings;
            if (calendarWraper._userViewSettings == null && calendar is BusinessObjects.Calendar)
            {
                calendarWraper._userViewSettings = (calendar as BusinessObjects.Calendar)
                                                   .ViewSettings.Find(s => s.UserId == AuthContext.CurrentAccount.ID);
            }

            if (calendarWraper._userViewSettings == null)
            {
                calendarWraper.UserCalendar = calendar;
                calendarWraper._userId      = AuthContext.CurrentAccount.ID;
            }
            else
            {
                calendarWraper.UserCalendar = calendar.GetUserCalendar(calendarWraper._userViewSettings);
                calendarWraper._userId      = calendarWraper._userViewSettings.UserId;
            }

            //---IsSubscription
            if (calendarWraper.UserCalendar.Id != null)
            {
                if (calendarWraper.UserCalendar.IsiCalStream())
                {
                    calendarWraper.IsSubscription = true;
                }
                else if (calendarWraper.UserCalendar.Id.Equals(SharedEventsCalendar.CalendarId, StringComparison.InvariantCultureIgnoreCase))
                {
                    calendarWraper.IsSubscription = true;
                }
                else if (calendarWraper.UserCalendar.OwnerId.Equals(calendarWraper._userId))
                {
                    calendarWraper.IsSubscription = false;
                }
                else
                {
                    calendarWraper.IsSubscription = true;
                }

                //---iCalUrl
                if (calendarWraper.UserCalendar.IsiCalStream())
                {
                    calendarWraper.iCalUrl = (calendarWraper.UserCalendar as BusinessObjects.Calendar).iCalUrl;
                }
                else
                {
                    calendarWraper.iCalUrl = "";
                }

                //---isiCalStream
                if (calendarWraper.UserCalendar.IsiCalStream())
                {
                    calendarWraper.IsiCalStream = true;
                }
                else
                {
                    calendarWraper.IsiCalStream = false;
                }

                //---IsHidden
                calendarWraper.IsHidden = calendarWraper._userViewSettings != null ? calendarWraper._userViewSettings.IsHideEvents : false;

                //---CanAlertModify
                calendarWraper.CanAlertModify = calendarWraper.UserCalendar.Context.CanChangeAlertType;

                //---IsShared
                calendarWraper.IsShared = calendarWraper.UserCalendar.SharingOptions.SharedForAll || calendarWraper.UserCalendar.SharingOptions.PublicItems.Count > 0;

                //---Permissions
                var p = new CalendarPermissions()
                {
                    Data = PublicItemCollectionHelper.GetForCalendar(calendarWraper.UserCalendar)
                };
                foreach (var item in calendarWraper.UserCalendar.SharingOptions.PublicItems)
                {
                    if (item.IsGroup)
                    {
                        p.UserParams.Add(new UserParams()
                        {
                            Id = item.Id, Name = UserManager.GetGroupInfo(item.Id).Name
                        });
                    }
                    else
                    {
                        p.UserParams.Add(new UserParams()
                        {
                            Id = item.Id, Name = UserManager.GetUsers(item.Id).DisplayUserName(DisplayUserSettingsHelper)
                        });
                    }
                }
                calendarWraper.Permissions = p;

                //---IsEditable
                if (calendarWraper.UserCalendar.IsiCalStream())
                {
                    calendarWraper.IsEditable = false;
                }
                else if (calendarWraper.UserCalendar is ISecurityObject)
                {
                    calendarWraper.IsEditable = PermissionContext.PermissionResolver.Check(Authentication.GetAccountByID(TenantManager.GetCurrentTenant().TenantId, calendarWraper._userId), (ISecurityObject)calendarWraper.UserCalendar as ISecurityObject, null, CalendarAccessRights.FullAccessAction);
                }
                else
                {
                    calendarWraper.IsEditable = false;
                }

                //---TextColor
                calendarWraper.TextColor = String.IsNullOrEmpty(calendarWraper.UserCalendar.Context.HtmlTextColor) ? BusinessObjects.Calendar.DefaultTextColor :
                                           calendarWraper.UserCalendar.Context.HtmlTextColor;

                //---BackgroundColor
                calendarWraper.BackgroundColor = String.IsNullOrEmpty(calendarWraper.UserCalendar.Context.HtmlBackgroundColor) ? BusinessObjects.Calendar.DefaultBackgroundColor :
                                                 calendarWraper.UserCalendar.Context.HtmlBackgroundColor;

                //---Description
                calendarWraper.Description = calendarWraper.UserCalendar.Description;

                //---Title
                calendarWraper.Title = calendarWraper.UserCalendar.Name;

                //---Id
                calendarWraper.Id = calendarWraper.UserCalendar.Id;

                //---IsTodo
                if (calendarWraper.UserCalendar.IsExistTodo())
                {
                    calendarWraper.IsTodo = (calendarWraper.UserCalendar as BusinessObjects.Calendar).IsTodo;
                }
                else
                {
                    calendarWraper.IsTodo = 0;
                }

                //---Owner
                var owner = new UserParams()
                {
                    Id = calendarWraper.UserCalendar.OwnerId, Name = ""
                };
                if (calendarWraper.UserCalendar.OwnerId != Guid.Empty)
                {
                    owner.Name = UserManager.GetUsers(calendarWraper.UserCalendar.OwnerId).DisplayUserName(DisplayUserSettingsHelper);
                }

                calendarWraper.Owner = owner;

                //---IsAcceptedSubscription
                calendarWraper.IsAcceptedSubscription = calendarWraper._userViewSettings == null || calendarWraper._userViewSettings.IsAccepted;

                //---DefaultAlertType
                calendarWraper.DefaultAlertType = EventAlertWrapper.ConvertToTypeSurrogated(calendarWraper.UserCalendar.EventAlertType);

                //---TimeZoneInfo
                calendarWraper.TimeZoneInfo = TimeZoneWrapperHelper.Get(calendarWraper.UserCalendar.TimeZone);

                //---CanEditTimeZone
                calendarWraper.CanEditTimeZone = calendarWraper.UserCalendar.Context.CanChangeTimeZone;
            }

            return(calendarWraper);
        }
Esempio n. 5
0
        public EventWrapper Get(IEvent baseEvent, Guid userId, TimeZoneInfo timeZone)
        {
            var eventWraper = new EventWrapper();

            _timeZone = timeZone;
            var _baseEvent = baseEvent;

            eventWraper.UserId      = userId;
            eventWraper.Id          = _baseEvent.Id;
            eventWraper.Uid         = _baseEvent.Uid;
            eventWraper.CalendarId  = _baseEvent.CalendarId;
            eventWraper.Name        = _baseEvent.Name;
            eventWraper.Description = _baseEvent.Description;
            eventWraper.AllDayLong  = _baseEvent.AllDayLong;;

            var icalendar = new iCalendar(AuthContext, TimeZoneConverter, TenantManager);
            //---
            var startD = _utcStartDate != DateTime.MinValue ? _utcStartDate : _baseEvent.UtcStartDate;

            startD = new DateTime(startD.Ticks, DateTimeKind.Utc);

            var updateD = _utcUpdateDate != DateTime.MinValue ? _utcUpdateDate : _baseEvent.UtcStartDate;

            if (_baseEvent.AllDayLong && _baseEvent.GetType().GetCustomAttributes(typeof(AllDayLongUTCAttribute), true).Length > 0)
            {
                eventWraper.Start = new ApiDateTime(startD, TimeZoneInfo.Utc.GetOffset());
            }
            else if (_baseEvent.GetType().Namespace == new BusinessObjects.Event(AuthContext, TimeZoneConverter, icalendar, DataProvider).GetType().Namespace)
            {
                eventWraper.Start = new ApiDateTime(startD, _timeZone.GetOffset(false, updateD));
            }
            else
            {
                eventWraper.Start = new ApiDateTime(startD, _timeZone.GetOffset());
            }

            //---
            var endD = _utcEndDate != DateTime.MinValue ? _utcEndDate : _baseEvent.UtcEndDate;

            endD = new DateTime(endD.Ticks, DateTimeKind.Utc);

            updateD = _utcUpdateDate != DateTime.MinValue ? _utcUpdateDate : _baseEvent.UtcStartDate;


            if (_baseEvent.AllDayLong && _baseEvent.GetType().GetCustomAttributes(typeof(AllDayLongUTCAttribute), true).Length > 0)
            {
                eventWraper.End = new ApiDateTime(endD, TimeZoneInfo.Utc.GetOffset());
            }
            else if (_baseEvent.GetType().Namespace == new BusinessObjects.Event(AuthContext, TimeZoneConverter, icalendar, DataProvider).GetType().Namespace)
            {
                eventWraper.End = new ApiDateTime(endD, _timeZone.GetOffset(false, updateD));
            }
            else
            {
                eventWraper.End = new ApiDateTime(endD, _timeZone.GetOffset());
            }

            eventWraper.RepeatRule = _baseEvent.RecurrenceRule.ToString();

            eventWraper.Alert          = EventAlertWrapper.ConvertToTypeSurrogated(_baseEvent.AlertType);
            eventWraper.IsShared       = _baseEvent.SharingOptions.SharedForAll || _baseEvent.SharingOptions.PublicItems.Count > 0;
            eventWraper.CanUnsubscribe = String.Equals(_baseEvent.CalendarId, SharedEventsCalendar.CalendarId, StringComparison.InvariantCultureIgnoreCase);

            if (_baseEvent is ISecurityObject)
            {
                eventWraper.IsEditable = PermissionContext.PermissionResolver.Check(Authentication.GetAccountByID(TenantManager.GetCurrentTenant().TenantId, userId), (ISecurityObject)_baseEvent, null, CalendarAccessRights.FullAccessAction);
            }
            else
            {
                eventWraper.IsEditable = false;
            }

            var p = new CalendarPermissions()
            {
                Data = PublicItemCollectionHelper.GetForEvent(_baseEvent)
            };

            foreach (var item in _baseEvent.SharingOptions.PublicItems)
            {
                if (item.IsGroup)
                {
                    p.UserParams.Add(new UserParams()
                    {
                        Id = item.Id, Name = UserManager.GetGroupInfo(item.Id).Name
                    });
                }
                else
                {
                    p.UserParams.Add(new UserParams()
                    {
                        Id = item.Id, Name = UserManager.GetUsers(item.Id).DisplayUserName(DisplayUserSettingsHelper)
                    });
                }
            }
            eventWraper.Permissions = p;

            var owner = new UserParams()
            {
                Id = _baseEvent.OwnerId, Name = ""
            };

            if (_baseEvent.OwnerId != Guid.Empty)
            {
                owner.Name = UserManager.GetUsers(_baseEvent.OwnerId).DisplayUserName(DisplayUserSettingsHelper);
            }

            eventWraper.Owner  = owner;
            eventWraper.Status = _baseEvent.Status;
            eventWraper.UserId = userId;


            return(eventWraper);
        }