Exemple #1
0
        public async Task <List <TimedStudentData> > GetAllUserByPeriod([FromBody] BddInfoModel model)
        {
            var sqlDatabase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            IEnumerable <TimedStudentData> studentList       = new List <TimedStudentData>();
            List <TimedStudentData>        timedStudentDatas = new List <TimedStudentData>();
            int userId = _authenticationInfo.ActualUser.UserId;


            using (var ctx = new SqlStandardCallContext())
            {
                AclQueries aclQueries = new AclQueries(ctx, sqlDatabase);

                if (!await aclQueries.VerifyGrantLevelByUserId(112, 9, userId, Operator.SuperiorOrEqual))
                {
                    Result result = new Result(Status.Unauthorized, "Vous n'etes pas autorisé à utiliser cette fonctionnalité !");
                }


                TimedPeriodQueries timedPeriodQueries = new TimedPeriodQueries(ctx, sqlDatabase);
                GroupQueries       groupQueries       = new GroupQueries(ctx, sqlDatabase);
                TimedUserQueries   timedUserQueries   = new TimedUserQueries(ctx, sqlDatabase);


                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

                //PeriodData periodData = await timedPeriodQueries.GetLastPeriodBySchool( groupData.ZoneId );
                IEnumerable <GroupData> groupList = await groupQueries.GetAllGroupByPeriod(groupData.ZoneId);

                List <GroupData> groupFinal = groupList.ToList();
                for (int i = 0; i < groupFinal.Count; i++)
                {
                    studentList = await timedUserQueries.GetAllStudentInfosByGroup(groupFinal[i].GroupId, model.TableName, model.TableId);

                    timedStudentDatas.AddRange(studentList);
                }
            }

            var duplicates = timedStudentDatas
                             .GroupBy(x => x.UserId)
                             .Where(g => g.Count() > 1)
                             .Select(g => g.Select(gg => gg));

            var single = timedStudentDatas
                         .GroupBy(x => x.UserId)
                         .Where(g => g.Count() == 1)
                         .SelectMany(g => g.Select(gg => gg));

            List <TimedStudentData> timedStudentDatasClean = new List <TimedStudentData>();

            timedStudentDatasClean = single.ToList();
            for (var i = 0; i < duplicates.Count(); i++)
            {
                var a = duplicates.ElementAt(i);

                if (a.ElementAt(0).GroupName == "S01" || a.ElementAt(0).GroupName == "S02")
                {
                    a.ElementAt(0).GroupName = a.ElementAt(0).GroupName;
                }
                else if (a.ElementAt(1).GroupName == "SR")
                {
                    a.ElementAt(0).GroupName = a.ElementAt(0).GroupName + " - " + a.ElementAt(1).GroupName;
                }
                else
                {
                    a.ElementAt(0).GroupName = a.ElementAt(1).GroupName + " - " + a.ElementAt(0).GroupName;
                }
                timedStudentDatasClean.Add(a.ElementAt(0));
            }
            ;

            return(timedStudentDatasClean);
        }