示例#1
0
        public async Task <IActionResult> GetAllGradeProject()
        {
            SqlDefaultDatabase db = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            int userId            = _authenticationInfo.ActualUser.UserId;

            using (var ctx = new SqlStandardCallContext())
            {
                ProjectQueries     projectQueries     = new ProjectQueries(ctx, db);
                TimedPeriodQueries timedPeriodQueries = new TimedPeriodQueries(ctx, db);
                TimedUserQueries   timedUserQueries   = new TimedUserQueries(ctx, db);
                UserQueries        userQueries        = new UserQueries(ctx, db);
                GroupQueries       groupQueries       = new GroupQueries(ctx, db);

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

                AclQueries aclQueries = new AclQueries(ctx, db);

                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));
                }

                List <ProjectInfosJuryData> projects = await projectQueries.getAllProjectsGrade(groupData.ZoneId);

                List <ProjectForumResultData> listToSend = GetProjectsOfForum(projects);

                return(Ok(listToSend));
            }
        }
示例#2
0
        public async Task <IActionResult> DownloadExcel(  )
        {
            var         sqlDatabase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            ExcelUtilis excel       = new ExcelUtilis();
            int         userId      = _authenticationInfo.ActualUser.UserId;

            using (var ctx = new SqlStandardCallContext())
            {
                GroupQueries   groupQueries   = new GroupQueries(ctx, sqlDatabase);
                ProjectQueries projectQueries = new ProjectQueries(ctx, sqlDatabase);

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

                AclQueries aclQueries = new AclQueries(ctx, sqlDatabase);

                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));
                }
                List <ProjectInfosJuryData> projectInfosJuries = await projectQueries.getAllProjectsGrade(groupData.ZoneId);

                List <ProjectForumResultData> allProjectsForumResult = GetProjectsOfForum(projectInfosJuries);


                byte[] excelToArray = await excel.CreateExcel(allProjectsForumResult, projectQueries);

                return(File(excelToArray, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
            }
        }
        public async Task <IActionResult> GetEvents()
        {
            int userId      = _authenticationInfo.ActualUser.UserId;
            var sqlDataBase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();

            using (var ctx = new SqlStandardCallContext())
            {
                GroupQueries groupQueries = new GroupQueries(ctx, sqlDataBase);
                EventQueries eventQueries = new EventQueries(ctx, sqlDataBase);

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

                AclQueries aclQueries = new AclQueries(ctx, sqlDataBase);

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

                List <EventData> events = await eventQueries.GetAllEventsByIdSchool(groupData.ParentZoneId);

                return(Ok(events));
            }
        }
        public async Task <IActionResult> UpdateEvents([FromBody] SchoolEventChangeModel model)
        {
            int userId      = _authenticationInfo.ActualUser.UserId;
            var sqlDataBase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();

            using (var ctx = new SqlStandardCallContext())
            {
                PeriodServices periodServices = new PeriodServices();
                GroupQueries   groupQueries   = new GroupQueries(ctx, sqlDataBase);
                EventQueries   eventQueries   = new EventQueries(ctx, sqlDataBase);

                if (!await periodServices.CheckPeriodGivenDate(_stObjMap, _authenticationInfo, model.BegDate, model.EndDate))
                {
                    Result result = new Result(Status.BadRequest, "Ces Dates ne sont pas comprises dans la periode actuel");
                    return(this.CreateResult(result));
                }

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

                AclQueries aclQueries = new AclQueries(ctx, sqlDataBase);

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

                await eventQueries.UpdateEvent(model.EventId, model.Name, model.BegDate, model.EndDate);

                List <EventData> events = await eventQueries.GetAllEventsByIdSchool(groupData.ParentZoneId);

                return(Ok(events));
            }
        }
