Пример #1
0
        public bool CanExecuteSaveAddedContactCommand()
        {
            if (string.IsNullOrEmpty(this.AddedContactId))
            {
                this.CurrentError = "The XDS ID is required.";
                return(false);
            }

            var regex = new Regex("^[A-Za-z0-9]+$");

            if (!regex.IsMatch(this.AddedContactId))
            {
                this.CurrentError = "Use only latin letters and numbers";
                return(false);
            }

            if (this.AddedContactId.Length < 13)
            {
                this.CurrentError = "This XDS ID is too short!";
                return(false);
            }
            if (this.AddedContactId.Length > 14)
            {
                this.CurrentError = "This XDS ID is too long!";
                return(false);
            }

            // TODO: Verify Base64 Chars
            if (this.contactListManager.Contacts.Count(c => c.ChatId == this.AddedContactId) > 0)
            {
                this.CurrentError = "This contact already exists.";
                return(false);
            }

            if (this.profileViewModel.ChatId == this.AddedContactId)
            {
                this.CurrentError = "You cannot add yourself.";
                return(false);
            }

            try
            {
                ChatId.DecodeChatId(this.AddedContactId);
            }
            catch (InvalidDataException ae)
            {
                this.CurrentError = ae.Message;
                return(false);
            }
            this.CurrentError = "Looks good!";
            return(true);
        }