Example #1
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));
            }
        }
Example #2
0
        public async Task <List <string> > GetGroupUserAccessPanel(int idZone)
        {
            List <string> listGroupToReturn = new List <string>();
            int           userId            = _authenticationInfo.ActualUser.UserId;
            var           sqlDataBase       = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>();

            if (userId == 0)
            {
                listGroupToReturn.Add("Anon");
                return(listGroupToReturn);
            }

            listGroupToReturn.Add("User");

            using (var ctx = new SqlStandardCallContext())
            {
                TimedPeriodQueries timedPeriod   = new TimedPeriodQueries(ctx, sqlDataBase);
                TimedUserQueries   timedUser     = new TimedUserQueries(ctx, sqlDataBase);
                GroupQueries       groupsQueries = new GroupQueries(ctx, sqlDataBase);
                UserQueries        userQueries   = new UserQueries(ctx, sqlDataBase);
                DateTime           dateNow       = DateTime.UtcNow;
                List <PeriodData>  periods       = await timedPeriod.GetNumberWishPeriodBySchool(idZone, 2);

                PeriodData period = null;


                for (int i = 0; i < periods.Count; i++)
                {
                    if (periods[i].BegDate.DayOfYear <= dateNow.DayOfYear && periods[i].EndDate.DayOfYear >= dateNow.DayOfYear)
                    {
                        period = periods[i];
                        break;
                    }
                }

                if (period == null)
                {
                    period = periods[0];
                }
                TimedUserData timedUserData = await timedUser.GetTimedUser(userId, period.ChildId);

                if (timedUserData == null)
                {
                    int adminIdZoneSchool = await groupsQueries.GetSpecificIdGroupByZoneIdAndGroupName(idZone, "Administration");

                    if (await userQueries.VerifyGroupUser(userId, adminIdZoneSchool) != 0)
                    {
                        listGroupToReturn.Add("Administration");
                    }

                    return(listGroupToReturn);
                }

                listGroupToReturn = await timedUser.getWhichCat(timedUserData.TimedUserId, listGroupToReturn);

                if (!listGroupToReturn.Contains("StaffMember"))
                {
                    return(listGroupToReturn);
                }

                List <string> listGroupsOfTimedUser = new List <string>();

                listGroupsOfTimedUser = await groupsQueries.GetAllGroupOfTimedUserByPeriod(period.ChildId, timedUserData.TimedUserId);

                for (int i = 0; i < listGroupsOfTimedUser.Count; i++)
                {
                    if (listGroupsOfTimedUser[i] == "Administration")
                    {
                        listGroupToReturn.Add("Administration");
                    }
                    else if (listGroupsOfTimedUser[i] == "Teacher")
                    {
                        listGroupToReturn.Add("Teacher");
                    }
                }

                if (!listGroupToReturn.Contains("Administration"))
                {
                    int adminIdZoneSchool = await groupsQueries.GetSpecificIdGroupByZoneIdAndGroupName(idZone, "Administration");

                    if (await userQueries.VerifyGroupUser(userId, adminIdZoneSchool) != 0)
                    {
                        listGroupToReturn.Add("Administration");
                    }
                }


                return(listGroupToReturn);
            }
        }