コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        public ECalendar PostSave(ECalendar calendar)
        {
            if (calendar.Id > 0)
                DatabaseContext.Database.Update(calendar);
            else
                DatabaseContext.Database.Save(calendar);

            return calendar;
        }
コード例 #4
0
 public Umbraco.Core.Attempt <object> ConvertPropertyValue(object sourceValue)
 {
     try
     {
         JavaScriptSerializer lizer = new JavaScriptSerializer();
         ECalendar            cal   = lizer.Deserialize <ECalendar>(sourceValue.ToString());
         return(Attempt <object> .Succeed(cal));  //(true, cal);
     }
     catch { return(Attempt <object> .Fail()); }
 }
コード例 #5
0
        public ActionResult Index(int id = 0)
        {
            ECalendar cal = null;

            if (0 != id && null != this._db)
            {
                cal = this._db.SingleOrDefault <ECalendar>(id);
            }
            ViewData["calendar"] = cal;
            return(View(cal));
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
 public CPGDate( DateTime dt )
 {
     m_etType = EType.Single;
     m_ecCalendar = ECalendar.Gregorian;
     m_year = new CYear( dt.Year );
     m_uMonth = (uint)dt.Month;
     m_uDay = (uint)dt.Day;
     m_yearTo = null;
     m_uMonthTo = 0;
     m_uDayTo = 0;
     m_sPhrase = "";
 }
コード例 #8
0
        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()));
            }
        }
コード例 #9
0
        public bool Delete()
        {
            //Code that will execute when deleting
            ECalendar c      = this._db.SingleOrDefault <ECalendar>(ParentID);
            var       events = this._db.Query <CalendarEntry>("SELECT * FROM ec_events WHERE calendarId = @0", c.Id);

            foreach (CalendarEntry e in events)
            {
                this._db.Delete(e);
            }
            this._db.Delete(c);
            return(true);
        }
コード例 #10
0
        public ActionResult EditCalendar(ECalendar calendar)
        {
            if (!ModelState.IsValid)
            {
                TempData["StatusSettings"] = "Invalid";
                return(RedirectToAction("Index", new { id = calendar.Id }));
                //ViewData["calendar"] = calendar;
                //return PartialView("Index");
            }

            TempData["StatusSettings"] = "Valid";
            this._db.Update(calendar);
            //ViewData["calendar"] = calendar;
            //return PartialView("Index");
            return(RedirectToAction("Index", new { id = calendar.Id }));
        }
コード例 #11
0
        // Copy constructor
        public CPGDate( CPGDate date )
        {
            m_etType = date.m_etType;
            m_ecCalendar = date.m_ecCalendar;
            if( date.m_year != null )
                m_year = new CYear( date.m_year );
            else
                m_year = null;
            m_uMonth = date.m_uMonth;
            m_uDay = date.m_uDay;
            if( date.m_yearTo != null )
                m_yearTo = new CYear( date.m_yearTo );
            else
                m_yearTo = null;

            m_uMonthTo = date.m_uMonthTo;
            m_uDayTo = date.m_uDayTo;
            m_sPhrase = date.m_sPhrase;
        }
コード例 #12
0
        public ActionResult AddEvent(AddEventModel new_event)
        {
            ECalendar cal = null;

            if (0 != new_event.calendarId && null != this._db)
            {
                cal = this._db.SingleOrDefault <ECalendar>(new_event.calendarId);
            }
            if (!ModelState.IsValid)
            {
                TempData["StatusNewEvent"] = "Invalid";
                return(RedirectToAction("Index", new { id = cal.Id }));

                //ViewData["calendar"] = cal;
                //return PartialView("Index");
            }
            TempData["StatusNewEvent"] = "Valid";
            CalendarEntry entry = new CalendarEntry()
            {
                allDay      = new_event.allday,
                calendarId  = new_event.calendarId,
                description = new_event.description,
                title       = new_event.title,
                start       = new_event.start,
                locationId  = new_event.selectedLocation
            };

            if (new_event.start > new_event.end)
            {
                entry.end = null;
            }
            else
            {
                entry.end = new_event.end;
            }

            this._db.Insert(entry);

            return(RedirectToAction("Index", new { id = cal.Id }));
        }
コード例 #13
0
        // Return this date as a displayable string. Used by ToString().
        private string DateString( uint uDay, uint uMonth, CYear year, ECalendar calendar )
        {
            if (year == null)
            {
                return "";
            }

            if (calendar == ECalendar.French)
            {
                return DateStringFren(uDay, uMonth, year);
            }
            if (calendar == ECalendar.Hebrew)
            {
                return DateStringHebr(uDay, uMonth, year);
            }

            string sDate = "";

            string[] aMonths = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

            if( uDay != 0 )
            {
                sDate = uDay.ToString();
                uint ord = uDay % 10;
                uint ord10 = uDay % 100;
                if( ord == 1 && ord10 != 11 )
                    sDate += "st";
                else if( ord == 2 && ord10 != 12 )
                    sDate += "nd";
                else if( ord == 3 && ord10 != 13 )
                    sDate += "rd";
                else
                    sDate += "th";
                sDate += " ";
            }

            if( uMonth > 0 && uMonth <= aMonths.Length )
            {
                sDate += aMonths[uMonth-1];
                sDate += " ";
            }

            sDate += year.ToString();

            return sDate;
        }