コード例 #1
0
    public void SaveUser(User user)
    {
        int      userID      = user.ID;
        DateTime createDate  = user.CreatedOn;
        DateTime updateDate  = DateTime.Now;
        long     phoneNumber = PhoneNumberConverter.Parse(user.PhoneNumber);

        using (TransactionScope tsc = new TransactionScope())
        {
            if (user.ID == 0)
            {
                createDate = updateDate;
                userID     = db.InsertUser(user.Name, phoneNumber, createDate,
                                           updateDate);
            }
            else
            {
                db.UpdateUser(user.ID, user.Name, phoneNumber, updateDate);
            }
            tsc.Complete();
        }
        user.ID           = userID;
        user.CreatedOn    = createDate;
        user.LastModified = updateDate;
    }
コード例 #2
0
        /// <summary>
        /// Will refresh the data for the currently selected person
        /// in family members list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RefreshFamilyButton_Click(object sender, RoutedEventArgs e)
        {
            CACCCheckInDb.PeopleWithDepartmentAndClassView person = null;

            if (null != PeopleDetail.DataContext)
            {
                CACCCheckInDb.PeopleWithDepartmentAndClassView currentPerson =
                    (CACCCheckInDb.PeopleWithDepartmentAndClassView)PeopleDetail.DataContext;

                person = ((List <CACCCheckInDb.PeopleWithDepartmentAndClassView>)
                          _familyView.SourceCollection).Find(p => p.PersonId.Equals(currentPerson.PersonId));
            }

            PhoneNumberConverter cvt = new PhoneNumberConverter();

            if (null != person)
            {
                person.FirstName   = FirstName.Text;
                person.LastName    = LastName.Text;
                person.PhoneNumber = (string)cvt.ConvertBack(PhoneNumber.Text,
                                                             typeof(string), null, null);
                person.SpecialConditions = SpecialConditions.Text;
                person.DepartmentId      = ((CACCCheckInDb.Department)DepartmentComboBox.SelectedItem).Id;
                person.DepartmentName    = ((CACCCheckInDb.Department)DepartmentComboBox.SelectedItem).Name;
                person.ClassId           = ((CACCCheckInDb.Class)ClassComboBox.SelectedItem).Id;
                person.ClassName         = ((CACCCheckInDb.Class)ClassComboBox.SelectedItem).Name;
                person.FamilyRole        = (string)FamilyRole.SelectedItem;

                _familyView.Refresh();
            }
        }
コード例 #3
0
        public AddPersonPage()
        {
            _PhoneNumberItems = new ObservableCollection<PhoneNumberGridItem>();
            _PhoneNumberConverter = new PhoneNumberConverter();

            InitializeComponent();
        }
        internal void Validate()
        {
            var format = TextBoxValidationExtensions.GetFormat(_textBox);

            var expectNonEmpty = format.HasFlag(ValidTextBoxFormats.NonEmpty);
            var isEmpty        = String.IsNullOrWhiteSpace(_textBox.Text);

            if (expectNonEmpty && isEmpty)
            {
                MarkInvalid();
                return;
            }

            var expectNumber = format.HasFlag(ValidTextBoxFormats.Numeric);

            if (expectNumber &&
                !isEmpty &&
                !IsNumeric())
            {
                MarkInvalid();
                return;
            }

            var expectPhone = format.HasFlag(ValidTextBoxFormats.Phone);

            if (expectPhone)
            {
                if (!isEmpty)
                {
                    IEnumerable <string> phones = PhoneNumbersInputParser.Parse(_textBox.Text);

                    string convertedNumber = String.Empty;
                    bool   isValid         = phones.All(number => PhoneNumberConverter.ConvertToIsdn(number, ref convertedNumber));

                    if (isValid)
                    {
                        MarkValid();
                    }
                    else
                    {
                        MarkInvalid();
                    }
                }
                else
                {
                    MarkInvalid();
                }

                return;
            }

            MarkValid();
        }
