//Loads the data for the Users at the MainMenu
    public void LoadUsers()
    {
        if (File.Exists(Application.persistentDataPath + "/UsernameMenuInfo.dat"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/UsernameMenuInfo.dat", FileMode.Open);
            MenuData        data = (MenuData)bf.Deserialize(file);
            file.Close();

            createUser.listOfTypeUSERS = data.Users;
            //createUser.listOfUsers = data.userNames;
            createUser.usernameNumb    = data.usernameNumb;
            createUser.layer           = data.layer;
            createUser.userNumbTracker = data.usernameTracker;
            createUser.tempLayer       = data.tempLayer;

            int tempPlacement = 0;
            for (int j = 0; j < data.usernameTracker; j++)
            {
                if (tempPlacement == 5)
                {
                    tempPlacement = 0;
                }

                createUser.CreateUser(tempPlacement);
                createUser.NameUser(data.Users[j].getPlayerName());
                createUser.listOfUsers[j].GetComponent <CanvasGroup>().alpha = 1;
                createUser.currUser.name = data.Users[j].getPlayerName();

                tempPlacement++;
            }

            flipPage.De_ActivateUsers();
        }
    }
Beispiel #2
0
        public async Task <User> AddNewUserAsync(CreateNewUser userData)
        {
            var manager = await GetUserAsync(userData.ManagingUserId);

            if (manager == null)
            {
                throw new NotFoundException($"Manager with id ({userData.ManagingUserId}) does not exist");
            }

            var userWithEmail = await _schedulearnContext.Users.Where(user => user.Email == userData.Email.ToLower()).FirstOrDefaultAsync();

            if (userWithEmail != null)
            {
                throw new UniqueConstraintViolatedException("User with this email already exists");
            }

            User newUser = userData.CreateUser();

            if (manager.ManagedTeam == null)
            {
                var newTeam = await _teamService.AddNewTeamAsync
                              (
                    new CreateNewTeam()
                {
                    ManagerId = manager.Id,
                    LimitId   = manager.Team?.LimitId ?? manager.LimitId.Value
                }
                              );

                newUser.TeamId = newTeam.Id;
            }
            else
            {
                newUser.TeamId = manager.ManagedTeam.Id;
            }

            Guid newUserGuid = Guid.NewGuid();

            newUser.RegistrationGuid = newUserGuid;

            var link = Regex.Replace(userData.RegisterAddress, "{GUID}", newUserGuid.ToString());

            await _schedulearnContext.Users.AddAsync(newUser);

            await _schedulearnContext.SaveChangesAsync();

            await _emailService.SendRegistrationEmail(newUser.Email, newUser.Name, manager.Name, link);

            return(newUser);
        }