示例#5
0
        public async Task deny_create_period()
        {
            DateTime dateTime    = DateTime.Now;
            DateTime dateTime2   = DateTime.Now.AddDays(1);
            var      timePeriod  = TestHelper.StObjMap.StObjs.Obtain <TimePeriodTable>();
            var      sqldatabase = TestHelper.StObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            var      userTable   = TestHelper.StObjMap.StObjs.Obtain <CustomUserTable>();
            var      group       = TestHelper.StObjMap.StObjs.Obtain <CustomGroupTable>();

            bool result = false;

            using (var ctx = new SqlStandardCallContext(TestHelper.Monitor))
            {
                AclQueries aclQueries = new AclQueries(ctx, sqldatabase);
                var        userId     = userTable.CreateUser(ctx, 1, Guid.NewGuid().ToString(), "NotAdmin", "NotAdmin");
                //Acl ID 9 is AclManagementId of Zone ID InTech
                if (await aclQueries.VerifyGrantLevelByUserId(127, 9, userId, Operator.SuperiorOrEqual) == true)
                {
                    var id = await timePeriod.CreateTimePeriodAsync(ctx, 1, dateTime, dateTime2, "I", 4);

                    result = true;
                    Assert.That(id > 0);
                }

                Assert.That(result == false);
            }
        }
        public async Task <IActionResult> DeleteEvent(int EventId)
        {
            int userId      = _authenticationInfo.ActualUser.UserId;
            var sqlDataBase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            var eventTable  = _stObjMap.StObjs.Obtain <EventSchoolTable>();

            using (var ctx = new SqlStandardCallContext())
            {
                AclQueries   aclQueries   = new AclQueries(ctx, sqlDataBase);
                GroupQueries groupQueries = new GroupQueries(ctx, sqlDataBase);

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

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

                EventStruct eventResult = await eventTable.DeleteEvent(ctx, userId, EventId);

                if (eventResult.Status == 1)
                {
                    Result result = new Result(Status.BadRequest, "Cette évenement n'existe plus ou n'a jamais existé ! ");
                    return(this.CreateResult(result));
                }

                return(Ok());
            }
        }
示例#7
0
        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());
        }
        public async Task <IActionResult> BlockedProject([FromBody] BlockedGradeViewModel model)
        {
            int                userId         = _authenticationInfo.ActualUser.UserId;
            EvaluatesTable     evaluatesTable = _stObjMap.StObjs.Obtain <EvaluatesTable>();
            SqlDefaultDatabase db             = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            PeriodServices     periodServices = new PeriodServices();


            using (var ctx = new SqlStandardCallContext())
            {
                AclQueries   aclQueries   = new AclQueries(ctx, db);
                GroupQueries groupQueries = new GroupQueries(ctx, db);

                if (!await periodServices.CheckInPeriod(_stObjMap, _authenticationInfo))
                {
                    Result result = new Result(Status.Unauthorized, "A la date d'aujourd'hui votre etablissement n'est dans une aucune periode");
                    return(this.CreateResult(result));
                }

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

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

                int idx = 0;
                foreach (var item in model.IndividualGrade)
                {
                    if (item.Value > 0)
                    {
                        await evaluatesTable.BlockedProjectGrade(ctx, model.JurysId[idx], model.ProjectId, item.Value, true);
                    }
                    else
                    {
                        await evaluatesTable.BlockedProjectGrade(ctx, model.JurysId[idx], model.ProjectId, true);
                    }
                    idx++;
                }

                return(Ok());
            }
        }