コード例 #5
0
        /// <summary>
        /// Validates phone number on ISDN format
        /// </summary>
        /// <param name="phoneNumber">phone number to validate</param>
        /// <returns>false if the phone number cannot be converted to ISDN format</returns>
        public static bool Validate(string phoneNumber)
        {
            Argument.ExpectNotNullOrWhiteSpace(() => phoneNumber);

            try
            {
                PhoneNumberConverter.ConvertToIsdn(phoneNumber);
                return(true);
            }
            catch (ArgumentException)
            {
                return(false);
            }
        }
コード例 #6
0
        public async Task OnPost()
        {
            Message.From = "+46723499120";

            var numberConvert = new PhoneNumberConverter();

            var roles = _roleManager.Roles.Where(a => a.Name == Message.ListType);

            var smslist = new List <PremiseContact>();


            if (Message.ListType != "User")
            {
                var users = await(from user in _userManager.Users
                                  join userRoles in _userManager.UserRoles on user.Id equals userRoles.UserId
                                  join role in _userManager.Roles on userRoles.RoleId equals role.Id
                                  where role.Name == Message.ListType
                                  select new { UserId = user.Id, UserName = user.UserName, RoleId = role.Id, RoleName = role.Name })
                            .ToListAsync();

                foreach (var item in users)
                {
                    var temp = await _context.PremiseContacts
                               .Where(a => a.IsDeleted == false && a.IsActive == true && a.WantInfoSMS == true && a.Email == item.UserName)
                               .FirstOrDefaultAsync();

                    if (temp != null)
                    {
                        smslist.Add(temp);
                    }
                }
            }
            else
            {
                smslist = _context.PremiseContacts.Where(a => a.IsDeleted == false && a.IsActive == true && a.WantInfoSMS == true).ToList();
            }


            foreach (var sms in smslist)
            {
                var message = MessageResource.Create(
                    to: new PhoneNumber(numberConvert.ConvertPhoneNumber(sms.MobileNumber)),
                    from: new PhoneNumber(Message.From),
                    body: Message.Message,
                    client: _client); // pass in the custom client
            }
        }
コード例 #7
0
        private string GetSubtitle()
        {
            if (_type is TLSentCodeTypeApp)
            {
                return(AppResources.CodeSentToTelegramApp);
            }

            if (_type is TLSentCodeTypeSms)
            {
                return(string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber)));
            }

            if (_type is TLSentCodeTypeCall)
            {
                return(string.Format(AppResources.CodeSentViaCallingPhone, PhoneNumberConverter.Convert(StateService.PhoneNumber)));
            }

            return(string.Empty);
        }
コード例 #8
0
        public void VerifyPhoneNumberTest()
        {
            // Arrange
            var phoneNumber = new PhoneNumberConverter();

            // Act
            var match1 = phoneNumber.ConvertPhoneNumber("0734435407");
            var match2 = phoneNumber.ConvertPhoneNumber("0734 435 407");
            var match3 = phoneNumber.ConvertPhoneNumber("0734-435407");
            var match4 = phoneNumber.ConvertPhoneNumber("46734-435407");
            var match5 = phoneNumber.ConvertPhoneNumber("+46734-435407");
            var match6 = phoneNumber.ConvertPhoneNumber("+460734-435407");


            // Assert
            Assert.AreEqual(match1, match2);
            Assert.AreEqual("+46734435407", match1);
            Assert.AreEqual("+46734435407", match3);
            Assert.AreEqual("+46734435407", match4);
            Assert.AreEqual("+46734435407", match5);
            Assert.AreEqual("+46734435407", match6);
        }
