// GET: /Export public ActionResult Export(string id) { //Get ClientSubUnit ClientSubUnit clientSubUnit = new ClientSubUnit(); clientSubUnit = clientSubUnitRepository.GetClientSubUnit(id); //Check Exists if (clientSubUnit == null) { ViewData["ActionMethod"] = "CreateGet"; return(View("RecordDoesNotExistError")); } //Access Rights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToClientSubUnit(id) || !hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } string filename = string.Format("{0}-{1}-BookingChannels Export.csv", CWTStringHelpers.AlphaNumericOnly(clientSubUnit.ClientTopUnit.ClientTopUnitName), CWTStringHelpers.AlphaNumericOnly(clientSubUnit.ClientSubUnitName)); //Get CSV Data byte[] csvData = bookingChannelRepository.Export(id); return(File(csvData, "text/csv", filename)); }
// GET: /ExportErrors public ActionResult ExportErrors() { var preImportCheckResultVM = (BookingChannelImportStep1VM)TempData["ErrorMessages"]; if (preImportCheckResultVM == null) { ViewData["ActionMethod"] = "ExportGet"; return(View("RecordDoesNotExistError")); } if (preImportCheckResultVM.ClientSubUnit == null) { ViewData["ActionMethod"] = "ExportGet"; return(View("RecordDoesNotExistError")); } //Check Exists ClientSubUnit clientSubUnit = clientSubUnitRepository.GetClientSubUnit(preImportCheckResultVM.ClientSubUnit.ClientSubUnitGuid); if (clientSubUnit == null) { ViewData["ActionMethod"] = "ExportGet"; return(View("RecordDoesNotExistError")); } //Get CSV Data var errors = preImportCheckResultVM.ImportStep2VM.ReturnMessages; var combinedErrors = errors.Aggregate((current, next) => current + "\r\n" + next); byte[] csvData = Encoding.ASCII.GetBytes(combinedErrors); return(File(csvData, "text/plain", string.Format("{0}-{1}-BookingChannels Error Summary.txt", CWTStringHelpers.AlphaNumericOnly(clientSubUnit.ClientTopUnit.ClientTopUnitName), CWTStringHelpers.AlphaNumericOnly(clientSubUnit.ClientSubUnitName)))); }