public static void Initialize(ScheduleDataContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.ScheduleEvents.Any()) { return; // DB has been seeded } var appointments = new ScheduleEvent[] { new ScheduleEvent { Id = 1, Subject = "Meeting", StartTime = new DateTime(2018, 3, 27, 10, 00, 00), EndTime = new DateTime(2018, 3, 27, 11, 00, 00), StartTimezone = "", EndTimezone = "", IsAllDay = false, Description = "", Location = "", RecurrenceID = "10", RecurrenceRule = "FREQ=DAILY;INTERVAL=1;COUNT=5" }, new ScheduleEvent { Id = 2, Subject = "Client Demo", StartTime = new DateTime(2018, 3, 28, 10, 00, 00), EndTime = new DateTime(2018, 3, 28, 11, 00, 00), StartTimezone = "", EndTimezone = "", IsAllDay = false, Description = "", Location = "" }, }; foreach (ScheduleEvent app in appointments) { context.ScheduleEvents.Add(app); } context.SaveChanges(); }
public JsonResult UpdateSchedule(string mon, string tue, string wed, string thu, string fri, string sat, string sun) { using (ScheduleDataContext db = new ScheduleDataContext()) { string user = User.Identity.Name; bool exists = db.Schedules.Any(m => m.UserName == user); // If user has a schedule, update it if (exists) { Schedule schedule = db.Schedules.First(m => m.UserName == user); if (schedule != null) { db.Schedules.Remove(schedule); Schedule updatedSchedule = new Schedule(); updatedSchedule.UserName = User.Identity.Name; updatedSchedule.Monday = bool.Parse(mon); updatedSchedule.Tuesday = bool.Parse(tue); updatedSchedule.Wednesday = bool.Parse(wed); updatedSchedule.Thursday = bool.Parse(thu); updatedSchedule.Friday = bool.Parse(fri); updatedSchedule.Saturday = bool.Parse(sat); updatedSchedule.Sunday = bool.Parse(sun); db.Schedules.Add(updatedSchedule); db.SaveChanges(); return(Json("Finished updating schedule.", JsonRequestBehavior.AllowGet)); } } else // If no schedule is found, create a new one { Schedule updatedSchedule = new Schedule(); updatedSchedule.UserName = User.Identity.Name; updatedSchedule.Monday = bool.Parse(mon); updatedSchedule.Tuesday = bool.Parse(tue); updatedSchedule.Wednesday = bool.Parse(wed); updatedSchedule.Thursday = bool.Parse(thu); updatedSchedule.Friday = bool.Parse(fri); updatedSchedule.Saturday = bool.Parse(sat); updatedSchedule.Sunday = bool.Parse(sun); db.Schedules.Add(updatedSchedule); db.SaveChanges(); return(Json("Finished updating schedule.", JsonRequestBehavior.AllowGet)); } } return(Json("Failed to update schedules.", JsonRequestBehavior.AllowGet)); }
private void AddSchedule() { var dc = new ScheduleDataContext(this.UserCD); dc.Schedule_Insert(this.Data); var cl = new FacebookBotClient(); cl.SendMessage(this.RecipientID, this.Text(BotTextKey.ScheduleAdded)); this.DeleteCommandData(); }
protected void Page_Load(object sender, EventArgs e) { if (MyCookie.HasClientId) { int clientId = int.Parse(MyCookie.ClientId); using (ScheduleDataContext db = new ScheduleDataContext(Config.LIFENAVConnectionString)) { var data = db.LIFENAV_GetDailyAppointments(DateTime.Today, null, clientId); Repeater1.DataSource = data; Repeater1.DataBind(); } } else { Response.Redirect("/Login.aspx", true); } }
public string GetMonthlySchedule(int year, int month) { using (ScheduleDataContext db = new ScheduleDataContext(Config.LIFENAVConnectionString)) { List<MonthlySchedule> schedules = new List<MonthlySchedule>(); DateTime startDate = new DateTime(year, month, 1); var query = db.LIFENAV_GetMonthlySchedule(startDate); foreach (LIFENAV_GetMonthlyScheduleResult data in query) { schedules.Add(new MonthlySchedule(data.Year, data.Month, data.Day, data.Appointments)); } string JSONSchedules = JavaScriptConvert.SerializeObject(schedules); return JSONSchedules; } }
public string GetDailyAppointments(int year, int month, int day) { using (ScheduleDataContext db = new ScheduleDataContext(Config.LIFENAVConnectionString)) { List<DailyAppointment> appointments = new List<DailyAppointment>(); DateTime startDate = new DateTime(year, month, day); var query = db.LIFENAV_GetDailyAppointments(startDate, 1, null); foreach (LIFENAV_GetDailyAppointmentsResult data in query) { appointments.Add(new DailyAppointment(data.ClientId, data.ShortName, data.ReservedDateTime)); } string JSONAppointments = JavaScriptConvert.SerializeObject(appointments); return JSONAppointments; } }
public string GetMonthlySchedule(int year, int month) { using (ScheduleDataContext db = new ScheduleDataContext(Config.LIFENAVConnectionString)) { List <MonthlySchedule> schedules = new List <MonthlySchedule>(); DateTime startDate = new DateTime(year, month, 1); var query = db.LIFENAV_GetMonthlySchedule(startDate); foreach (LIFENAV_GetMonthlyScheduleResult data in query) { schedules.Add(new MonthlySchedule(data.Year, data.Month, data.Day, data.Appointments)); } string JSONSchedules = JavaScriptConvert.SerializeObject(schedules); return(JSONSchedules); } }
public string GetDailyAppointments(int year, int month, int day) { using (ScheduleDataContext db = new ScheduleDataContext(Config.LIFENAVConnectionString)) { List <DailyAppointment> appointments = new List <DailyAppointment>(); DateTime startDate = new DateTime(year, month, day); var query = db.LIFENAV_GetDailyAppointments(startDate, 1, null); foreach (LIFENAV_GetDailyAppointmentsResult data in query) { appointments.Add(new DailyAppointment(data.ClientId, data.ShortName, data.ReservedDateTime)); } string JSONAppointments = JavaScriptConvert.SerializeObject(appointments); return(JSONAppointments); } }
public JsonResult GetSchedule() { string jsonSchedule = ""; using (ScheduleDataContext db = new ScheduleDataContext()) { string user = User.Identity.Name; bool exists = db.Schedules.Any(m => m.UserName == user); // User has a schedule so retrieve it if (exists) { Schedule schedule = db.Schedules.First(m => m.UserName == user); if (schedule != null) { jsonSchedule += "{"; jsonSchedule += "\"monday\":" + "\"" + schedule.Monday + "\"" + ","; jsonSchedule += "\"tuesday\":" + "\"" + schedule.Tuesday + "\"" + ","; jsonSchedule += "\"wednesday\":" + "\"" + schedule.Wednesday + "\"" + ","; jsonSchedule += "\"thursday\":" + "\"" + schedule.Thursday + "\"" + ","; jsonSchedule += "\"friday\":" + "\"" + schedule.Friday + "\"" + ","; jsonSchedule += "\"saturday\":" + "\"" + schedule.Saturday + "\"" + ","; jsonSchedule += "\"sunday\":" + "\"" + schedule.Sunday + "\"" + "}"; } else { return(Json("failed", JsonRequestBehavior.AllowGet)); } } else // User doesn't have a schedule so make a default one { jsonSchedule += "{"; jsonSchedule += "\"monday\":" + "\"" + "True" + "\"" + ","; jsonSchedule += "\"tuesday\":" + "\"" + "True" + "\"" + ","; jsonSchedule += "\"wednesday\":" + "\"" + "True" + "\"" + ","; jsonSchedule += "\"thursday\":" + "\"" + "True" + "\"" + ","; jsonSchedule += "\"friday\":" + "\"" + "True" + "\"" + ","; jsonSchedule += "\"saturday\":" + "\"" + "True" + "\"" + ","; jsonSchedule += "\"sunday\":" + "\"" + "True" + "\"" + "}"; } } return(Json(jsonSchedule, JsonRequestBehavior.AllowGet)); }
public ActionResult Index(CancellationToken cancellationToken) { // Google Authorization var result = new AuthorizationCodeMvcApp(this, new AppFlowMetadata()). AuthorizeAsync(cancellationToken).Result; if (result.Credential != null) { string user = User.Identity.Name; CalendarService service = new CalendarService(new BaseClientService.Initializer { HttpClientInitializer = result.Credential, ApplicationName = "GameLogger" }); using (ScheduleDataContext db = new ScheduleDataContext()) { bool scheduleExists = db.Schedules.Any(m => m.UserName == user); bool playedGameExists = db.PlayedGames.Any(m => m.UserName == user); // If no schedule exists then create one if (!scheduleExists) { Schedule schedule = new Schedule(); schedule.UserName = user; db.Schedules.Add(schedule); db.SaveChanges(); } // If user is playing a game then add it to the calendar if (playedGameExists) { Schedule schedule = db.Schedules.First(m => m.UserName == user); PlayedGame playedGame = db.PlayedGames.First(m => m.UserName == user); int id = playedGame.GameId; Game game = db.Games.First(m => m.Id == id); // User has a game selected and a schedule set up so update their Google Calendar if (schedule != null && playedGame != null) { AddCalendarEvent(service, schedule, game); } } else // No game is being played so create an empty calendar { // Get gamelogger calendar or make one if it doesn't exist IList <CalendarListEntry> calendars = service.CalendarList.List().Execute().Items; // Delete previous calendar and create a new one for (int i = 0; i < calendars.Count; i++) { if (calendars[i].Summary == "GameLogger") { service.Calendars.Delete(calendars[i].Id).Execute(); } } // Create new calendar Calendar calendar = new Calendar(); calendar.Summary = "GameLogger"; calendar.TimeZone = "America/New_York"; var newCal = service.Calendars.Insert(calendar).Execute(); string id = newCal.Id; } } return(View()); } else { return(new RedirectResult(result.RedirectUri)); } }
public HomeController(ScheduleDataContext context) { _context = context; }