コード例 #9
0
        /// <summary>
        /// Will add the current person to the family members list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddToFamilyButton_Click(object sender, RoutedEventArgs e)
        {
            Guid?currentFamilyId;

            if (null != PeopleDetail.DataContext)
            {
                CACCCheckInDb.PeopleWithDepartmentAndClassView currentPerson =
                    (CACCCheckInDb.PeopleWithDepartmentAndClassView)PeopleDetail.DataContext;
                currentFamilyId = currentPerson.FamilyId;
            }
            else
            {
                currentFamilyId = Guid.NewGuid();
            }

            PhoneNumberConverter cvt = new PhoneNumberConverter();

            CACCCheckInDb.PeopleWithDepartmentAndClassView person =
                new CACCCheckInDb.PeopleWithDepartmentAndClassView();
            person.PersonId    = Guid.NewGuid();
            person.FirstName   = FirstName.Text;
            person.LastName    = LastName.Text;
            person.PhoneNumber = (string)cvt.ConvertBack(PhoneNumber.Text,
                                                         typeof(string), null, null);
            person.SpecialConditions = SpecialConditions.Text;
            person.DepartmentId      = ((CACCCheckInDb.Department)DepartmentComboBox.SelectedItem).Id;
            person.DepartmentName    = ((CACCCheckInDb.Department)DepartmentComboBox.SelectedItem).Name;
            person.ClassId           = ((CACCCheckInDb.Class)ClassComboBox.SelectedItem).Id;
            person.ClassName         = ((CACCCheckInDb.Class)ClassComboBox.SelectedItem).Name;
            person.ClassRole         = ClassRoles.Member;
            person.FamilyId          = currentFamilyId;
            person.FamilyRole        = (string)FamilyRole.SelectedItem;

            _familyMembers.Add(person);
            PeopleDetail.DataContext = person;
            _familyView.Refresh();
        }
コード例 #10
0
        /// <summary>
        /// Sends the SMS message.
        /// </summary>
        /// <param name="phoneNumbers">Phone numbers to send SMS message to.</param>
        /// <param name="message">Message body to send.</param>
        /// <returns>Instance of <see cref="SmsResponse"/> with sent SMS response information.</returns>
        /// <exception cref="System.ArgumentNullException">phoneNumbers is null.</exception>
        /// <exception cref="System.ArgumentException">phoneNumbers count equals zero.</exception>
        public async Task <SmsResponse> SendSms(IEnumerable <string> phoneNumbers, string message)
        {
            Argument.ExpectNotNull(() => phoneNumbers);
            Argument.Expect(() => phoneNumbers.Any(), "phoneNumbers", "at least one phone number required");

            List <string> isdnAddresses = phoneNumbers
                                          .Select(a => PhoneNumberConverter.ConvertToIsdn(a))
                                          .ToList();

            var body = String.Empty;

            if (isdnAddresses.Count == 1)
            {
                var raw = new OutboundSmsRaw(isdnAddresses[0], message);
                body = JsonParser <OutboundSmsRaw> .SerializeToJson(raw);
            }
            else
            {
                var numbers = new OutboundSms(isdnAddresses, message);
                body = JsonParser <OutboundSms> .SerializeToJson(numbers);
            }

            return(SmsResponse.Parse(await SendRawRequest(HttpMethod.Post, SendRelativeUrl, body)));
        }
コード例 #11
0
        private void ChangePhoneNumber()
        {
            IsWorking = true;
            NotifyOfPropertyChange(() => CanSignIn);
            var phoneNumber = PhoneCode + PhoneNumber;

            _startTime = DateTime.Now;
            _showHelpTimer.Start();
            MTProtoService.SendChangePhoneCodeAsync(new TLString(phoneNumber),
                                                    sentCode => BeginOnUIThread(() =>
            {
                _showHelpTimer.Stop();
                StateService.PhoneNumber       = new TLString(phoneNumber);
                StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber));

                StateService.PhoneCodeHash     = sentCode.PhoneCodeHash;
                StateService.PhoneRegistered   = new TLBool(false);
                StateService.SendCallTimeout   = sentCode.SendCodeTimeout;
                StateService.ChangePhoneNumber = true;

                NavigationService.UriFor <ConfirmViewModel>().Navigate();

                IsWorking = false;
                NotifyOfPropertyChange(() => CanSignIn);
            }),
                                                    error => BeginOnUIThread(() =>
            {
                _lastError = error;

                IsWorking = false;
                NotifyOfPropertyChange(() => CanSignIn);

                if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                {
                    MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.PHONE_NUMBER_OCCUPIED))
                {
                    MessageBox.Show(string.Format(AppResources.NewNumberTaken, "+" + phoneNumber), AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.CodeEquals(ErrorCode.FLOOD))
                {
                    MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK);
                }
                else
                {
                    Execute.ShowDebugMessage("account.sendChangePhoneCode error " + error);
                }
            }));
        }
