public ActionResult FileUpload(IFormFile Files) { try { string path = " "; if (UniversalFunctions.File_is_not_empty(Files)) { path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", Files.FileName); UniversalFunctions.CreateFileStream(Files, path); } else { return(View()); } List <string[]> Events = CSVImportParser.GetListFromCSV(path); for (int i = 0; i < Events.Count; i++) { Event ev = EventFunctions.GetEventFromString(Events[i]); eventManager.AddEventToDB(ev); } UniversalFunctions.RemoveTempFile(path); return(RedirectToAction("Index")); } catch { return(RedirectToAction("IncorrectFile", "Home")); } }
public ActionResult FileUpload(IFormFile Files) { try { List <Volunteer> volunteers = volunteerManager.GetListOfVolunteers(); int docsimported = 0; if (UniversalFunctions.File_is_not_empty(Files)) { string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", Files.FileName); UniversalFunctions.CreateFileStream(Files, path); List <string[]> volunteersasstring = CSVImportParser.GetListFromCSV(path); if (CSVImportParser.DefaultVolunteerCSVFormat(path)) { for (int i = 0; i < volunteersasstring.Count; i++) { Volunteer volunteer = new Volunteer(); volunteer = VolunteerFunctions.GetVolunteerFromString(volunteersasstring[i]); if (VolunteerFunctions.DoesNotExist(volunteers, volunteer)) { docsimported++; volunteerManager.AddVolunteerToDB(volunteer); } } } else { for (int i = 0; i < volunteersasstring.Count; i++) { Volunteer volunteer = new Volunteer(); volunteer = VolunteerFunctions.GetVolunteerFromOtherString(volunteersasstring[i]); if (VolunteerFunctions.DoesNotExist(volunteers, volunteer)) { docsimported++; volunteerManager.AddVolunteerToDB(volunteer); } } } UniversalFunctions.RemoveTempFile(path); return(RedirectToAction("ImportUpdate", "Home", new { docsimported })); } else { return(View()); } } catch { return(RedirectToAction("IncorrectFile", "Home")); } }
public ActionResult FileUpload(IFormFile Files) { try { List <Beneficiary> beneficiaries = beneficiaryManager.GetListOfBeneficiaries(); int docsimported = 0; if (UniversalFunctions.File_is_not_empty(Files)) { string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", Files.FileName); UniversalFunctions.CreateFileStream(Files, path); List <string[]> beneficiaryasstring = CSVImportParser.GetListFromCSV(path); if (CSVImportParser.DefaultBeneficiaryCSVFormat(path)) { for (int i = 0; i < beneficiaryasstring.Count; i++) { Beneficiary beneficiary = new Beneficiary(); beneficiary = BeneficiaryFunctions.GetBeneficiaryFromString(beneficiaryasstring[i]); if (BeneficiaryFunctions.DoesNotExist(beneficiaries, beneficiary)) { docsimported++; beneficiaryManager.AddBeneficiaryToDB(beneficiary); } } } else { for (int i = 0; i < beneficiaryasstring.Count; i++) { Beneficiary beneficiary = new Beneficiary(); beneficiary = BeneficiaryFunctions.GetBeneficiaryFromOtherString(beneficiaryasstring[i]); if (BeneficiaryFunctions.DoesNotExist(beneficiaries, beneficiary)) { docsimported++; beneficiaryManager.AddBeneficiaryToDB(beneficiary); } } } List <Beneficiary> beneficiarycollection = beneficiaryManager.GetListOfBeneficiaries(); List <Beneficiarycontract> beneficiaryContractCollection = beneficiaryContractManager.GetListOfBeneficiariesContracts(); List <Beneficiarycontract> beneficiaryContracts = BeneficiaryFunctions.GetBeneficiaryContractsFromCsv(beneficiaryasstring, beneficiarycollection, beneficiaryContractCollection); foreach (Beneficiarycontract bc in beneficiaryContracts) { bc._id = Guid.NewGuid().ToString(); beneficiaryContractManager.AddBeneficiaryContractToDB(bc); } UniversalFunctions.RemoveTempFile(path); return(RedirectToAction("ImportUpdate", "Home", new { docsimported })); } else { return(View()); } } catch { return(RedirectToAction("IncorrectFile", "Home")); } }