diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs index 7fa07c4..b5be32b 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs @@ -64,9 +64,15 @@ namespace LaDOSE.Api.Controllers } [HttpGet("CreateChallonge/{gameId:int}/{wpEventId:int}")] - public bool CreateChallonge(int gameId, int wpEventId) + public string CreateChallonge(int gameId, int wpEventId) { - return _service.CreateChallonge(gameId, wpEventId); + return _service.CreateChallonge(gameId, wpEventId,null); + } + + [HttpPost("CreateChallonge/{gameId:int}/{wpEventId:int}")] + public string CreateChallonge(int gameId, int wpEventId, [FromBody]List additionalPlayer) + { + return _service.CreateChallonge(gameId, wpEventId, additionalPlayer); } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs b/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs index f5f547e..5b08cfe 100644 --- a/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs +++ b/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs @@ -14,18 +14,4 @@ namespace LaDOSE.DTO public DateTime? Date { get; set; } public List WpBookings { get; set; } } - - public class WPBooking - { - public WPUser WpUser { get; set; } - public string Message { get; set; } - - public string Meta { get; set; } - } - - public class WPUser - { - public string Name { get; set; } - } - } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DTO/WPUser.cs b/LaDOSE.Src/LaDOSE.DTO/WPUser.cs new file mode 100644 index 0000000..85b305f --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DTO/WPUser.cs @@ -0,0 +1,8 @@ +namespace LaDOSE.DTO +{ + public class WPUser + { + public string Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs b/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs new file mode 100644 index 0000000..c2ced85 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs @@ -0,0 +1,11 @@ +namespace LaDOSE.DTO +{ + public class WPBooking + { + public WPUser WpUser { get; set; } + public string Message { get; set; } + + public string Meta { get; set; } + } + +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml index 09ab519..5b6efc4 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml @@ -8,7 +8,7 @@ - + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Behaviors/MultiSelectorBehaviours.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Behaviors/MultiSelectorBehaviours.cs new file mode 100644 index 0000000..fe81b4d --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Behaviors/MultiSelectorBehaviours.cs @@ -0,0 +1,418 @@ +using System; +using System.Collections; +using System.Collections.Specialized; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; + +namespace LaDOSE.DesktopApp.Behaviors +{ + /// + /// A sync behaviour for a multiselector. + /// + public static class MultiSelectorBehaviours + { + public static readonly DependencyProperty SynchronizedSelectedItems = DependencyProperty.RegisterAttached( + "SynchronizedSelectedItems", typeof(IList), typeof(MultiSelectorBehaviours), new PropertyMetadata(null, OnSynchronizedSelectedItemsChanged)); + + private static readonly DependencyProperty SynchronizationManagerProperty = DependencyProperty.RegisterAttached( + "SynchronizationManager", typeof(SynchronizationManager), typeof(MultiSelectorBehaviours), new PropertyMetadata(null)); + + /// + /// Gets the synchronized selected items. + /// + /// The dependency object. + /// The list that is acting as the sync list. + public static IList GetSynchronizedSelectedItems(DependencyObject dependencyObject) + { + return (IList)dependencyObject.GetValue(SynchronizedSelectedItems); + } + + /// + /// Sets the synchronized selected items. + /// + /// The dependency object. + /// The value to be set as synchronized items. + public static void SetSynchronizedSelectedItems(DependencyObject dependencyObject, IList value) + { + dependencyObject.SetValue(SynchronizedSelectedItems, value); + } + + private static SynchronizationManager GetSynchronizationManager(DependencyObject dependencyObject) + { + return (SynchronizationManager)dependencyObject.GetValue(SynchronizationManagerProperty); + } + + private static void SetSynchronizationManager(DependencyObject dependencyObject, SynchronizationManager value) + { + dependencyObject.SetValue(SynchronizationManagerProperty, value); + } + + private static void OnSynchronizedSelectedItemsChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + { + if (e.OldValue != null) + { + SynchronizationManager synchronizer = GetSynchronizationManager(dependencyObject); + synchronizer.StopSynchronizing(); + + SetSynchronizationManager(dependencyObject, null); + } + + IList list = e.NewValue as IList; + Selector selector = dependencyObject as Selector; + + // check that this property is an IList, and that it is being set on a ListBox + if (list != null && selector != null) + { + SynchronizationManager synchronizer = GetSynchronizationManager(dependencyObject); + if (synchronizer == null) + { + synchronizer = new SynchronizationManager(selector); + SetSynchronizationManager(dependencyObject, synchronizer); + } + + synchronizer.StartSynchronizingList(); + } + } + + /// + /// A synchronization manager. + /// + private class SynchronizationManager + { + private readonly Selector _multiSelector; + private TwoListSynchronizer _synchronizer; + + /// + /// Initializes a new instance of the class. + /// + /// The selector. + internal SynchronizationManager(Selector selector) + { + _multiSelector = selector; + } + + /// + /// Starts synchronizing the list. + /// + public void StartSynchronizingList() + { + IList list = GetSynchronizedSelectedItems(_multiSelector); + + if (list != null) + { + _synchronizer = new TwoListSynchronizer(GetSelectedItemsCollection(_multiSelector), list); + _synchronizer.StartSynchronizing(); + } + } + + /// + /// Stops synchronizing the list. + /// + public void StopSynchronizing() + { + _synchronizer.StopSynchronizing(); + } + + public static IList GetSelectedItemsCollection(Selector selector) + { + if (selector is MultiSelector) + { + return (selector as MultiSelector).SelectedItems; + } + else if (selector is ListBox) + { + return (selector as ListBox).SelectedItems; + } + else + { + throw new InvalidOperationException("Target object has no SelectedItems property to bind."); + } + } + + } + } + + + public class TwoListSynchronizer : IWeakEventListener + { + private static readonly IListItemConverter DefaultConverter = new DoNothingListItemConverter(); + private readonly IList _masterList; + private readonly IListItemConverter _masterTargetConverter; + private readonly IList _targetList; + + + /// + /// Initializes a new instance of the class. + /// + /// The master list. + /// The target list. + /// The master-target converter. + public TwoListSynchronizer(IList masterList, IList targetList, IListItemConverter masterTargetConverter) + { + _masterList = masterList; + _targetList = targetList; + _masterTargetConverter = masterTargetConverter; + } + + /// + /// Initializes a new instance of the class. + /// + /// The master list. + /// The target list. + public TwoListSynchronizer(IList masterList, IList targetList) + : this(masterList, targetList, DefaultConverter) + { + } + + private delegate void ChangeListAction(IList list, NotifyCollectionChangedEventArgs e, Converter converter); + + /// + /// Starts synchronizing the lists. + /// + public void StartSynchronizing() + { + ListenForChangeEvents(_masterList); + ListenForChangeEvents(_targetList); + + // Update the Target list from the Master list + SetListValuesFromSource(_masterList, _targetList, ConvertFromMasterToTarget); + + // In some cases the target list might have its own view on which items should included: + // so update the master list from the target list + // (This is the case with a ListBox SelectedItems collection: only items from the ItemsSource can be included in SelectedItems) + if (!TargetAndMasterCollectionsAreEqual()) + { + SetListValuesFromSource(_targetList, _masterList, ConvertFromTargetToMaster); + } + } + + /// + /// Stop synchronizing the lists. + /// + public void StopSynchronizing() + { + StopListeningForChangeEvents(_masterList); + StopListeningForChangeEvents(_targetList); + } + + /// + /// Receives events from the centralized event manager. + /// + /// The type of the calling this method. + /// Object that originated the event. + /// Event data. + /// + /// true if the listener handled the event. It is considered an error by the handling in WPF to register a listener for an event that the listener does not handle. Regardless, the method should return false if it receives an event that it does not recognize or handle. + /// + public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) + { + HandleCollectionChanged(sender as IList, e as NotifyCollectionChangedEventArgs); + + return true; + } + + /// + /// Listens for change events on a list. + /// + /// The list to listen to. + protected void ListenForChangeEvents(IList list) + { + if (list is INotifyCollectionChanged) + { + CollectionChangedEventManager.AddListener(list as INotifyCollectionChanged, this); + } + } + + /// + /// Stops listening for change events. + /// + /// The list to stop listening to. + protected void StopListeningForChangeEvents(IList list) + { + if (list is INotifyCollectionChanged) + { + CollectionChangedEventManager.RemoveListener(list as INotifyCollectionChanged, this); + } + } + + private void AddItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + int itemCount = e.NewItems.Count; + + for (int i = 0; i < itemCount; i++) + { + int insertionPoint = e.NewStartingIndex + i; + + if (insertionPoint > list.Count) + { + list.Add(converter(e.NewItems[i])); + } + else + { + list.Insert(insertionPoint, converter(e.NewItems[i])); + } + } + } + + private object ConvertFromMasterToTarget(object masterListItem) + { + return _masterTargetConverter == null ? masterListItem : _masterTargetConverter.Convert(masterListItem); + } + + private object ConvertFromTargetToMaster(object targetListItem) + { + return _masterTargetConverter == null ? targetListItem : _masterTargetConverter.ConvertBack(targetListItem); + } + + private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + IList sourceList = sender as IList; + + switch (e.Action) + { + case NotifyCollectionChangedAction.Add: + PerformActionOnAllLists(AddItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Move: + PerformActionOnAllLists(MoveItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Remove: + PerformActionOnAllLists(RemoveItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Replace: + PerformActionOnAllLists(ReplaceItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Reset: + UpdateListsFromSource(sender as IList); + break; + default: + break; + } + } + + private void MoveItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + RemoveItems(list, e, converter); + AddItems(list, e, converter); + } + + private void PerformActionOnAllLists(ChangeListAction action, IList sourceList, NotifyCollectionChangedEventArgs collectionChangedArgs) + { + if (sourceList == _masterList) + { + PerformActionOnList(_targetList, action, collectionChangedArgs, ConvertFromMasterToTarget); + } + else + { + PerformActionOnList(_masterList, action, collectionChangedArgs, ConvertFromTargetToMaster); + } + } + + private void PerformActionOnList(IList list, ChangeListAction action, NotifyCollectionChangedEventArgs collectionChangedArgs, Converter converter) + { + StopListeningForChangeEvents(list); + action(list, collectionChangedArgs, converter); + ListenForChangeEvents(list); + } + + private void RemoveItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + int itemCount = e.OldItems.Count; + + // for the number of items being removed, remove the item from the Old Starting Index + // (this will cause following items to be shifted down to fill the hole). + for (int i = 0; i < itemCount; i++) + { + list.RemoveAt(e.OldStartingIndex); + } + } + + private void ReplaceItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + RemoveItems(list, e, converter); + AddItems(list, e, converter); + } + + private void SetListValuesFromSource(IList sourceList, IList targetList, Converter converter) + { + StopListeningForChangeEvents(targetList); + + targetList.Clear(); + + foreach (object o in sourceList) + { + targetList.Add(converter(o)); + } + + ListenForChangeEvents(targetList); + } + + private bool TargetAndMasterCollectionsAreEqual() + { + return _masterList.Cast().SequenceEqual(_targetList.Cast().Select(item => ConvertFromTargetToMaster(item))); + } + + /// + /// Makes sure that all synchronized lists have the same values as the source list. + /// + /// The source list. + private void UpdateListsFromSource(IList sourceList) + { + if (sourceList == _masterList) + { + SetListValuesFromSource(_masterList, _targetList, ConvertFromMasterToTarget); + } + else + { + SetListValuesFromSource(_targetList, _masterList, ConvertFromTargetToMaster); + } + } + + + + + /// + /// An implementation that does nothing in the conversions. + /// + internal class DoNothingListItemConverter : IListItemConverter + { + /// + /// Converts the specified master list item. + /// + /// The master list item. + /// The result of the conversion. + public object Convert(object masterListItem) + { + return masterListItem; + } + + /// + /// Converts the specified target list item. + /// + /// The target list item. + /// The result of the conversion. + public object ConvertBack(object targetListItem) + { + return targetListItem; + } + } + public interface IListItemConverter + { + /// + /// Converts the specified master list item. + /// + /// The master list item. + /// The result of the conversion. + object Convert(object masterListItem); + + /// + /// Converts the specified target list item. + /// + /// The target list item. + /// The result of the conversion. + object ConvertBack(object targetListItem); + } + } +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj index d72efd6..0c7e86a 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj +++ b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj @@ -8,12 +8,13 @@ WinExe LaDOSE.DesktopApp LaDOSE.DesktopApp - v4.6.1 + v4.6.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true true + AnyCPU @@ -50,7 +51,11 @@ + + + + ..\packages\Caliburn.Micro.3.2.0\lib\net45\System.Windows.Interactivity.dll @@ -72,6 +77,7 @@ MSBuild:Compile Designer + @@ -82,15 +88,19 @@ + + + WebNavigationView.xaml + ShellView.xaml GameView.xaml - - WpView.xaml + + WordPressView.xaml App.xaml @@ -100,6 +110,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -108,7 +122,7 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile @@ -148,8 +162,9 @@ LaDOSE.DTO + - + \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs index 5e8e560..62258ed 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace LaDOSE.DesktopApp.Properties -{ - - +namespace LaDOSE.DesktopApp.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,51 +19,43 @@ namespace LaDOSE.DesktopApp.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LaDOSE.DesktopApp.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs index ba88adf..e05364f 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs @@ -8,21 +8,17 @@ // //------------------------------------------------------------------------------ -namespace LaDOSE.DesktopApp.Properties -{ - - +namespace LaDOSE.DesktopApp.Properties { + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { + + public static Settings Default { + get { return defaultInstance; } } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Resources/64x64.png b/LaDOSE.Src/LaDOSE.DesktopApp/Resources/64x64.png new file mode 100644 index 0000000..e4e114c Binary files /dev/null and b/LaDOSE.Src/LaDOSE.DesktopApp/Resources/64x64.png differ diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs index d858414..f2f810f 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Configuration; using System.Windows; using LaDOSE.DTO; @@ -64,6 +65,31 @@ namespace LaDOSE.DesktopApp.Services } + } + private R Post(string resource, P entity) + { + var json = new RestSharp.Serialization.Json.JsonSerializer(); + var jsonD = new RestSharp.Serialization.Json.JsonDeserializer(); + var request = new RestRequest(); + request.Method = Method.POST; + request.Resource = resource; + request.AddHeader("Accept", "application/json"); + request.AddHeader("Content-type", "application/json"); + request.Parameters.Clear(); + request.AddParameter("application/json; charset=utf-8", json.Serialize(entity), ParameterType.RequestBody); + //request.AddObject(entity); + var response = Client.Execute(request); + //var content = response.Content; // raw content as string + try + { + return jsonD.Deserialize(response); + } + catch (Exception) + { + return default(R); + } + + } #endregion @@ -77,11 +103,17 @@ namespace LaDOSE.DesktopApp.Services } - public bool CreateChallonge(int gameId, int eventId) + public string CreateChallonge(int gameId, int eventId) { var restRequest = new RestRequest($"/api/wordpress/CreateChallonge/{gameId}/{eventId}", Method.GET); - var restResponse = Client.Get(restRequest); - return restResponse.Data; + var restResponse = Client.Get(restRequest); + return restResponse.Content; + } + public string CreateChallonge2(int gameId, int eventId, List optionalPlayers) + { + + var restResponse = Post,string>($"/api/wordpress/CreateChallonge/{gameId}/{eventId}",optionalPlayers); + return restResponse; } public bool RefreshDb() { diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs index 7cfdfc9..75ac9d6 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs @@ -16,6 +16,13 @@ namespace LaDOSE.DesktopApp.ViewModels { this.RestService = restService; this.Games=new List(); + + } + + protected override void OnInitialize() + { + LoadGames(); + base.OnInitialize(); } public void LoadGames() diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs index ae1f107..4b020cc 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs @@ -1,19 +1,29 @@ -using Caliburn.Micro; +using System; +using System.Windows; +using System.Windows.Media.Imaging; +using Caliburn.Micro; using LaDOSE.DesktopApp.Services; namespace LaDOSE.DesktopApp.ViewModels { public class ShellViewModel : Conductor.Collection.AllActive { + + protected override void OnInitialize() { + this.DisplayName = "LaDOSE"; + this.AppIcon = BitmapFrame.Create(Application.GetResourceStream(new Uri("/LaDOSE.DesktopApp;component/Resources/64x64.png", + UriKind.RelativeOrAbsolute)).Stream); var wordPressViewModel = new WordPressViewModel(IoC.Get()); ActivateItem(wordPressViewModel); base.OnInitialize(); - + } + public BitmapFrame AppIcon { get; set; } + public void LoadEvent() { ActivateItem(new WordPressViewModel(IoC.Get())); @@ -23,5 +33,9 @@ namespace LaDOSE.DesktopApp.ViewModels ActivateItem(new GameViewModel(IoC.Get())); } + public void OpenWeb() + { + ActivateItem(new WebNavigationViewModel("www.google.com")); + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WebNavigationViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WebNavigationViewModel.cs new file mode 100644 index 0000000..bc5767c --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WebNavigationViewModel.cs @@ -0,0 +1,15 @@ +using Caliburn.Micro; + +namespace LaDOSE.DesktopApp.ViewModels +{ + public class WebNavigationViewModel : Screen + { + public WebNavigationViewModel(string uri) + { + Uri = uri; + this.DisplayName = Uri; + } + + public string Uri { get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs index b75491e..3137fc6 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs @@ -22,7 +22,8 @@ namespace LaDOSE.DesktopApp.ViewModels private Game _selectedGame; private ObservableCollection _players; private ObservableCollection _playersOptions; - + private ObservableCollection _optionalPlayers; + private RestService RestService { get; set; } public WordPressViewModel(RestService restService) @@ -30,6 +31,121 @@ namespace LaDOSE.DesktopApp.ViewModels this.RestService = restService; Players = new ObservableCollection(); PlayersOptions = new ObservableCollection(); + OptionalPlayers = new ObservableCollection(); + } + + #region Auto Property + + protected override void OnInitialize() + { + base.OnInitialize(); + Task.Factory.StartNew(new Action(this.Load), TaskCreationOptions.LongRunning).ContinueWith(t => { }, + CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, + TaskScheduler.FromCurrentSynchronizationContext()); + } + + public bool CanGenerate + { + get { return SelectedWpEvent != null && SelectedGame != null && Players?.Count() > 0; } + } + + public List Events { get; set; } + + public WPEvent SelectedWpEvent + { + get => _selectedWpEvent; + set + { + _selectedWpEvent = value; + SelectedGame = null; + ParseGame(_selectedWpEvent); + } + } + + public Game SelectedGame + { + get => _selectedGame; + set + { + _selectedGame = value; + + Players.Clear(); + PlayersOptions.Clear(); + + Task.Factory.StartNew(LoadPlayers, TaskCreationOptions.LongRunning).ContinueWith(t => { }, + CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, + TaskScheduler.FromCurrentSynchronizationContext()); + NotifyOfPropertyChange(() => SelectedGame); + NotifyOfPropertyChange(() => this.CanGenerate); + NotifyOfPropertyChange(() => Players); + NotifyOfPropertyChange(() => PlayersOptions); + } + } + + public ObservableCollection Players + { + get => _players; + set + { + _players = value; + NotifyOfPropertyChange(() => Players); + } + } + + public ObservableCollection PlayersOptions + { + get => _playersOptions; + set + { + _playersOptions = value; + NotifyOfPropertyChange(() => PlayersOptions); + } + } + + public ObservableCollection OptionalPlayers + { + get => _optionalPlayers; + set + { + _optionalPlayers = value; + NotifyOfPropertyChange(() => OptionalPlayers); + } + } + + public ObservableCollection GamesFound { get; set; } + public List Games { get; set; } + + #endregion + + #region Commands + + public void UpdateDb() + { + Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; + var tsk = Task.Factory.StartNew(new Action(()=>this.RestService.RefreshDb())); + tsk.ContinueWith(t => + { + MessageBox.Show(t.Exception.InnerException.Message); + }, + CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, + TaskScheduler.FromCurrentSynchronizationContext()); + + MessageBox.Show("Database updated"); + + } + + public void Generate() + { + List test = new List(); + test = OptionalPlayers.ToList(); + var messageBoxText = this.RestService.CreateChallonge2(SelectedGame.Id, SelectedWpEvent.Id, test); + + if (messageBoxText != null && messageBoxText.Length > 0 && !messageBoxText.Contains("error")) + { + System.Diagnostics.Process.Start($"https://challonge.com/{messageBoxText}"); + } + else + MessageBox.Show("Didn't work :("); } public void LoadEvents() @@ -45,86 +161,7 @@ namespace LaDOSE.DesktopApp.ViewModels TaskScheduler.FromCurrentSynchronizationContext()); } - private void Load() - { - GamesFound = new ObservableCollection(); - this.Games = this.RestService.GetGames(); - this.Events = this.RestService.GetEvents(); - - NotifyOfPropertyChange("Events"); - Application.Current.Dispatcher.Invoke(() => - System.Windows.Input.Mouse.OverrideCursor = null); - } - - - public bool CanGenerate - { - get { return SelectedWpEvent != null && SelectedGame != null; } - } - - - public List Events { get; set; } - - public WPEvent SelectedWpEvent - { - get => _selectedWpEvent; - set - { - _selectedWpEvent = value; - SelectedGame = null; - ParseGame(_selectedWpEvent); - - } - } - - public Game SelectedGame - { - get => _selectedGame; - set - { - _selectedGame = value; - - Players.Clear(); - PlayersOptions.Clear(); - - Task.Factory.StartNew(LoadPlayers,TaskCreationOptions.LongRunning).ContinueWith(t => - { - - }, - CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, - TaskScheduler.FromCurrentSynchronizationContext()); - NotifyOfPropertyChange(() => SelectedGame); - NotifyOfPropertyChange(() => this.CanGenerate); - NotifyOfPropertyChange(() => Players); - NotifyOfPropertyChange(() => PlayersOptions); - } - } - - - - public ObservableCollection Players - { - get => _players; - set - { - _players = value; - NotifyOfPropertyChange(()=>Players); - } - } - - public ObservableCollection PlayersOptions - { - get => _playersOptions; - set - { - _playersOptions = value; - NotifyOfPropertyChange(() => PlayersOptions); - } - } - - - public ObservableCollection GamesFound { get; set; } - public List Games { get; set; } + #endregion private void ParseGame(WPEvent selectedWpEvent) { @@ -153,32 +190,58 @@ namespace LaDOSE.DesktopApp.ViewModels private void LoadPlayers() { - if (SelectedWpEvent != null) if (SelectedGame != null) { - this.RestService.GetUsers(SelectedWpEvent.Id, SelectedGame.Id).ForEach((e) => this.Players.AddUI(e)); - this.RestService.GetUsersOptions(SelectedWpEvent.Id, SelectedGame.Id).ForEach((e) => this.PlayersOptions.AddUI(e)); + var findUser = FindUser(SelectedWpEvent.Id, SelectedGame); + var findUser2 = FindUser(SelectedWpEvent.Id, SelectedGame,true); + findUser.ForEach((e) => this.Players.AddUI(e)); + findUser2.ForEach((e) => this.PlayersOptions.AddUI(e)); + //this.RestService.GetUsers(SelectedWpEvent.Id, SelectedGame.Id) + // .ForEach((e) => this.Players.AddUI(e)); + //this.RestService.GetUsersOptions(SelectedWpEvent.Id, SelectedGame.Id) + // .ForEach((e) => this.PlayersOptions.AddUI(e)); + NotifyOfPropertyChange(() => this.CanGenerate); } - } - public void UpdateDb() + private void Load() { - if (this.RestService.RefreshDb()) - MessageBox.Show("DataBaseUpdated"); - else - MessageBox.Show("Update Failed"); + Application.Current.Dispatcher.Invoke(() => + System.Windows.Input.Mouse.OverrideCursor = Cursors.Wait); + GamesFound = new ObservableCollection(); + this.Games = this.RestService.GetGames(); + this.Events = this.RestService.GetEvents(); + + NotifyOfPropertyChange("Events"); + Application.Current.Dispatcher.Invoke(() => + System.Windows.Input.Mouse.OverrideCursor = null); } - public void Generate() + public List FindUser(int wpEventId, Game game,bool optional = false) { - if (this.RestService.CreateChallonge(SelectedGame.Id, SelectedWpEvent.Id)) - MessageBox.Show("Challonge Created"); - else - MessageBox.Show("Didn't worl :("); - } + string[] selectedGameWpId; + selectedGameWpId = !optional ? game.WordPressTag.Split(';') : game.WordPressTagOs.Split(';'); + + var currentWpEvent = this.Events.Where(e => e.Id == wpEventId).ToList(); + List bookings = currentWpEvent.SelectMany(e => e.WpBookings).ToList(); + List users = new List(); + foreach (var booking in bookings) + { + var reservations = WpEventDeserialize.Parse(booking.Meta); + if (reservations != null) + { + var gamesReservation = reservations.Where(e => e.Valid).Select(e => e.Name); + if (selectedGameWpId.Any(e => gamesReservation.Contains(e))) + { + users.Add(booking.WpUser); + } + } + } + + return users; + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml index 47290be..b24e19e 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml @@ -4,10 +4,16 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:LaDOSE.DesktopApp.Views" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:cal="http://www.caliburnproject.org" + Icon="{Binding Path=AppIcon}" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> + + + + @@ -32,10 +38,18 @@ + + + + + + + + - + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml new file mode 100644 index 0000000..61fd2b3 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml.cs new file mode 100644 index 0000000..e107967 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +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 LaDOSE.DesktopApp.ViewModels; + +namespace LaDOSE.DesktopApp.Views +{ + /// + /// Interaction logic for ShellView.xaml + /// + public partial class WebNavigationView : UserControl + { + public WebNavigationView() + { + + InitializeComponent(); + + + } + + + } +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebView.xaml.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebView.xaml.cs new file mode 100644 index 0000000..267a933 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebView.xaml.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +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; + +namespace LaDOSE.DesktopApp.Views +{ + /// + /// Interaction logic for ShellView.xaml + /// + public partial class WebNavigationView : UserControl + { + public WebNavigationView() + { + + InitializeComponent(); + } + } +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml similarity index 90% rename from LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml rename to LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml index 0cab5f7..8a3dbba 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml @@ -6,13 +6,16 @@ xmlns:local="clr-namespace:LaDOSE.DesktopApp.Views" xmlns:userControls="clr-namespace:LaDOSE.DesktopApp.UserControls" xmlns:cal="http://www.caliburnproject.org" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:behaviors="clr-namespace:LaDOSE.DesktopApp.Behaviors" mc:Ignorable="d" + d:DesignHeight="450" d:DesignWidth="800"> - + @@ -43,7 +46,7 @@ + x:Name="BookingList" IsTextSearchEnabled="True" TextSearch.TextPath="WpUser.Name"> @@ -76,7 +79,7 @@ + SelectedItem="{Binding SelectedGame,UpdateSourceTrigger=PropertyChanged}" IsTextSearchEnabled="True" TextSearch.TextPath="Name"> @@ -99,7 +102,7 @@ - + @@ -113,7 +116,8 @@ - + + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml.cs similarity index 98% rename from LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml.cs rename to LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml.cs index 31063f6..d775dbf 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml.cs @@ -22,6 +22,7 @@ namespace LaDOSE.DesktopApp.Views { public WordPressView() { + InitializeComponent(); } diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs index e5af5eb..252fee3 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs @@ -10,6 +10,6 @@ namespace LaDOSE.Business.Interface List GetBooking(int wpEventId, Game game); List GetBookingOptions(int wpEventId, Game game); bool UpdateBooking(); - bool CreateChallonge(int gameId, int wpEventId); + string CreateChallonge(int gameId, int wpEventId, IList additionPlayers); } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs b/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs index 8537326..b743485 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs @@ -9,6 +9,7 @@ using LaDOSE.Entity.Context; using LaDOSE.Entity.Wordpress; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; namespace LaDOSE.Business.Service { @@ -78,14 +79,14 @@ namespace LaDOSE.Business.Service } return users; } - public bool CreateChallonge(int gameId, int wpEventId) + public string CreateChallonge(int gameId, int wpEventId, IList additionalPlayers) { var selectedGame = _context.Game.FirstOrDefault(e => e.Id == gameId); var selectedGameWpId = selectedGame.WordPressTag.Split(';'); var currentWpEvent = _context.WPEvent.Include(e => e.WPBookings).ThenInclude(e => e.WPUser) .Where(e => e.Id == wpEventId); var users = currentWpEvent.SelectMany(e => e.WPBookings.Select(u => u.WPUser)); - + var useradded = new List(); if (selectedGame != null) @@ -110,6 +111,7 @@ namespace LaDOSE.Business.Service { try { + useradded.Add(booking.WPUser); _challongeProvider.AddPlayer(tournament.id, booking.WPUser.Name); } catch @@ -124,13 +126,25 @@ namespace LaDOSE.Business.Service } - - return true; + if (additionalPlayers != null && additionalPlayers.Count > 0) + { + foreach (var additionalPlayer in additionalPlayers) + { + if (useradded.All(e => e.Name != additionalPlayer.Name)) + { + _challongeProvider.AddPlayer(tournament.id, additionalPlayer.Name); + } + } + + } + + + return tournament.url; } - return false; + return "error while creating challonge"; } } } \ No newline at end of file