示例#9
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);
        }
        public async Task <IActionResult> CreatePeriod([FromBody] CreatePeriodModel createPeriodModel)
        {
            int userId      = _authenticationInfo.ActualUser.UserId;
            var sqlDatabase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            var group       = _stObjMap.StObjs.Obtain <CustomGroupTable>();
            var timePeriod  = _stObjMap.StObjs.Obtain <TimePeriodTable>();
            var timedUser   = _stObjMap.StObjs.Obtain <TimedUserTable>();

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

                //if( await aclQueries.VerifyGrantLevelByUserId( 112, await aclQueries.GetAclIdBySchoolId( createPeriodModel.idZone ), userId, Operator.SuperiorOrEqual ) == false )
                //{
                //    Result result = new Result( Status.Unauthorized, "Vous n'etes pas autorisé à utiliser cette fonctionnalité !" );
                //    return this.CreateResult( result );
                //}

                createPeriodModel.begDate = createPeriodModel.begDate.AddDays(1);
                createPeriodModel.endDate = createPeriodModel.endDate.AddDays(1);

                var idPeriod = await timePeriod.CreateTimePeriodAsync(ctx, 1, createPeriodModel.begDate, createPeriodModel.endDate, createPeriodModel.Kind, createPeriodModel.idZone);

                if (idPeriod == 0)
                {
                    Result result = new Result(Status.BadRequest, "Quelques choses s'est mal passé durant la création de periode.");
                    return(this.CreateResult(result));
                }
                string groupName = createPeriodModel.begDate.Year + "-0" + createPeriodModel.begDate.Month;

                await group.Naming.GroupRenameAsync(ctx, userId, idPeriod, groupName);

                int idGroupAdmin = 0;
                for (int i = 0; i < createPeriodModel.Groups.Count; i++)
                {
                    int idGroup;

                    if (createPeriodModel.Groups[i].IsAlreadyPermanent == false && createPeriodModel.Groups[i].State == true)
                    {
                        idGroup = await group.CreateGroupAsync(ctx, userId, 4);

                        await group.Naming.GroupRenameAsync(ctx, 17, idGroup, createPeriodModel.Groups[i].Name);
                    }

                    idGroup = await group.CreateGroupAsync(ctx, userId, idPeriod);

                    await group.Naming.GroupRenameAsync(ctx, 17, idGroup, createPeriodModel.Groups[i].Name);

                    if (createPeriodModel.Groups[i].Name == "Administration")
                    {
                        idGroupAdmin = idGroup;
                    }
                }

                await group.AddUserAsync(ctx, 1, idGroupAdmin, userId, true);

                await timedUser.CreateOrUpdateTimedUserAsyncWithType(ctx, Data.TypeTimedUser.StaffMember, idPeriod, userId);

                return(this.CreateResult(Result.Success()));
            }
        }
        public async Task <IActionResult> NoteProject([FromBody] NoteProjectViewModel model)
        {
            int userId = _authenticationInfo.ActualUser.UserId;
            TimedUserNoteProjectTable timedUserNoteProjectTable = _stObjMap.StObjs.Obtain <TimedUserNoteProjectTable>();
            TimedUserTable            timedUserTable            = _stObjMap.StObjs.Obtain <TimedUserTable>();
            EvaluatesTable            evaluatesTable            = _stObjMap.StObjs.Obtain <EvaluatesTable>();
            SqlDefaultDatabase        db             = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            PeriodServices            periodServices = new PeriodServices();

            using (var ctx = new SqlStandardCallContext())
            {
                ProjectQueries     projectQueries     = new ProjectQueries(ctx, db);
                TimedPeriodQueries timedPeriodQueries = new TimedPeriodQueries(ctx, db);
                UserQueries        userQueries        = new UserQueries(ctx, db);
                TimedUserQueries   timedUserQueries   = new TimedUserQueries(ctx, db);
                AclQueries         aclQueries         = new AclQueries(ctx, db);
                GroupQueries       groupQueries       = new GroupQueries(ctx, db);

                //Case Change Grade by Administration ====================================================================================================================
                if (model.User == ViewModels.TypeTimedUser.StaffMember)
                {
                    if (!await periodServices.CheckInPeriod(_stObjMap, _authenticationInfo))
                    {
                        Result result = new Result(Status.Unauthorized, "A la date d'aujourd'hui votre etablissement n'est dans une aucune periode");
                        return(this.CreateResult(result));
                    }

                    GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

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

                    await evaluatesTable.EvaluateOrUpdateGradeProject(ctx, model.JuryId, model.ProjectId, model.Grade);

                    return(Ok());
                }
                //=========================================================================================================================================================

                PeriodData periodData = await timedPeriodQueries.GetLastPeriodBySchool(model.SchoolId);

                TimedUserData timedUserData = await timedUserQueries.GetTimedUser(userId, periodData.ChildId);

                if (timedUserData == null)
                {
                    TimedUserStruct timedUser = await timedUserTable.CreateOrUpdateTimedUserAsyncWithType(ctx, Data.TypeTimedUser.Anon, periodData.ChildId, userId);

                    timedUserData = new TimedUserData
                    {
                        TimedUserId = timedUser.TimedUserId
                    };
                    await timedUserNoteProjectTable.AddOrUpdateNote(ctx, timedUserData.TimedUserId, model.ProjectId, model.Grade);

                    return(Ok());
                }

                if (model.User == ViewModels.TypeTimedUser.Jury)
                {
                    await evaluatesTable.EvaluateOrUpdateGradeProject(ctx, model.JuryId, model.ProjectId, model.Grade);
                }
                else
                {
                    await timedUserNoteProjectTable.AddOrUpdateNote(ctx, timedUserData.TimedUserId, model.ProjectId, model.Grade);
                }

                return(Ok());
            }
        }