Пример #1
0
        public async Task Add_TimedUser_AnyType()
        {
            var      userTimed   = TestHelper.StObjMap.StObjs.Obtain <TimedUserTable>();
            var      userTable   = TestHelper.StObjMap.StObjs.Obtain <CustomUserTable>();
            var      school      = TestHelper.StObjMap.StObjs.Obtain <SchoolTable>();
            var      timePeriod  = TestHelper.StObjMap.StObjs.Obtain <TimePeriodTable>();
            var      sqlDatabase = TestHelper.StObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            DateTime dateTime    = DateTime.Now;
            DateTime dateTime2   = DateTime.Now.AddDays(1);
            int      maxType     = 4;

            using (var ctx = new SqlStandardCallContext(TestHelper.Monitor))
            {
                TimedUserQueries timedUserQueries = new TimedUserQueries(ctx, sqlDatabase);
                var idSchool = await school.CreateSchool(ctx, 1, Guid.NewGuid().ToString());

                var userId = await userTable.CreateUserAsync(ctx, 1, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

                var id = await timePeriod.CreateTimePeriodAsync(ctx, 1, dateTime, dateTime2, "S", idSchool);

                for (int i = 0; i < maxType; i++)
                {
                    TimedUserStruct result = await userTimed.CreateOrUpdateTimedUserAsync(ctx, i, id, userId);

                    Assert.That(result.Status == i);

                    if (await timedUserQueries.GetAllTimedUserByUserId(userId) == null)
                    {
                        TimedUserStruct result2 = await userTimed.CreateOrUpdateTimedUserAsync(ctx, i, id, userId);

                        Assert.That(result2.Status == i);
                    }
                }
            }
        }
Пример #2
0
        public async Task add_or_update_note()
        {
            var userTable      = TestHelper.StObjMap.StObjs.Obtain <CustomUserTable>();
            var school         = TestHelper.StObjMap.StObjs.Obtain <SchoolTable>();
            var timePeriod     = TestHelper.StObjMap.StObjs.Obtain <TimePeriodTable>();
            var sqlDatabase    = TestHelper.StObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            var noteTable      = TestHelper.StObjMap.StObjs.Obtain <TimedUserNoteProjectTable>();
            var projectStudent = TestHelper.StObjMap.StObjs.Obtain <ProjectStudentTable>();
            var userTimed      = TestHelper.StObjMap.StObjs.Obtain <TimedUserTable>();

            DateTime dateTime  = DateTime.Now;
            DateTime dateTime2 = DateTime.Now.AddDays(1);

            double grade = 10.5F;

            using (var ctx = new SqlStandardCallContext())
            {
                ProjectQueries timedUserQueries = new ProjectQueries(ctx, sqlDatabase);

                var idSchool = await school.CreateSchool(ctx, 1, Guid.NewGuid().ToString());

                var userId = await userTable.CreateUserAsync(ctx, 1, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

                var id = await timePeriod.CreateTimePeriodAsync(ctx, 1, dateTime, dateTime2, "S", idSchool);

                // 0 = Anon Create TimedUser
                TimedUserStruct result = await userTimed.CreateOrUpdateTimedUserAsync(ctx, 0, id, userId);

                var ProjectCreate = await projectStudent.CreateProjectStudent(ctx, 1, 2, "name", 1, "a;b;c", "aaa", "okok", "wwww", 1, "I");

                await noteTable.AddOrUpdateNote(ctx, result.TimedUserId, ProjectCreate.ProjectStudentId, grade);

                Assert.That(await timedUserQueries.GetProjectGradeSpecificTimedUser(ProjectCreate.ProjectStudentId, result.TimedUserId) == grade);
                Assert.That(await timedUserQueries.GetProjectGradeSpecificTimedUser(ProjectCreate.ProjectStudentId, result.TimedUserId) == grade);
                //Assert.That( await timedUserQueries.GetProjectGradeSpecJury( ProjectCreate.ProjectStudentId, result.TimedUserId ) == grade );

                grade = 15;

                await noteTable.AddOrUpdateNote(ctx, result.TimedUserId, ProjectCreate.ProjectStudentId, grade);

                Assert.That(await timedUserQueries.GetProjectGradeSpecificTimedUser(ProjectCreate.ProjectStudentId, result.TimedUserId) == grade);
                //     Assert.That( await timedUserQueries.GetProjectGradeSpecificTimedUser( ProjectCreate.ProjectStudentId, result.TimedUserId ) == grade );
                //     Assert.That( await timedUserQueries.GetProjectGradeSpecJury( ProjectCreate.ProjectStudentId, result.TimedUserId ) == grade );
            }
        }
Пример #3
0
        public async Task verify_user_is_in_group()
        {
            var      userTimed   = TestHelper.StObjMap.StObjs.Obtain <TimedUserTable>();
            var      userTable   = TestHelper.StObjMap.StObjs.Obtain <CustomUserTable>();
            var      timePeriod  = TestHelper.StObjMap.StObjs.Obtain <TimePeriodTable>();
            var      group       = TestHelper.StObjMap.StObjs.Obtain <CustomGroupTable>();
            var      sqlDatabase = TestHelper.StObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            DateTime dateTime    = DateTime.Now;
            DateTime dateTime2   = DateTime.Now.AddDays(1);

            using (var ctx = new SqlStandardCallContext())
            {
                //CaseIsAdmin

                TimedUserQueries timedUserQueries = new TimedUserQueries(ctx, sqlDatabase);
                var userId = await userTable.CreateUserAsync(ctx, 1, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

                var id = await timePeriod.CreateTimePeriodAsync(ctx, 1, dateTime, dateTime2, "S", 4);

                TimedUserStruct TimedUserResult = await userTimed.CreateOrUpdateTimedUserAsync(ctx, 2, id, userId);

                var groupId = await group.CreateGroupAsync(ctx, userId, id);

                await group.Naming.GroupRenameAsync(ctx, 1, groupId, "Administration");

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

                bool boolResult = await timedUserQueries.VerifyUserInSpecificGroup(TimedUserResult.TimedUserId, "Administration");

                Assert.That(boolResult == true);

                //CaseIsNotAdmin

                userId = await userTable.CreateUserAsync(ctx, 1, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

                TimedUserResult = await userTimed.CreateOrUpdateTimedUserAsync(ctx, 1, id, userId);

                boolResult = await timedUserQueries.VerifyUserInSpecificGroup(TimedUserResult.TimedUserId, "Administration");

                Assert.That(boolResult == false);
            }
        }
Пример #4
0
        public async Task insert_user()
        {
            var userTable      = TestHelper.StObjMap.StObjs.Obtain <CustomUserTable>();
            var userTimed      = TestHelper.StObjMap.StObjs.Obtain <TimedUserTable>();
            var school         = TestHelper.StObjMap.StObjs.Obtain <SchoolTable>();
            var group          = TestHelper.StObjMap.StObjs.Obtain <GroupTable>();
            var projectStudent = TestHelper.StObjMap.StObjs.Obtain <ProjectStudentTable>();

            var timePeriod  = TestHelper.StObjMap.StObjs.Obtain <TimePeriodTable>();
            var sqlDatabase = TestHelper.StObjMap.StObjs.Obtain <SqlDefaultDatabase>();

            DateTime dateTime  = DateTime.Now;
            DateTime dateTime2 = DateTime.Now.AddDays(1);

            using (var ctx = new SqlStandardCallContext())
            {
                TimedUserQueries timedUserQueries = new TimedUserQueries(ctx, sqlDatabase);
                //3 is the id of Intech
                var id = await timePeriod.CreateTimePeriodAsync(ctx, 1, dateTime, dateTime2, "S", 3);

                List <TimedUserStruct> timedStudents     = new List <TimedUserStruct>();
                List <TimedUserStruct> timedStaffMembers = new List <TimedUserStruct>();
                List <TimedUserStruct> timedJurys        = new List <TimedUserStruct>();
                await create_zone();

                for (int i = 0; i < 100; i++)
                {
                    int userType;

                    string userName  = Guid.NewGuid().ToString();
                    string firstName = "Prenom: " + Guid.NewGuid();
                    string lastName  = "Nom de famille: " + Guid.NewGuid();
                    string logo      = "Logo: " + Guid.NewGuid();
                    string slogan    = "Slogan " + Guid.NewGuid();
                    string pitch     = "Pitch " + Guid.NewGuid();

                    var userid = userTable.CreateUser(ctx, 1, userName, firstName, lastName);

                    if (i < 25)
                    {
                        userType = 0;
                        await userTimed.CreateOrUpdateTimedUserAsync(ctx, userType, id, userid);

                        group.AddUser(ctx, 1, 5, userid, true);
                    }
                    else if (i < 50)
                    {
                        userType = 1;
                        TimedUserStruct timedStudent = await userTimed.CreateOrUpdateTimedUserAsync(ctx, userType, id, userid);

                        timedStudents.Add(timedStudent);
                        var ProjectCreate = await projectStudent.CreateProjectStudent(ctx, 1, 2, "name", 1, "a;b;c", logo, slogan, pitch, 1, "I");

                        group.AddUser(ctx, 1, 6, userid, true);
                    }

                    else if (i < 75)
                    {
                        userType = 2;
                        TimedUserStruct timedStaffMember = await userTimed.CreateOrUpdateTimedUserAsync(ctx, userType, id, userid);

                        timedStaffMembers.Add(timedStaffMember);
                        group.AddUser(ctx, 1, 7, userid, true);
                    }
                    else if (i < 100)
                    {
                        userType = 3;
                        TimedUserStruct timedJury = await userTimed.CreateOrUpdateTimedUserAsync(ctx, userType, id, userid);

                        timedJurys.Add(timedJury);
                        group.AddUser(ctx, 1, 8, userid, true);
                    }
                }
            }
        }
Пример #5
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());
            }
        }