132 lines
4.0 KiB
C#
132 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
using BreCalClient.misc.Api;
|
|
using BreCalClient.misc.Client;
|
|
using BreCalClient.misc.Model;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
DefaultApi _api;
|
|
ObservableCollection<ShipcallControlModel> _controlModels = new();
|
|
List<Ship> _ships = new();
|
|
Dictionary<int, Ship> _shipLookupDict = new();
|
|
List<Berth> _berths = new();
|
|
Dictionary<int, Berth> _berthLookupDict = new();
|
|
List<Participant> _participants = new();
|
|
Dictionary<int, Participant> _participantLookupDict = new();
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
_api = new DefaultApi();
|
|
_api.Configuration.ApiKeyPrefix["Authorization"] = "Bearer";
|
|
}
|
|
|
|
#region event handler
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private async void buttonLogin_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(this.textPassword.Password) || string.IsNullOrEmpty(this.textUsername.Text))
|
|
{
|
|
this.labelLoginResult.Content = Application.Current.FindResource("textUserNamePasswordEmpty").ToString();
|
|
return;
|
|
}
|
|
|
|
Credentials credentials = new(username: textUsername.Text.Trim(),
|
|
password: textPassword.Password.Trim());
|
|
|
|
try
|
|
{
|
|
LoginResult loginResult = await _api.LoginPostAsync(credentials);
|
|
if(loginResult != null)
|
|
{
|
|
if(loginResult.Id > 0)
|
|
{
|
|
this.busyIndicator.IsBusy = false;
|
|
this._api.Configuration.ApiKey["Authorization"] = loginResult.Token;
|
|
this.LoadStaticLists();
|
|
}
|
|
}
|
|
}
|
|
catch (ApiException ex)
|
|
{
|
|
this.labelLoginResult.Content = ex.Message;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void buttonExit_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private methods
|
|
|
|
private async void LoadStaticLists()
|
|
{
|
|
this._berths = await _api.BerthsGetAsync();
|
|
foreach(var berth in this._berths)
|
|
_berthLookupDict[berth.Id] = berth;
|
|
this._ships = await _api.ShipsGetAsync();
|
|
foreach(var ship in this._ships)
|
|
_shipLookupDict[ship.Id] = ship;
|
|
// this._participants = await _api.ParticipantGetAsync();
|
|
}
|
|
|
|
private async void RefreshShipcalls()
|
|
{
|
|
List<Shipcall> shipcalls = await _api.ShipcallsGetAsync(0); // TODO: this must return all current calls
|
|
foreach(Shipcall shipcall in shipcalls)
|
|
{
|
|
|
|
|
|
// TODO: find out if we already have this thing
|
|
|
|
// yes: update values
|
|
|
|
// no: create new entry
|
|
ShipcallControlModel scm = new ShipcallControlModel();
|
|
scm.Shipcall = shipcall;
|
|
if(this._shipLookupDict.ContainsKey(shipcall.Id))
|
|
scm.Ship = this._shipLookupDict[shipcall.Id];
|
|
_controlModels.Add(scm);
|
|
|
|
// TODO: sort this list somehow
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|