コード例 #12
0
        public void SignIn()
        {
            if (_changePhoneNumber)
            {
                ChangePhoneNumber();
                return;
            }

#if LOG_REGISTRATION
            TLUtils.WriteLog("auth.sendCode");
#endif

            IsWorking = true;
            NotifyOfPropertyChange(() => CanSignIn);

            var phoneNumber = PhoneCode + PhoneNumber;
            _startTime = DateTime.Now;
            _showHelpTimer.Start();

            MTProtoService.SendCodeAsync(new TLString(phoneNumber), TLSmsType.Code,
                                         sentCode => BeginOnUIThread(() =>
            {
#if LOG_REGISTRATION
                TLUtils.WriteLog("auth.sendCode result: " + sentCode);
#endif
                _sentCode = sentCode;

                _showHelpTimer.Stop();
                StateService.PhoneNumber       = new TLString(phoneNumber);
                StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber));
                StateService.PhoneCodeHash     = sentCode.PhoneCodeHash;
                StateService.PhoneRegistered   = sentCode.PhoneRegistered;
                StateService.SendCallTimeout   = sentCode.SendCallTimeout;

                NavigationService.UriFor <ConfirmViewModel>().Navigate();
                IsWorking = false;
                NotifyOfPropertyChange(() => CanSignIn);
            }),
                                         attemptNumber => BeginOnUIThread(() =>
            {
#if LOG_REGISTRATION
                TLUtils.WriteLog("auth.sendCode attempt failed " + attemptNumber);
#endif
                Execute.ShowDebugMessage("auth.sendCode attempt failed " + attemptNumber);
            }),
                                         error => BeginOnUIThread(() =>
            {
#if LOG_REGISTRATION
                TLUtils.WriteLog("auth.sendCode error " + error);
#endif

                _lastError = error;
                IsWorking  = false;
                NotifyOfPropertyChange(() => CanSignIn);

                if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                {
                    MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.CodeEquals(ErrorCode.FLOOD))
                {
                    MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK);
                }
                else
                {
                    Execute.ShowDebugMessage("auth.sendCode error " + error);
                }
            }));
        }
