private void RemoveRepairHistory_OnClick(object sender, RoutedEventArgs e)
        {
            using (var dbContext = new DatabaseContext())
            {
                try
                {
                    var lastRepair = dbContext.Repair.Where(x => x.AssetId == SelectedAsset.Id)
                                     .OrderByDescending(x => x.AddedDate).First();
                    dbContext.Remove(lastRepair);
                    dbContext.SaveChanges();
                    RepairsList.RemoveAt(RepairsList.Count - 1);

                    MessageBox.Show("Asset Repair Deleted", "Done");
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    MessageBox.Show("Error Deleting Asset repair");
                }
            }
        }
        private void FillTheUi()
        {
            RepairsList.Clear();
            RepositionsList.Clear();
            using (var dbContext = new DatabaseContext())
            {
                try
                {
                    SelectedAsset = dbContext.Assets.Where(x =>
                                                           x.AssetId == SelectedAssetDto.AssetId && x.AssetNumber == SelectedAssetDto.AssetNumber).First();
                    foreach (var rep in dbContext.Repair.Where(x => x.AssetId == SelectedAsset.Id)
                             .OrderByDescending(x => x.RepairDate).ToList())
                    {
                        RepairsList.Add(new RepairDto(rep));
                    }
                    RepairGrid.ItemsSource = RepairsList;

                    foreach (var rep in dbContext.Repositions.Where(x => x.AssetId == SelectedAsset.Id)
                             .OrderByDescending(x => x.AddedDate).ToList())
                    {
                        RepositionsList.Add(new RepositionDto(rep));
                    }
                    RepositionHistory.ItemsSource = RepositionsList;

                    if (SelectedAsset == null)
                    {
                        MessageBox.Show("Invalid selected Asset", "Error");
                        return;
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    MessageBox.Show("Error Loading Assets ");
                }
            }

            if (SelectedAsset == null)
            {
                return;
            }
            AssetIdBox.Text                   = SelectedAsset.AssetId;
            PMVCodeBox.Text                   = SelectedAsset.PMVCode;
            AssetNumberBox.Text               = SelectedAsset.AssetNumber;
            PoNumberBox.Text                  = SelectedAsset.PoNumber;
            AssetNameBox.Text                 = SelectedAsset.AssetName;
            PlateSerialNumberBox.Text         = SelectedAsset.PlateSerialNumber;
            DateOfPurchasePicker.SelectedDate = SelectedAsset.DateOfPurchase;
            CostOfAssetBox.Text               = SelectedAsset.PurchaseCostOfAsset.ToString(CultureInfo.InvariantCulture);
            ToolTypeBox.Text                  = SelectedAsset.ToolType;
            MonthsToDepreciationBox.Text      = SelectedAsset.MonthsToDepreciation.ToString();
            StatusPicker.SelectedIndex        = ComboboxSource.IndexOf(SelectedAsset.AssetStatus.ToString());
            CalibrationCertificationDatePicker.SelectedDate = SelectedAsset.CalibrationCertificationDate;
            CalibrationCertificationNumberBox.Text          = SelectedAsset.CalibrationCertificationNumber;
            var netBookValue = SelectedAsset.PurchaseCostOfAsset -
                               SelectedAsset.PurchaseCostOfAsset / SelectedAsset.MonthsToDepreciation *
                               (DateTime.Today.Month - SelectedAsset.DateOfPurchase.Month + 1);

            netBookValue         = Math.Round(netBookValue, 3);
            NetBookValueBox.Text = netBookValue.ToString(CultureInfo.InvariantCulture);
            if (netBookValue > 0.0)
            {
                var mon = SelectedAsset.PurchaseCostOfAsset / SelectedAsset.MonthsToDepreciation;
                mon = Math.Round(mon, 3);
                MonthlyDepreciationDueDateBox.Text = mon.ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                MonthlyDepreciationDueDateBox.Text = 1.ToString();
            }

            Application.Current.Properties[Constants.ShouldAssetDetailsRefresh] = false;
        }