Esempio n. 1
0
        static public void UpdateAssignmentEvent(Assignment assignment, Event aEvent, int ActiveCourseUserId, ContextBase db)
        {
            //Link to assignment details.
            UrlHelper u = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);

            aEvent.Description = "[url:Assignment Page|" + u.Action("Index", "Home", new { assignmentId = assignment.ID, area = "AssignmentDetails" }, System.Web.HttpContext.Current.Request.Url.Scheme) + "]"; //plus.osble.org/AssignmentDetails/" + assignment.ID + "]";
            aEvent.EndDate     = null;
            aEvent.StartDate   = assignment.DueDate;
            aEvent.StartTime   = assignment.DueTime;
            aEvent.PosterID    = ActiveCourseUserId;
            aEvent.Title       = assignment.AssignmentTypeID == (int)AssignmentTypes.DiscussionAssignment? assignment.AssignmentName + " Closes" : assignment.AssignmentName + " Due";
            aEvent.Approved    = true;
            //aEvent.HideTime
            if (aEvent.ID == 0)
            {
                db.Events.Add(aEvent);
                db.SaveChanges();
                assignment.AssociatedEventID = aEvent.ID;
                db.Entry(assignment).State   = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                db.Entry(aEvent).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            if (assignment.CourseID.HasValue)
            {
                //rebuilds course calendar file upon assignment updates/creations
                using (iCalendarController ical = new iCalendarController())
                {
                    ical.CreateCourseCalendar(assignment.CourseID.Value);
                }
            }
        }
Esempio n. 2
0
        public ActionResult Edit(Event e)
        {
            int utcOffset = 0;

            try
            {
                Int32.TryParse(Request.Form["utc-offset"].ToString(), out utcOffset);
            }
            catch (Exception)
            {
            }

            // Validate original event. make sure it exists and is part of the active course.
            Event originalEvent = db.Events.Find(e.ID);

            originalEvent.Title       = e.Title;
            originalEvent.Description = e.Description;


            originalEvent.StartDate = e.StartDate.CourseToUTC(ActiveCourseUser.AbstractCourseID);
            originalEvent.StartTime = e.StartTime.CourseToUTC(ActiveCourseUser.AbstractCourseID);

            if (!Request.Form.AllKeys.Contains("IncludeEndDate"))
            {
                originalEvent.EndDate = null;
            }
            else
            {
                originalEvent.EndDate = ((DateTime)e.EndDate).CourseToUTC(ActiveCourseUser.AbstractCourseID);
                originalEvent.EndTime = ((DateTime)e.EndTime).CourseToUTC(ActiveCourseUser.AbstractCourseID);
                //make sure that the end date happens after the start
                if ((DateTime)originalEvent.EndDate < originalEvent.StartDate)
                {
                    ModelState.AddModelError("badDates", "The starting time must occur before the ending time");
                }
            }
            if ((originalEvent == null) || (originalEvent.Poster.AbstractCourseID != ActiveCourseUser.AbstractCourseID))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                db.Entry(originalEvent).State = EntityState.Modified;
                db.SaveChanges();

                //rebuilds course calendar file upon editing an event
                using (iCalendarController ical = new iCalendarController())
                {
                    ical.CreateCourseCalendar(ActiveCourseUser.AbstractCourseID);
                }

                return(RedirectToAction("Index"));
            }
            return(View(e));
        }
Esempio n. 3
0
        private bool CreateEvents(List <OSBLE.Models.HomePage.Event> events)
        {
            List <OSBLE.Models.HomePage.Event> uniqueEvents = DBHelper.RemoveDuplicateEvents(events);

            if (uniqueEvents.Count() > 0)
            {
                foreach (var item in uniqueEvents)
                {
                    db.Events.Add(item);
                }

                db.SaveChanges();

                using (iCalendarController ical = new iCalendarController())
                {
                    ical.CreateCourseCalendar(ActiveCourseUser.AbstractCourseID);
                }
            }
            return(true);
        }
Esempio n. 4
0
        public ActionResult Approve(int id)
        {
            Event e = db.Events.Find(id);

            if (e.Poster.AbstractCourseID != ActiveCourseUser.AbstractCourseID)
            {
                return(RedirectToAction("Index", "Home"));
            }

            e.Approved        = true;
            db.Entry(e).State = EntityState.Modified;
            db.SaveChanges();

            //rebuilds course calendar file upon event approval
            using (iCalendarController ical = new iCalendarController())
            {
                ical.CreateCourseCalendar(ActiveCourseUser.AbstractCourseID);
            }

            return(RedirectToAction("Index", "Event"));
        }
Esempio n. 5
0
        public ActionResult Create(Event e)
        {
            // Set to current user and poster
            e.Poster = ActiveCourseUser;

            // Default to not Approved.
            e.Approved = false;

            if (!Request.Form.AllKeys.Contains("IncludeEndDate"))
            {
                e.EndDate = null;
            }
            else
            {
                //make sure that the end date happens after the start
                if ((DateTime)e.EndDate < e.StartDate)
                {
                    ModelState.AddModelError("badDates", "The starting time must occur before the ending time");
                }
            }

            // Approve if instructor/leader, course is community, or approval is not required.
            if (ActiveCourseUser.AbstractRole.CanModify ||
                ((ActiveCourseUser.AbstractCourse is Course) &&
                 !(ActiveCourseUser.AbstractCourse as Course).RequireInstructorApprovalForEventPosting) ||
                (ActiveCourseUser.AbstractCourse is Community)
                )
            {
                e.Approved = true;
            }

            if (ModelState.IsValid)
            {
                //locate timezone offset
                //int courseOffset = (ActiveCourseUser.AbstractCourse).GetType() != typeof(Community) ? ((Course)ActiveCourseUser.AbstractCourse).TimeZoneOffset : 0;
                //CourseController cc = new CourseController();
                //TimeZoneInfo tz = cc.getTimeZone(courseOffset);

                //now convert the time to utc
                //if (e.EndDate != null)
                //    e.EndDate = TimeZoneInfo.ConvertTimeToUtc((DateTime)e.EndDate, tz);

                //e.StartDate = TimeZoneInfo.ConvertTimeToUtc(e.StartDate, tz);

                if (e.EndDate != null)
                {
                    e.EndDate = ((DateTime)e.EndDate).CourseToUTC(ActiveCourseUser.AbstractCourseID);
                }

                e.StartDate = e.StartDate.CourseToUTC(ActiveCourseUser.AbstractCourseID);

                db.Events.Add(e);
                db.SaveChanges();

                if (!e.Approved)
                {
                    using (NotificationController nc = new NotificationController())
                    {
                        nc.SendEventApprovalNotification(e);
                    }

                    return(RedirectToAction("NeedsApproval"));
                }
                //rebuilds course calendar file upon creating of a new event ICAL
                using (iCalendarController ical = new iCalendarController())
                {
                    ical.CreateCourseCalendar(ActiveCourseUser.AbstractCourseID);
                }

                return(RedirectToAction("Index"));
            }

            return(View(e));
        }