示例#1
0
        //Add on focusLost event to all phone number input fields, validate phone numbers are not in between acceptable values. 5, 7, 11, if they are remove
        // the excess characters and warn the user with a label.

        private void phoneLostFocus(object sender, RoutedEventArgs e)
        {
            TextBox phone  = sender as TextBox;
            bool    office = phone.Name.Equals("office");
            bool    cell   = phone.Name.Equals("cell");
            bool    home   = phone.Name.Equals("home");

            if (PhoneConverter.FilterNonNumeric(phone.Text).Length > 7 && PhoneConverter.FilterNonNumeric(phone.Text).Length < 10)
            {
                phone.Text = phone.Text.Remove(6);

                //remove any pre-existing labels
                phoneLabelManager(office, cell, home, phone, "", false);
                //Add new label with new text
                phoneLabelManager(office, cell, home, phone, "The " + phone.Name + " phone is to short, last characters will be removed to make it fit a valid format.", true);
            }
            else if (PhoneConverter.FilterNonNumeric(phone.Text).Length < 7 && !PhoneConverter.FilterNonNumeric(phone.Text).Equals(""))
            {
                //remove any pre-existing labels
                phoneLabelManager(office, cell, home, phone, "", false);
                //Add new label with new text
                phoneLabelManager(office, cell, home, phone, "The " + phone.Name + " phone is to short, please check that the phone number is at least 5 digits in length.", true);
            }
            else if (PhoneConverter.FilterNonNumeric(phone.Text).Length == 5 ||
                     PhoneConverter.FilterNonNumeric(phone.Text).Length == 7 ||
                     PhoneConverter.FilterNonNumeric(phone.Text).Length == 11 ||
                     PhoneConverter.FilterNonNumeric(phone.Text).Equals(""))
            {
                //calling labelManager to remove the labels that were added when the phone number is valid.
                phoneLabelManager(office, cell, home, phone, "", false);
            }
        }
示例#2
0
        public List <Contact> SearchByPhoneNumber(string lookup)
        {
            List <Contact> result = new List <Contact>();

            foreach (var c in _contactStore)
            {
                if (c.CellPhone != null)
                {
                    if (c.CellPhone.StartsWith(PhoneConverter.FilterNonNumeric(lookup)))
                    {
                        result.Add(c);
                    }
                }
                else if (c.OfficePhone != null)
                {
                    if (c.OfficePhone.StartsWith(PhoneConverter.FilterNonNumeric(lookup)))
                    {
                        result.Add(c);
                    }
                }
                else if (c.HomePhone != null)
                {
                    if (c.HomePhone.StartsWith(PhoneConverter.FilterNonNumeric(lookup)))
                    {
                        result.Add(c);
                    }
                }
            }

            return(result);
        }
示例#3
0
        public async Task <IActionResult> RegisterDevice(RegisterDeviceInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest());
            }

            var number = PhoneConverter.Convert(model.OwnerNumber);
            var result = await UserModel.RegNewUser(number, model.Password, model.DeviceId);

            return(result ? Ok() : new HttpStatusCodeResult(500));
        }
示例#4
0
        private void phoneNumberTextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox text = sender as TextBox;

            PhoneConverter converter = new PhoneConverter();

            if (converter.CheckNumericLength(text.Text))
            {
                text.Text = text.Text.Remove(text.Text.Length - 1);
            }

            text.CaretIndex = text.Text.Length;
        }
示例#5
0
        private async void OnSendCommand(object obj)
        {
            SendWindow.IsEnabled = false;
            var api = GetApi();

            var msg = new SingleMessageSms();

            msg.From = (string)PhoneConverter.ConvertBack(this.Sender);
            msg.To   = (string)PhoneConverter.ConvertBack(this.Receiver);
            msg.Msg  = this.Message;

            try
            {
                var response = await api.SendSms(msg);

                if (response.StatusCode.Equals("00"))
                {
                    MessageBox.Show($"Mensagem enviada com sucesso [{response.DetailCode}]!");
                    var msgs = new MessageModel(msg);
                    DBContext.Messages.Add(msgs);
                    DBContext.SaveChanges();
                    this.Messages.Add(msgs);
                }
                else
                {
                    MessageBox.Show($"Falha ao enviar: [{response.StatusCode}] {response.StatusDescription} \n[{response.DetailCode}] {response.DetailDescription}");
                }
                SendWindow.Close();

                this.Sender   = string.Empty;
                this.Receiver = string.Empty;
                this.Message  = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Falha ao enviar: {ex.Message}");
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                SendWindow.IsEnabled = true;
            }
        }
示例#6
0
        public async Task <IActionResult> LoginByPhone(LoginByPhoneInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest());
            }

            var  number = PhoneConverter.Convert(model.PhoneNumber);
            bool result = await UserModel.LoginByPhone(number, model.Password);

            if (result)
            {
                var token = Guid.NewGuid().ToString();
                SessionsService.AddSession(number, token);
                return(Json(new LoginOutputModel {
                    AuthorizationToken = token, Expired = DateTimeOffset.Now.AddDays(1)
                }));
            }

            return(HttpNotFound());
        }