Beispiel #1
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;
            }
        }