Beispiel #1
0
 static async Task AddSpeaker(AddSpeaker obj)
 {
     var                 json                = JsonConvert.SerializeObject(obj);
     var                 httpContent         = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
     HttpClient          client              = new HttpClient();
     HttpResponseMessage httpResponseMessage = await client.PostAsync("http://localhost:2794/Speaker/AddSpeaker", httpContent);
 }
Beispiel #2
0
        private async Task SendToQueue(AddSpeaker command, CancellationToken cancellationToken)
        {
            // Get the connection string from app settings
            string connectionString = this.configuration["Speakers:StorageAccount"];
            string queueName        = this.configuration["Speakers:CommandQueueName"];

            var serializedCommand = JsonSerializer.Serialize(command);

            var queueClient = new QueueClient(connectionString, queueName);

            if (await queueClient.ExistsAsync(cancellationToken))
            {
                await queueClient.SendMessageAsync(
                    Base64Encode(serializedCommand),
                    cancellationToken);
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Add(SpeakerInformation speakerInformation, CancellationToken cancellationToken)
        {
            this.logger.LogInformation($"Executing {nameof(Add)}.");
            var command = new AddSpeaker
            {
                Id        = Guid.NewGuid(),
                FirstName = speakerInformation.FirstName,
                LastName  = speakerInformation.LastName,
                Level     = speakerInformation.Level
            };

            // Send the command to the queue
            await SendToQueue(command, cancellationToken);

            this.logger.LogInformation($"Executed {nameof(Add)}.");
            return(Accepted(command.Id));
        }
        private static async Task EmitEvent(IAsyncCollector <Event> outputCollector, AddSpeaker deserializedCommand)
        {
            // Specify some meta data of the message you want to publish to Event Grid
            var myTestEvent = new Event
            {
                EventType = "SecureApi.Speaker.SpeakerAdded",
                Subject   = "New Speaker",
                Data      = new SpeakerAdded
                {
                    Id        = deserializedCommand.Id,
                    FirstName = deserializedCommand.FirstName,
                    LastName  = deserializedCommand.LastName
                },
                DataVersion = "1.0"
            };

            // Add the event to the IAsyncCollector<T> in order to get your event published.
            await outputCollector.AddAsync(myTestEvent);
        }
Beispiel #5
0
        private async void BtnSave_ClickAsync(object sender, EventArgs e)
        {
            if (EditOrSave == false)
            {
                if (dictionar == "DictionaryCountry")
                {
                    try {
                        AddCountry obj = new AddCountry
                        {
                            Code = textBox1.Text,
                            Name = textBox2.Text
                        }; await AddCountry(obj);
                    }
                    catch
                    {
                        SetBalloonTip("Already Exists", "There is a Country with this name");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }

                    form4.RefreshLists("DictionaryCountry");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "Speaker")
                {
                    try
                    {
                        AddSpeaker obj = new AddSpeaker
                        {
                            Email       = textBox1.Text,
                            Name        = textBox2.Text,
                            Nationality = textBox3.Text
                        }; await AddSpeaker(obj);
                    }
                    catch
                    {
                        SetBalloonTip("Already Exists", "There is a Speaker with this name");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("Speaker");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryCounty")
                {
                    try
                    {
                        AddCounty obj = new AddCounty
                        {
                            Code    = textBox1.Text,
                            Name    = textBox2.Text,
                            country = DetailEvent.DictionaryCountryId.ToString()
                        }; await AddCounty(obj);
                    }
                    catch {
                        SetBalloonTip("Already Exists", "There is a County with this name");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryCounty");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryCity")
                {
                    try
                    {
                        AddCity obj = new AddCity
                        {
                            Code   = textBox1.Text,
                            Name   = textBox2.Text,
                            county = DetailEvent.DictionaryCountyId.ToString()
                        }; await AddCity(obj);
                    }
                    catch
                    {
                        SetBalloonTip("Already Exists", "There is a City with this name");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryCity");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryCategory")
                {
                    try { await AddCategory(textBox2.Text); }
                    catch {
                        SetBalloonTip("Already Exists", "There is a Category with this name");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryCategory");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryType")
                {
                    try
                    {
                        AddType obj = new AddType
                        {
                            Name     = textBox2.Text,
                            isRemote = checkBox1.Checked
                        }; await AddType(obj);
                    }
                    catch {
                        SetBalloonTip("Already Exists", "There is a Type with this name");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryType");
                    form4.Enabled = true;
                    this.Close();
                }
            }
            else if (EditOrSave == true)
            {
                if (dictionar == "DictionaryCountry")
                {
                    try {
                        EditCountry obj = new EditCountry {
                            Id   = DetailEvent.DictionaryCountryId,
                            Code = textBox1.Text,
                            Name = textBox2.Text
                        }; await EditCountry(obj);
                    }
                    catch {
                        SetBalloonTip("Already Exists", "There is a Country with this name");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryCountry");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "Speaker")
                {
                    try {
                        EditSpeaker obj = new EditSpeaker {
                            Name        = textBox2.Text,
                            Email       = textBox1.Text,
                            Id          = DetailEvent.SpeakerId,
                            Nationality = textBox3.Text
                        };
                        await EditSpeaker(obj);
                    }
                    catch {
                        SetBalloonTip("Please insert a valid mail", "Invalid Email");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("Speaker");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryCounty")
                {
                    try
                    {
                        EditCounty obj = new EditCounty
                        {
                            Id   = DetailEvent.DictionaryCountyId,
                            Name = textBox2.Text,
                            Code = textBox1.Text
                        }; await EditCounty(obj);
                    }

                    catch {
                        SetBalloonTip("Error", "There was a problem");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryCounty");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryCity")
                {
                    try
                    {
                        EditCity obj = new EditCity
                        {
                            Name = textBox2.Text,
                            Code = textBox1.Text,
                            Id   = DetailEvent.DictionaryCityId
                        };
                        await EditCity(obj);
                    }
                    catch {
                        SetBalloonTip("Error", "There was a problem");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryCity");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryCategory")
                {
                    try { EditCategory obj = new EditCategory {
                              id   = DetailEvent.DictionaryConferenceCategoryId,
                              Name = textBox2.Text
                          };
                          await EditCategory(obj); }
                    catch {
                        SetBalloonTip("Error", "There was a problem");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryCategory");
                    form4.Enabled = true;
                    this.Close();
                }
                else if (dictionar == "DictionaryType")
                {
                    try { EditType obj = new EditType {
                              Name     = textBox2.Text,
                              id       = DetailEvent.ConferenceTypeId,
                              isRemote = checkBox1.Checked
                          }; await EditType(obj); }
                    catch {
                        SetBalloonTip("Error", "There was a problem");
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(3000);
                    }
                    form4.RefreshLists("DictionaryType");
                    form4.Enabled = true;
                    this.Close();
                }
            }
        }
 public IActionResult AddSpeaker([FromBody] AddSpeaker obj)
 {
     _speakerrepository.AddSpeaker(obj.Email, obj.Name, obj.Nationality);
     return(Ok());
 }