public ActionResult AddCalendarEvent(string title, string description, string location, string start, string end, string allDay) { int newID; // Convert start and end to DateTime objects DateTime startTime = DateTime.ParseExact(start, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); DateTime endTime = DateTime.ParseExact(end, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Create CalendarEvent to be passed to database CalendarEvent calEvent = new CalendarEvent { FBID = (String)Session["FBID"], Title = title, Description = description, Location = location, StartTime = startTime, EndTime = endTime, Recurring = false, AllDay = Boolean.Parse(allDay) }; using (CalendarContext db = new CalendarContext()) { // Add CalendarEvent to database db.CalendarEvents.Add(calEvent); db.SaveChanges(); newID = calEvent.EventID; } // Return the new ID value so we can set it on the new calendar object return Json(newID, JsonRequestBehavior.AllowGet); }
public ActionResult DeleteCalendarEvent(string id) { int eventID = Convert.ToInt32(id); using (CalendarContext db = new CalendarContext()) { // Delete CalendarEvent from database CalendarEvent calEventToDelete = db.CalendarEvents.Where(ce => ce.EventID == eventID).FirstOrDefault(); db.CalendarEvents.Remove(calEventToDelete); db.SaveChanges(); } return View(); }
public ActionResult UploadCalendarEvent(HttpPostedFileBase uploadFile) { int newID = 0; if (uploadFile == null) { return RedirectToLocal("/Calendar/Index"); } StreamReader csvreader = new StreamReader(uploadFile.InputStream); while (!csvreader.EndOfStream) { var line = csvreader.ReadLine(); var values = line.Split(','); try { // Create new CalendarEvent to pass to database CalendarEvent calEvent = new CalendarEvent { FBID = (String)Session["FBID"], Title = values[0], Description = values[1], Location = values[2], StartTime = Convert.ToDateTime(values[3]), EndTime = Convert.ToDateTime(values[4]), Recurring = Boolean.Parse(values[5]), AllDay = Boolean.Parse(values[6]) }; using (CalendarContext db = new CalendarContext()) { db.CalendarEvents.Add(calEvent); db.SaveChanges(); newID = calEvent.EventID; } } catch (Exception e) // If we can't read the file or it is in the wrong format { return RedirectToLocal("/Calendar/Index"); } } // Return the new ID value so we can set it on the new calendar object //return Json(newID, JsonRequestBehavior.AllowGet); return RedirectToLocal("/Calendar/Index"); }
public ActionResult UpdateCalendarEventOnDrop(string id, string title, string description, string location, string start, string end, string allDay) { // Convert start and end to DateTime objects DateTime startTime = DateTime.ParseExact(start, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); DateTime endTime = DateTime.ParseExact(end, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); int eventID = Convert.ToInt32(id); using (CalendarContext db = new CalendarContext()) { // Update CalendarEvent in database CalendarEvent calEventToUpdate = db.CalendarEvents.Where(ce => ce.EventID == eventID).FirstOrDefault(); // Create CalendarEvent to be passed to database // Only title, description, and location can be updated currently CalendarEvent calEvent = new CalendarEvent { EventID = Convert.ToInt32(id), FBID = (String)Session["FBID"], Title = title, Description = description, Location = location, StartTime = startTime, EndTime = endTime, Recurring = false, AllDay = calEventToUpdate.AllDay }; if (calEventToUpdate != null) { db.Entry(calEventToUpdate).CurrentValues.SetValues(calEvent); } db.SaveChanges(); } return View(); }