Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetInfosOwnAccount()
        {
            int userId      = _authenticationInfo.ActualUser.UserId;
            var sqlDataBase = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();

            using (var ctx = new SqlStandardCallContext())
            {
                AccountUserData accountUserData = new AccountUserData();

                PeriodServices     periodService      = new PeriodServices();
                UserQueries        userQueries        = new UserQueries(ctx, sqlDataBase);
                GroupQueries       groupQueries       = new GroupQueries(ctx, sqlDataBase);
                TimedPeriodQueries timedPeriodQueries = new TimedPeriodQueries(ctx, sqlDataBase);
                TimedUserQueries   timedUserQueries   = new TimedUserQueries(ctx, sqlDataBase);

                //Donnée de l'utilisateur
                UserData userData = await userQueries.GetInfosUserById(userId);

                //Derniere PeriodId de l'user et timedUserId
                TimedUserData timedUser = await timedUserQueries.GetLastTimedUserId(userId);

                if (timedUser == null)
                {
                    accountUserData.UserData = userData;
                    accountUserData.Group    = "User";
                    return(Ok(accountUserData));
                }

                //Recuperer Groupe du timedUser
                List <string> listGroupUser = await groupQueries.GetAllGroupOfTimedUserByPeriod(timedUser.TimePeriodId, timedUser.TimedUserId);

                string group = listGroupUser.Find(x => x.StartsWith("S0") || x.StartsWith("S1") || x == "Teacher" || x == "Administration");
                string spec  = listGroupUser.Find(x => x == "IL" || x == "SR");

                if (spec != null)
                {
                    group += "-" + spec;
                }

                accountUserData.UserData = userData;
                accountUserData.Group    = group;

                if (await periodService.CheckInPeriod(_stObjMap, _authenticationInfo))
                {
                    accountUserData.IsActual = true;
                }
                else
                {
                    accountUserData.IsActual = false;
                }

                return(Ok(accountUserData));
            }
        }
Exemplo n.º 4
0
        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());
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> VerifyActualPeriod()
        {
            PeriodServices periodServices = new PeriodServices();

            return(Ok(await periodServices.CheckInPeriod(_stObjMap, _authenticationInfo)));
        }
Exemplo n.º 6
0
        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());
            }
        }