Beispiel #1
0
    /// <summary>
    /// Validates form.
    /// </summary>
    private void OnBeforeValidate(object sender, EventArgs e)
    {
        int      selectedCMSUserId = ValidationHelper.GetInteger(Control.GetFieldValue("ChatUserUserID"), 0);
        UserInfo user     = UserInfoProvider.GetUserInfo(selectedCMSUserId);
        string   nickname = Control.GetFieldValue("ChatUserNickname") as string;

        // Validate form - user and nickname fields must be filled
        if ((user == null) || (String.IsNullOrWhiteSpace(nickname)))
        {
            ShowErrorAndStopProcessing("chat.user.erroridnickname");

            return;
        }

        if (user.IsPublic())
        {
            ShowErrorAndStopProcessing("chat.cantassociatechatusertopublic");

            return;
        }

        // Creating a new object
        if (Control.IsInsertMode)
        {
            // Check if userID is unique in ChatUser table if adding a new user
            if (ChatUserInfoProvider.GetChatUserByUserID(selectedCMSUserId) != null)
            {
                ShowErrorAndStopProcessing("chat.user.erroridunique");

                return;
            }
        }

        // Check nickname only if text has been changed
        ChatUserInfo editedChatUser = Control.EditedObject as ChatUserInfo;

        if (Control.IsInsertMode || (nickname != editedChatUser.ChatUserNickname))
        {
            try
            {
                ChatUserHelper.VerifyNicknameIsValid(ref nickname);
            }
            catch (ChatServiceException ex)
            {
                ShowErrorAndStopProcessing(ex.StatusMessage);

                return;
            }


            // Check if Nickname is unique in registered users
            if (!ChatUserHelper.IsNicknameAvailable(nickname))
            {
                ShowErrorAndStopProcessing("chat.user.errornickunique");

                return;
            }
        }
    }
Beispiel #2
0
    protected void UIFormOnOnBeforeValidate(object sender, EventArgs e)
    {
        int selectedCMSUserId = ValidationHelper.GetInteger(fUserSelector.Value, 0);

        UserInfo user = UserInfoProvider.GetUserInfo(selectedCMSUserId);

        // Validate form - both fields must be filled
        if ((user == null) || (fNickname.EditingControl.Text == ""))
        {
            ShowErrorAndStopProcessing("chat.user.erroridnickname");
            return;
        }

        if (user.IsPublic())
        {
            ShowErrorAndStopProcessing("chat.cantassociatechatusertopublic");
            return;
        }


        // Editing
        if (TypedEditedObject != null)
        {
            if (!TypedEditedObject.ChatUserUserID.HasValue)
            {
                ShowErrorAndStopProcessing("chat.user.cannoteditanonymoususer");
                return;
            }
        }
        else
        {
            // New object

            // Check if userID is unique in ChatUser table if adding a new user
            if (ChatUserInfoProvider.GetChatUserByUserID(selectedCMSUserId) != null)
            {
                ShowErrorAndStopProcessing("chat.user.erroridunique");
                return;
            }
        }

        string newNickname = fNickname.EditingControl.Text;

        // Check nickname only if text has been changed
        if ((TypedEditedObject == null) || (newNickname != TypedEditedObject.ChatUserNickname))
        {
            try
            {
                ChatUserHelper.VerifyNicknameIsValid(ref newNickname);
            }
            catch (ChatServiceException ex)
            {
                ShowErrorAndStopProcessing(ex.StatusMessage);
                return;
            }


            // Check if Nickname is unique in registered users
            if (!ChatUserHelper.IsNicknameAvailable(newNickname))
            {
                ShowErrorAndStopProcessing("chat.user.errornickunique");
                return;
            }
        }

        fNickname.EditingControl.Text = newNickname;
    }