public async Task <FileResult> Download(int templateId) { var template = db.Templates.First(x => x.TemplateId == templateId); var filters = JsonConvert.DeserializeObject <FilterInputs>(template.Filters); var csvUtils = new CsvMethods(); var bytes = await csvUtils.GetZipFile( filters.Schools, //filters.SchoolYears, //filters.Terms, //filters.Subjects, //filters.Courses, filters.Teachers, filters.Sections, template.OneRosterVersion); var logUtils = new LoggingMethods(); string ip = Request.UserHostAddress; logUtils.LogAdminDownload(template, UserName, ip); var downloadFileName = "EdFiExport_" + string.Format("{0:MM_dd_yyyy}", DateTime.Now) + ".zip"; return(File(bytes, "application/zip", downloadFileName)); }
public async Task <ActionResult> DownloadCsv(ExportsViewModel model) { var schools = model.SelectedSchools?.Split(',').ToList(); //var schoolYears = model.SelectedSchoolYears?.Split(',').ToList(); //var terms = model.SelectedTerms?.Split(',').ToList(); //var subjects = model.SelectedSubjects?.Split(',').ToList(); //var courses = model.SelectedCourses?.Split(',').ToList(); var teachers = model.SelectedTeachers?.Split(',').ToList(); var sections = model.SelectedSections?.Split(',').ToList(); var csvUtils = new CsvMethods(); //var bytes = await csvUtils.GetZipFile(schools, schoolYears, terms, subjects, courses, teachers, sections, model.OneRosterVersion); var bytes = await csvUtils.GetZipFile(schools, teachers, sections, model.OneRosterVersion); var downloadFileName = "EdFiExport_" + string.Format("{0:MM_dd_yyyy}", DateTime.Now) + ".zip"; return(File(bytes, "application/zip", downloadFileName)); }
public async Task <ActionResult> Index(string id) //Careful when changing this method definition. There is a custom route for it in the RouteConfig. { var logUtils = new LoggingMethods(); var template = db.Templates.First(x => x.AccessUrl.Contains(id)); if (Request.Headers["token"] == null) //http://forums.asp.net/t/1991328.aspx?Reading+HTTP+Header+in+MVC+5 { var errorMsg = "No Security Token Received"; logUtils.LogUserDownload(template, IpAddress, false, errorMsg); return(Json(new { ErrorMessage = errorMsg }, JsonRequestBehavior.AllowGet)); } string token = Request.Headers["token"]; if (template == null || template.AccessToken != token) { var errorMsg = "Url not found and/or token doesnt match"; logUtils.LogUserDownload(template, IpAddress, false, errorMsg); return(Json(new { ErrorMessage = errorMsg }, JsonRequestBehavior.AllowGet)); } var filters = JsonConvert.DeserializeObject <FilterInputs>(template.Filters); var csvUtils = new CsvMethods(); var bytes = await csvUtils.GetZipFile( filters.Schools, //filters.SchoolYears, //filters.Terms, //filters.Subjects, //filters.Courses, filters.Teachers, filters.Sections, template.OneRosterVersion); logUtils.LogUserDownload(template, IpAddress, true, null); var downloadFileName = "EdFiExport_" + string.Format("{0:MM_dd_yyyy}", DateTime.Now) + ".zip"; return(File(bytes, "application/zip", downloadFileName)); }