public ActionResult ExportSchedule(string id, string username) { var name = username.FromBase64String(); var schedule = PaulRepository.GetSchedule(id); if (schedule != null && schedule.Users.Any(u => u.Name == name)) { return(File(Encoding.UTF8.GetBytes(ScheduleExporter.ExportSchedule(schedule, name)), "text/calendar", $"schedule{schedule.Id}_{name}.ics")); } else { return(BadRequest()); } }
/// <summary> /// Loads the schedule with the specified ID either from /// cache or from the database. /// </summary> /// <param name="scheduleId">Schedule ID</param> /// <returns> /// A ViewModel representing the schedule or null if no /// schedule with the specified ID exists /// </returns> public SharedScheduleViewModel GetOrLoadSchedule(string scheduleId) { SharedScheduleViewModel scheduleVm; if (_loadedSchedules.TryGetValue(scheduleId, out scheduleVm)) { return(scheduleVm); } else { var schedule = PaulRepository.GetSchedule(scheduleId); if (schedule == null) { // Schedule with that ID does not exist return(null); } var vm = new SharedScheduleViewModel(schedule); _loadedSchedules.Add(scheduleId, vm); return(vm); } }