public CalendarWrapper CreateCalendar(string name, string description, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, List <SharingParam> sharingOptions) { var sharingOptionsList = sharingOptions ?? new List <SharingParam>(); var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone); name = (name ?? "").Trim(); if (String.IsNullOrEmpty(name)) { throw new Exception(Resources.CalendarApiResource.ErrorEmptyName); } description = (description ?? "").Trim(); textColor = (textColor ?? "").Trim(); backgroundColor = (backgroundColor ?? "").Trim(); var cal = _dataProvider.CreateCalendar( SecurityContext.CurrentAccount.ID, name, description, textColor, backgroundColor, timeZoneInfo, alertType, null, sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList(), new List <UserViewSettings>()); if (cal != null) { foreach (var opt in sharingOptionsList) { if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase)) { CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, cal)); } } //notify CalendarNotifyClient.NotifyAboutSharingCalendar(cal); return(new CalendarWrapper(cal)); } return(null); }
public CalendarWrapper UpdateCalendar(string calendarId, string name, string description, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, bool hideEvents, List <SharingParam> sharingOptions) { TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone); int calId; if (int.TryParse(calendarId, out calId)) { var oldCal = _dataProvider.GetCalendarById(calId); if (CheckPermissions(oldCal, CalendarAccessRights.FullAccessAction, true)) { //update calendar and share options var sharingOptionsList = sharingOptions ?? new List <SharingParam>(); name = (name ?? "").Trim(); if (String.IsNullOrEmpty(name)) { throw new Exception(Resources.CalendarApiResource.ErrorEmptyName); } description = (description ?? "").Trim(); textColor = (textColor ?? "").Trim(); backgroundColor = (backgroundColor ?? "").Trim(); //view var userOptions = oldCal.ViewSettings; var usrOpt = userOptions.Find(o => o.UserId.Equals(SecurityContext.CurrentAccount.ID)); if (usrOpt == null) { userOptions.Add(new UserViewSettings() { Name = name, TextColor = textColor, BackgroundColor = backgroundColor, EventAlertType = alertType, IsAccepted = true, UserId = SecurityContext.CurrentAccount.ID, TimeZone = timeZoneInfo }); } else { usrOpt.Name = name; usrOpt.TextColor = textColor; usrOpt.BackgroundColor = backgroundColor; usrOpt.EventAlertType = alertType; usrOpt.TimeZone = timeZoneInfo; } userOptions.RemoveAll(o => !o.UserId.Equals(oldCal.OwnerId) & !sharingOptionsList.Exists(opt => (!opt.IsGroup && o.UserId.Equals(opt.Id)) || opt.IsGroup && CoreContext.UserManager.IsUserInGroup(o.UserId, opt.Id))); //check owner if (!oldCal.OwnerId.Equals(SecurityContext.CurrentAccount.ID)) { name = oldCal.Name; description = oldCal.Description; } var cal = _dataProvider.UpdateCalendar(calId, name, description, sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList(), userOptions); if (cal != null) { //clear old rights CoreContext.AuthorizationManager.RemoveAllAces(cal); foreach (var opt in sharingOptionsList) { if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase)) { CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, cal)); } } //notify CalendarNotifyClient.NotifyAboutSharingCalendar(cal, oldCal); return(new CalendarWrapper(cal)); } return(null); } } //update view return(UpdateCalendarView(calendarId, name, textColor, backgroundColor, timeZone, alertType, hideEvents)); }