Exemplo n.º 1
0
        public static async Task <(UserQueries, TimedUserQueries, ProjectStudentStruct, TimedUserData)> SaveProjectPi(
            ProjectPi project,
            ProjectStudentTable projectTable,
            int userId,
            SqlDefaultDatabase db,
            SqlStandardCallContext ctx,
            string type,
            ProjectUrlTable projectUrlTable,
            CustomGroupTable CustomGroupTable
            )
        {
            GroupQueries        groupQueries       = new GroupQueries(ctx, db);
            TraitContextQueries traitContext       = new TraitContextQueries(ctx, db);
            TimedUserQueries    timedUserQueries   = new TimedUserQueries(ctx, db);
            TimedPeriodQueries  timedPeriodQueries = new TimedPeriodQueries(ctx, db);
            UserQueries         userQueries        = new UserQueries(ctx, db);

            GroupData school = await groupQueries.GetIdSchoolByConnectUser(userId);

            // PeriodData timePeriod = await timedPeriodQueries.GetLastPeriodBySchool(school.ZoneId);
            TimedUserData timedUser = await timedUserQueries.GetTimedUser(userId, school.ZoneId);

            int traitContextId = await traitContext.GetTraitContextId(type);

            string email = project.team.leader;
            int    leaderId;

            if (email == "None")
            {
                leaderId = 0;
            }
            else
            {
                UserData user = await userQueries.GetUserByEmail(email);

                TimedUserData timedLeader = await timedUserQueries.GetTimedUser(user.UserId, school.ZoneId);

                leaderId = user.UserId;
            }


            ProjectStudentStruct ProjectCreate = await projectTable.CreateProjectStudent(
                ctx,
                userId,
                school.ZoneId,
                project.name.project_name,
                traitContextId,
                string.Join(";", project.technologies.technologies),
                project.logo.url,
                project.slogan.slogan,
                project.pitch.pitch,
                leaderId,
                type
                );

            if (project.git.url != "None")
            {
                await projectUrlTable.CreateOrUpdateProjectUrl(ctx, ProjectCreate.ProjectStudentId, project.git.url, "Git");
            }

            foreach (var item in project.semester.semester)
            {
                string semester   = "S0" + item.ToString();
                int    idSemester = await groupQueries.GetSpecificIdGroupByZoneIdAndGroupName(school.ZoneId, semester);

                await CustomGroupTable.AddUserAsync(ctx, userId, idSemester, ProjectCreate.ProjectStudentId, true);
            }

            string[] sector = project.semester.sector.Split(" - ");
            foreach (var item in sector)
            {
                int idSector = await groupQueries.GetSpecificIdGroupByZoneIdAndGroupName(school.ZoneId, item);

                await CustomGroupTable.AddUserAsync(ctx, userId, idSector, ProjectCreate.ProjectStudentId, true);
            }


            return(userQueries, timedUserQueries, ProjectCreate, timedUser);
        }
Exemplo n.º 2
0
        public static async Task <(UserQueries, TimedUserQueries, ProjectStudentStruct, TimedUserData)> SaveProjectPfh(
            ProjectPfh project,
            ProjectStudentTable projectTable,
            int userId,
            SqlDefaultDatabase db,
            SqlStandardCallContext ctx,
            string type,
            ProjectUrlTable projectUrlTable,
            CustomGroupTable CustomGroupTable
            )
        {
            GroupQueries        groupQueries       = new GroupQueries(ctx, db);
            TraitContextQueries traitContext       = new TraitContextQueries(ctx, db);
            TimedUserQueries    timedUserQueries   = new TimedUserQueries(ctx, db);
            TimedPeriodQueries  timedPeriodQueries = new TimedPeriodQueries(ctx, db);
            UserQueries         userQueries        = new UserQueries(ctx, db);

            GroupData school = await groupQueries.GetIdSchoolByConnectUser(userId);

            // PeriodData timePeriod = await timedPeriodQueries.GetLastPeriodBySchool(school.ZoneId);
            TimedUserData timedUser = await timedUserQueries.GetTimedUser(userId, school.ZoneId);

            int traitContextId = await traitContext.GetTraitContextId(type);

            string email = project.team.leader;
            int    leaderId;

            if (email == "None")
            {
                leaderId = 0;
            }
            else
            {
                UserData user = await userQueries.GetUserByEmail(email);

                TimedUserData timedLeader = await timedUserQueries.GetTimedUser(user.UserId, school.ZoneId);

                leaderId = user.UserId;
            }

            project.background.image = GetTomlFromGoogleDrive.GetUrlRessource(project.background.image);

            ProjectStudentStruct ProjectCreate = await projectTable.CreateProjectStudent(
                ctx,
                userId,
                school.ZoneId,
                project.name.project_name,
                traitContextId,
                project.logo.url,
                project.slogan.slogan,
                project.pitch.pitch,
                leaderId,
                type,
                project.background.image
                );

            foreach (var item in project.semester.semester)
            {
                string semester   = "S0" + item.ToString();
                int    idSemester = await groupQueries.GetSpecificIdGroupByZoneIdAndGroupName(school.ZoneId, semester);

                await CustomGroupTable.AddUserAsync(ctx, userId, idSemester, ProjectCreate.ProjectStudentId, true);
            }


            return(userQueries, timedUserQueries, ProjectCreate, timedUser);
        }