Пример #1
0
 //
 // GET: /Calendar/
 public ActionResult Index()
 {
     ViewBag.Message = "Calendar";
     CalendarModel c = new CalendarModel();
     c.populateLists();
     return View(c);
 }
Пример #2
0
        public ActionResult DeleteEvent(CalendarModel c)
        {
            int EventID = Int32.Parse(c.currentEventID);
            string UserID = User.Identity.GetUserId();
            if (UserID != null) {
                MySqlConnection db = new MySqlConnection();
                db.CreateConn();

                SqlCommand cmd = new SqlCommand("DeleteCalendarEvent", db.Connection);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@UserId", UserID));
                cmd.Parameters.Add(new SqlParameter("@EventId", EventID));

                db.Command = cmd;
                db.Command.Prepare();
                db.Command.ExecuteNonQuery();
            }

            return RedirectToAction("Index");
        }
Пример #3
0
        /// <summary>
        /// Translates the various time forms from the view into two DateTime variables, the data then gets passed to the InsertEvent function.
        /// </summary>
        /// <param name="c"></param>
        /// <param name="EventName"></param>
        /// <param name="EventDescription"></param>
        /// <param name="EventStart"></param>
        /// <param name="EventEnd"></param>
        /// <returns></returns>
        public ActionResult TranslateEventTime(CalendarModel c, string EventName, string EventDescription, string EventStart, string EventEnd)
        {
            // Translating user input into event start datetime variable
            int startHour = c.startHourVal;
            string startHourText;
            if (startHour.ToString().Length == 1) {
                startHourText = "0" + startHour.ToString();
            } else {
                startHourText = startHour.ToString();
            }
            if (c.startTimeframeText == null) {
                c.startTimeframeText = "AM";
            }
            if (c.startMinuteText == null) {
                c.startMinuteText = "00";
            }
            if (c.startTimeframeText == "PM" && startHour != 12) {
                startHour += 12;
                startHourText = startHour.ToString();
            }
            if (startHour == 12 && c.startTimeframeText == "AM") {
                startHourText = "00";
            }
            var startTime = startHourText + ":" + c.startMinuteText + ":00";
            startTime = EventStart + " " + startTime;

            // Translating user input into event end datetime variable
            int endHour = c.endHourVal;
            string endHourText;
            if (endHour.ToString().Length == 1) {
                endHourText = "0" + endHour.ToString();
            } else {
                endHourText = endHour.ToString();
            }
            if (c.endTimeframeText == null) {
                c.endTimeframeText = "AM";
            }
            if (c.endMinuteText == null) {
                c.endMinuteText = "00";
            }
            if (c.endTimeframeText == "PM" && endHour != 12) {
                endHour += 12;
                endHourText = endHour.ToString();
            }
            if (endHour == 12 && c.endTimeframeText == "AM") {
                endHourText = "00";
            }
            var endTime = endHourText + ":" + c.endMinuteText + ":00";
            endTime = EventEnd + " " + endTime;

            // Validate the start time and endtime to make sure they are actually dates in a calendar.
            DateTime dtStart;
            DateTime dtEnd;

            if (DateTime.TryParseExact(startTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtStart) == true &&
                DateTime.TryParseExact(endTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtEnd) == true) {
                    if (dtStart != dtEnd) {
                        InsertEvent(EventName, EventDescription, dtStart, dtEnd);
                    }
            }
            return RedirectToAction("Index");
        }