コード例 #13
0
        private void SavePhoneAsync(TLString phone)
        {
            var phoneNumberValue = _phoneNumberValue;

            if (phoneNumberValue == null)
            {
                var secureRequiredType = _secureRequiredType != null ? _secureRequiredType.DataRequiredType as TLSecureRequiredType : null;
                var secureType         = secureRequiredType != null && IsValidType(secureRequiredType.Type)
                    ? secureRequiredType.Type
                    : null;

                // add new phone number from passport settings
                if (_secureType != null && IsValidType(_secureType))
                {
                    phoneNumberValue = new TLSecureValue85
                    {
                        Flags = new TLInt(0),
                        Type  = _secureType
                    };
                }
                // add new phone number from authorization form
                else if (secureType != null)
                {
                    phoneNumberValue = new TLSecureValue85
                    {
                        Flags = new TLInt(0),
                        Type  = secureType
                    };
                }
                else
                {
                    return;
                }
            }

            IsWorking =
                SavePhoneAsync(
                    phone, _passwordBase as TLPassword, MTProtoService,
                    result => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;
                if (_authorizationForm != null)
                {
                    _authorizationForm.Values.Remove(phoneNumberValue);
                    _authorizationForm.Values.Add(result);
                }

                phoneNumberValue.Update(result);
                phoneNumberValue.NotifyOfPropertyChange(() => phoneNumberValue.Self);

                if (_secureType != null)
                {
                    EventAggregator.Publish(new AddSecureValueEventArgs {
                        Values = new List <TLSecureValue> {
                            phoneNumberValue
                        }
                    });
                }

                if (_secureRequiredType != null)
                {
                    _secureRequiredType.UpdateValue();
                }

                NavigationService.GoBack();
            }),
                    error => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;

                if (error.CodeEquals(ErrorCode.BAD_REQUEST) &&
                    error.TypeEquals(ErrorType.PHONE_VERIFICATION_NEEDED))
                {
                    MTProtoService.SendVerifyPhoneCodeAsync(phone, null,
                                                            result2 => BeginOnUIThread(() =>
                    {
                        StateService.PhoneNumber       = phone;
                        StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber));
                        StateService.PhoneCodeHash     = result2.PhoneCodeHash;
                        StateService.PhoneRegistered   = result2.PhoneRegistered;
                        StateService.SendCallTimeout   = result2.SendCallTimeout;
                        var sentCode50 = result2 as TLSentCode50;
                        if (sentCode50 != null)
                        {
                            StateService.Type     = sentCode50.Type;
                            StateService.NextType = sentCode50.NextType;
                        }
                        StateService.Password           = _passwordBase;
                        StateService.AuthorizationForm  = _authorizationForm;
                        StateService.SecureValues       = _secureValues;
                        StateService.SecureType         = _secureType;
                        StateService.SecureRequiredType = _secureRequiredType;
                        NavigationService.UriFor <PhoneNumberCodeViewModel>().Navigate();
                    }),
                                                            error2 => BeginOnUIThread(() =>
                    {
                        if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                        {
                            ShellViewModel.ShowCustomMessageBox(AppResources.PhoneNumberInvalidString, AppResources.Error, AppResources.Ok);
                        }
                        else if (error.CodeEquals(ErrorCode.FLOOD))
                        {
                            ShellViewModel.ShowCustomMessageBox(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, AppResources.Ok);
                        }
                        else
                        {
                            Telegram.Api.Helpers.Execute.ShowDebugMessage("account.sendVerifyPhoneCode error " + error);
                        }
                    }));
                }
                else if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.PhoneNumberInvalidString, AppResources.Error, AppResources.Ok);
                }
                else if (error.CodeEquals(ErrorCode.BAD_REQUEST))
                {
                    ShellViewModel.ShowCustomMessageBox(
                        "account.saveSecureValue" + Environment.NewLine + error.Message,
                        AppResources.AppName,
                        AppResources.Ok);
                }
            }));
        }
コード例 #14
0
        /// <summary>
        /// Sends new MMS message.
        /// </summary>
        /// <param name="phoneNumbers">Phone numbers to send MMS message to.</param>
        /// <param name="message">Message body to send.</param>
        /// <param name="attachments">List of files attached to MMS.</param>
        /// <param name="priority">MMS priority.</param>
        /// <returns>Instance of <see cref="MmsResponse"/> with sent MMS response information.</returns>
        /// <exception cref="System.ArgumentNullException">Throws exception when the message is null.</exception>
        public async Task <MmsResponse> SendMms(IEnumerable <string> phoneNumbers, string message, IEnumerable <Windows.Storage.StorageFile> attachments, MmsPriority priority = MmsPriority.Normal)
        {
            Argument.ExpectNotNullOrWhiteSpace(() => message);
            Argument.ExpectNotNull(() => phoneNumbers);
            Argument.Expect(() => phoneNumbers.Any(), "phoneNumbers", "at least one phone number is required");

            var attachList = attachments == null
                                                                ? null
                                                                : attachments.ToList();

            var sb = new StringBuilder();

            foreach (string pn in phoneNumbers)
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "Address={0}&", Uri.EscapeUriString(PhoneNumberConverter.ConvertToIsdn(pn)));
            }

            return(await SendMms(sb.ToString(), message, attachList, priority));
        }
コード例 #15
0
 /// <summary>
 /// Convert phone number to ISDN format.  Removes dashes, removes "+" from country code, etc.
 /// </summary>
 /// <param name="numberToConvert">Phone number to convert.</param>
 /// <returns>Converted phone number.</returns>
 /// <exception cref="System.ArgumentNullException">numberToConvert is null.</exception>
 /// <exception cref="System.ArgumentException">numberToConvert is in incorrect format</exception>
 public static string ConvertToIsdn(string numberToConvert)
 {
     return(PhoneNumberConverter.ConvertToIsdn(numberToConvert));
 }
コード例 #16
0
        public void PhoneNumberNullTest()
        {
            var phoneNumber = new PhoneNumberConverter();

            Assert.IsNotNull(phoneNumber);
        }