public async Task <IActionResult> AddStudentListCsv(string type) { var file = Request.Form.Files[0]; int userId = _authenticationInfo.ActualUser.UserId; var sqlDatabase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>(); PeriodServices periodServices = new PeriodServices(); using (var ctx = new SqlStandardCallContext()) { GroupQueries groupQueries = new GroupQueries(ctx, sqlDatabase); AclQueries aclQueries = new AclQueries(ctx, sqlDatabase); GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId); // User must have the rights to do this action //if( await aclQueries.VerifyGrantLevelByUserId( 112, await aclQueries.GetAclIdBySchoolId( groupData.ParentZoneId ), userId, Operator.SuperiorOrEqual ) == false ) //{ // Result result = new Result( Status.Unauthorized, "Vous n'etes pas autorisé à utiliser cette fonctionnalité !" ); // return this.CreateResult( result ); //} bool isInPeriod = await periodServices.CheckInPeriod(_stObjMap, _authenticationInfo); // The school in wich the user is need to be in a period when the action is done if (!isInPeriod) { Result result = new Result(Status.Unauthorized, "A la date d'aujourd'hui votre etablissement n'est dans une aucune periode"); return(this.CreateResult(result)); } if (type == "student" || type == "staffMember") { CsvStudentMapping <UserList> csvStudentMapping = new CsvStudentMapping <UserList>(_emailer); List <UserList> studentResult = await csvStudentMapping.CSVReader(file); await csvStudentMapping.UserParser(studentResult, _stObjMap, _authenticationInfo, type); } else if (type == "projectNumber") { CsvStudentMapping <ProjectNumbers> csvStudentMapping = new CsvStudentMapping <ProjectNumbers>(_emailer); List <ProjectNumbers> projectNumbers = await csvStudentMapping.CSVReaderProjectNumber(file); await csvStudentMapping.ForumNumberParser(_stObjMap, projectNumbers, _authenticationInfo); } else if (type == "jury") { CsvStudentMapping <JuryInfos> csvStudentMapping = new CsvStudentMapping <JuryInfos>(_emailer); List <JuryInfos> result = await csvStudentMapping.CSVReaderProjectNumber(file); await csvStudentMapping.AssignProjectToJury(_stObjMap, _authenticationInfo, result, type); } } return(Ok()); }
/// <summary> /// Parses the stream to student list. /// </summary> /// <param name="fileStream">The file stream.</param> /// <returns></returns> public List <CsvMappingResult <Student> > ParseStreamToStudentList(Stream fileStream) { var streamReader = new StreamReader(fileStream); var fileString = streamReader.ReadToEnd(); var csvParserOptions = new CsvParserOptions(true, ','); var csvReaderOptions = new CsvReaderOptions(new[] { Environment.NewLine }); var csvMapper = new CsvStudentMapping(); var csvParser = new CsvParser <Student>(csvParserOptions, csvMapper); return(csvParser.ReadFromString(csvReaderOptions, fileString).ToList()); }