Example #1
0
 public void DistrictControllerTest_Post_Delete()
 {
     Task.Run(async() =>
     {
         var district = new District()
         {
             Name = "Norway",
             PrimarySalesperson = new Salesperson()
             {
                 Id       = 5,
                 Name     = "zzz",
                 LastName = "xxx"
             }
         };
         var p        = await controller.GetAllAsync();
         int countOld = p.Count();
         await controller.PersistAsync(district);
         p            = await controller.GetAllAsync();
         int countNew = p.Count();
         Assert.AreNotEqual(countOld, countNew);
         int id = p.ToList().SingleOrDefault(x => { return(x.Name.Equals(district.Name) && x.PrimarySalesperson.Id.Equals(district.PrimarySalesperson.Id)); }).Id;
         await controller.DeleteAsync(id);
         p        = await controller.GetAllAsync();
         countNew = p.Count();
         Assert.AreEqual(countOld, countNew);
     }).GetAwaiter().GetResult();
 }
        private async void DeleteSelected_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show($"Are you sure you want to to delete district {SelectedDistrict.Name}?",
                                                      "Delete operation",
                                                      MessageBoxButton.YesNo,
                                                      MessageBoxImage.Question);

            if (result.Equals(MessageBoxResult.Yes))
            {
                try
                {
                    await districtContext.DeleteAsync(SelectedDistrict.Id);
                }
                catch (ApiException ex)
                {
                    MessageBox.Show(ex.Message, "API Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    LoadDistricts();
                }
            }
        }