Skip to content

Commit

Permalink
#14 removing server
Browse files Browse the repository at this point in the history
  • Loading branch information
tym32167 committed May 7, 2016
1 parent 243f872 commit 06092fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
13 changes: 9 additions & 4 deletions src/Arma3BE.Client.Libs/Repositories/ServerInfoRepository.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Arma3BEClient.Common.Core;
using Arma3BEClient.Libs.Context;
using Arma3BEClient.Libs.ModelCompact;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using Arma3BEClient.Common.Core;
using Arma3BEClient.Libs.Context;
using Arma3BEClient.Libs.ModelCompact;

namespace Arma3BEClient.Libs.Repositories
{
Expand Down Expand Up @@ -60,7 +60,12 @@ public void Remove(Guid serverInfoId)
{
using (var dc = new Arma3BeClientContext())
{
dc.ServerInfo.RemoveRange(dc.ServerInfo.Where(x=>x.Id == serverInfoId));
dc.ChatLog.RemoveRange(dc.ChatLog.Where(x => x.ServerId == serverInfoId));
dc.Bans.RemoveRange(dc.Bans.Where(x => x.ServerId == serverInfoId));
dc.PlayerHistory.RemoveRange(dc.PlayerHistory.Where(x => x.ServerId == serverInfoId));
dc.Admins.RemoveRange(dc.Admins.Where(x => x.ServerId == serverInfoId));

dc.ServerInfo.RemoveRange(dc.ServerInfo.Where(x => x.Id == serverInfoId));
dc.SaveChanges();
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Arma3BE.Client/Options.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
xmlns:viewModel="clr-namespace:Arma3BEClient.ViewModel"
Title="Options" WindowStartupLocation="CenterScreen" Height="600" Width="800"
WindowStyle="ToolWindow">

<xctk:BusyIndicator IsBusy="False" BusyContent="Saving changes..." Name="BusyIndicator">

<Grid>

<Grid.RowDefinitions>
Expand All @@ -19,7 +22,6 @@
ItemsSource="{Binding Servers}"
ItemAdded="ServerAdded" ItemDeleted="ServerDeleted"
ItemsSourceType="viewModel:ServerInfoModel"
ItemDeleting="ServerDeleting"
NewItemTypes="{Binding NewListItemTypes}" />
</Grid>
</TabItem>
Expand Down Expand Up @@ -49,4 +51,5 @@
</StackPanel>

</Grid>
</xctk:BusyIndicator>
</Window>
37 changes: 16 additions & 21 deletions src/Arma3BE.Client/Options.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Linq;
using Arma3BEClient.ViewModel;
using System;
using System.Threading.Tasks;
using System.Windows;
using Arma3BEClient.Libs.Repositories;
using Arma3BEClient.ViewModel;
using Xceed.Wpf.AvalonDock.Layout;
using Xceed.Wpf.Toolkit;

namespace Arma3BEClient
Expand Down Expand Up @@ -41,25 +39,22 @@ private void ServerAdded(object sender, ItemEventArgs e)
_optionsModel.Servers.Add(e.Item as ServerInfoModel);
}

private void ServerDeleting(object sender, ItemDeletingEventArgs e)
private void Save_Click(object sender, RoutedEventArgs e)
{
var model = e.Item as ServerInfoModel;
var dbm = model.GetDbModel();
if (dbm.Id != Guid.Empty)
BusyIndicator.IsBusy = true;
var t = Task.Factory.StartNew(() =>
{
using (var chat = new ChatRepository())
{
if (chat.HaveChatLogs(dbm.Id)) e.Cancel = true;

}

}
}
_optionsModel.Save();
});

private void Save_Click(object sender, RoutedEventArgs e)
{
_optionsModel.Save();
Close();
t.ContinueWith((p) =>
{
Dispatcher.Invoke(() =>
{
BusyIndicator.IsBusy = false;
Close();
});
});
}

private void Cancel_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 06092fb

Please sign in to comment.