Example #1
0
        public ActionResult ManageEvent(string time, string description, int year, int month, int day)
        {
            int hour, minute;

            try {
                hour   = Convert.ToInt32(time.Substring(0, 2));
                minute = Convert.ToInt32(time.Substring(3, 2));
            }
            catch (Exception) {
                return(ShowError(new ArgumentException("Invalid time.")));
            }

            EventViewModel newEvent = new EventViewModel(year, month, day, hour, minute);

            newEvent.Description = description ?? "";

            int newEventId;

            try { newEventId = DataHandler.AddEvent(newEvent); }
            catch (Exception e) { return(ShowError(e)); }

            return(Json(new {
                status = "ok",
                id = newEventId
            }));
        }
Example #2
0
        public IActionResult ApplyChanges(int id, string time, string description, int year = 0, int month = 0, int day = 0)
        {
            int hour, minute;

            try {
                hour   = Convert.ToInt32(time.Substring(0, 2));
                minute = Convert.ToInt32(time.Substring(3, 2));
            }
            catch (Exception) {
                throw new ArgumentException("Invalid time.");
            }

            if (id != -1)
            {
                DateTime eventTime = DataHandler.UpdateEvent(id, hour, minute, description ?? "");
                return(RedirectToAction("DisplayDate", new { year = eventTime.Year, month = Pad(eventTime.Month), day = Pad(eventTime.Day) }));
            }
            else
            {
                EventViewModel newEvent = new EventViewModel(year, month, day, hour, minute);
                newEvent.Description = description ?? "";

                DataHandler.AddEvent(newEvent);
                return(RedirectToAction("DisplayDate", new { year = year, month = Pad(month), day = Pad(day) }));
            }
        }