Ejemplo n.º 1
0
        /// <summary>
        /// Creates the user to the database
        /// </summary>
        /// <param name="viewModel">The form of the model that was used</param>
        /// <returns>True if successful save, false if not.</returns>
        public bool Create(AccountViewModel viewModel)
        {
            if (viewModel != null)
            {
                ApplyChanges(viewModel);

                // Verify we can create the user
                Model.Salt       = HashManager.GetSalt();
                Model.Password   = HashManager.HashPassword(viewModel.Password, Model.Salt);
                Model.CreatedOn  = DateTime.Now;
                Model.InviteCode = Codes.GenerateInviteCode();

                bool usernameExists = services.Account.AccountEmailExists(viewModel.Username);
                bool emailExists    = services.Account.AccountEmailExists(viewModel.Email);
                bool passwordsMatch = viewModel.Password == viewModel.PasswordVerify;


                if (!usernameExists && !emailExists && passwordsMatch)
                {
                    services.Account.AddAccount(Model);
                    return(services.Save());
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        //TODO: Fix issue where tournamentCodes can collide and be repeatable.
        public bool Create(TournamentViewModel viewModel, Account account)
        {
            ApplyChanges(viewModel);
            // Exit the create if we detect there is an exception in the viewModel.
            if (viewModel.e != null)
            {
                SetupViewModel(viewModel);
                return(false);
            }

            Model.LastEditedOn   = DateTime.Now;
            Model.LastEditedByID = account.Model.AccountID;
            Model.CreatedOn      = DateTime.Now;
            Model.CreatedByID    = account.Model.AccountID;

            // Generate the Tournament Invite Codes
            Model.InviteCode = Codes.GenerateInviteCode();

            //Save the tournament First.
            services.Tournament.AddTournament(Model);
            AddUser(account, Permission.TOURNAMENT_CREATOR);
            //if (viewModel.BracketData != null) UpdateBrackets();
            bool tournamentSave = services.Save();

            // Create InviteModel
            TournamentInviteModel inviteModel = new TournamentInviteModel()
            {
                TournamentInviteCode = Model.InviteCode,
                DateCreated          = DateTime.Now,
                TournamentID         = Model.TournamentID,
                NumberOfUses         = 0
            };

            // Add the Invite Model

            services.Tournament.AddTournamentInvite(inviteModel);
            bool TournamentInviteSave = services.Save();

            return(tournamentSave && TournamentInviteSave);
        }