public ECalendar PostSave(ECalendar calendar)
 {
     var db = UmbracoContext.Application.DatabaseContext.Database;
     if (calendar.Id > 0)
     {
         return CalendarService.UpdateCalendar(calendar);
     }
     else
     {
         return CalendarService.CreateCalendar(calendar, Security.GetUserId());
     }
 }
        /// <summary>
        /// Creates a new calendar
        /// </summary>
        /// <param name="calendar">The calendar which should be created in the database</param>
        /// <param name="creatorId">The id of the user who created the calendar</param>
        /// <returns>The newly created calendar</returns>
        public static ECalendar CreateCalendar(ECalendar calendar, int creatorId)
        {
            var db = ApplicationContext.Current.DatabaseContext.Database;

            var args = new CalendarCreationEventArgs { Calendar = calendar };
            OnCreating(args);

            if (args.Cancel)
            {
                return calendar;
            }

            db.Save(calendar);

            //Update usersettings and add the newly created calendar to the allowed calendar
            SecurityService.AddCalendarToUser(creatorId, calendar.Id);

            var args2 = new CalendarCreatedEventArgs { Calendar = calendar };
            OnCreated(args2);

            return calendar;
        }
 /// <summary>
 /// Updates a calendar with now values in database
 /// </summary>
 /// <param name="calendar">The calendar to update</param>
 /// <returns>The updated calendar</returns>
 public static ECalendar UpdateCalendar(ECalendar calendar)
 {
     var db = ApplicationContext.Current.DatabaseContext.Database;
     db.Update(calendar);
     return calendar;
 }
        /// <summary>
        /// Updates a calendar with now values in database
        /// </summary>
        /// <param name="calendar">The calendar to update</param>
        /// <param name="creatorId">The creator id of the calendar</param>
        /// <returns>The updated calendar</returns>
        public static ECalendar UpdateCalendar(ECalendar calendar, int creatorId)
        {
            var db = ApplicationContext.Current.DatabaseContext.Database;

            db.Update(calendar);

            //Update usersettings and add the newly created calendar to the allowed calendar
            SecurityService.AddCalendarToUser(creatorId, calendar.Id);

            return calendar;
        }