This commit is contained in:
parent
4d59131905
commit
3e1acd26f2
@ -6,13 +6,13 @@ namespace Sledgemapper.Api.Commands
|
||||
public class InvitePlayerToCampaignCommand : IRequest<bool>
|
||||
{
|
||||
public double Timestamp { get; private set; }
|
||||
public string CampaignName { get; private set; }
|
||||
public Guid CampaignId { get; private set; }
|
||||
public string Email { get; private set; }
|
||||
public string UserId { get; private set; }
|
||||
public InvitePlayerToCampaignCommand(string campaingName, string email, string userId)
|
||||
public InvitePlayerToCampaignCommand(Guid campaignId, string email, string userId)
|
||||
{
|
||||
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
CampaignName = campaingName;
|
||||
CampaignId = campaignId;
|
||||
UserId = userId;
|
||||
Email = email;
|
||||
}
|
||||
|
@ -48,10 +48,10 @@ namespace Sledgemapper.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{campaignName}/players/{email}")]
|
||||
public async Task<bool> Invite(string campaignName, string email)
|
||||
[Route("{campaignId}/players/{email}")]
|
||||
public async Task<bool> Invite(Guid campaignId, string email)
|
||||
{
|
||||
var result = await _mediator.Send(new InvitePlayerToCampaignCommand(campaignName, email, UserId));
|
||||
var result = await _mediator.Send(new InvitePlayerToCampaignCommand(campaignId, email, UserId));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||
|
||||
var campaign = await _dbcontext.Campaigns.Where(campaign=>campaign.CampaignName==command.CampaignName && campaign.OwnerId==command.UserId).Include(campaign=>campaign.InvitedUsers).FirstAsync();
|
||||
var invitedUser = await _dbcontext.Users.FirstOrDefaultAsync(user=>user.Email==command.Email);
|
||||
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.InvitedUsers).FirstAsync();
|
||||
var invitedUser = await _dbcontext.Users.FirstOrDefaultAsync(user => user.Email == command.Email);
|
||||
_dbcontext.Attach(invitedUser);
|
||||
_dbcontext.Attach(campaign);
|
||||
campaign.InvitedUsers.Add(invitedUser);
|
||||
|
@ -42,15 +42,15 @@ namespace Sledgemapper
|
||||
Task<List<Player>> GetPlayers(Guid campaignName);
|
||||
|
||||
|
||||
[Get("/campaign/{campaignName}/maps")]
|
||||
Task<List<Session>> GetMaps(Guid campaignName);
|
||||
[Get("/campaign/{campaignId}/maps")]
|
||||
Task<List<Session>> GetMaps(Guid campaignId);
|
||||
|
||||
[Get("/map/{campaignName}/{mapName}")]
|
||||
Task<Session> GetMap(Guid campaignName, Guid mapName);
|
||||
[Get("/map/{campaignId}/{mapId}")]
|
||||
Task<Session> GetMap(Guid campaignId, Guid mapId);
|
||||
|
||||
|
||||
[Post("/campaign/{campaignName}/players/{email}")]
|
||||
Task InvitePlayer(string campaignName, string email);
|
||||
[Post("/campaign/{campaignId}/players/{email}")]
|
||||
Task InvitePlayer(Guid campaignId, string email);
|
||||
|
||||
|
||||
|
||||
|
@ -100,6 +100,7 @@ namespace Sledgemapper.UI
|
||||
_authResponse = await CommunicationManager.Login(new AuthenticateModel
|
||||
{
|
||||
Username = TxtEmail.Text,
|
||||
Email = TxtEmail.Text,
|
||||
Password = TxtPassword.Text
|
||||
});
|
||||
successful = true;
|
||||
|
@ -297,7 +297,7 @@ namespace Sledgemapper.UI
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled) return;
|
||||
|
||||
var content = new PlayerList(CommunicationManager);
|
||||
var content = new PlayerList(CommunicationManager, Messenger);
|
||||
if (await content.LoadPlayers())
|
||||
{
|
||||
content.ShowInModalWindow(Desktop, "Players");
|
||||
|
@ -1,15 +1,20 @@
|
||||
/* Generated by MyraPad at 28/08/2021 19:49:08 */
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using TinyMessenger;
|
||||
|
||||
namespace Sledgemapper.UI
|
||||
{
|
||||
public partial class PlayerList
|
||||
{
|
||||
protected readonly CommunicationManager CommunicationManager;
|
||||
protected CommunicationManager CommunicationManager { get; }
|
||||
protected TinyMessengerHub Messenger { get; }
|
||||
|
||||
public PlayerList(CommunicationManager communicationManager)
|
||||
public PlayerList(CommunicationManager communicationManager, TinyMessenger.TinyMessengerHub messenger)
|
||||
{
|
||||
CommunicationManager = communicationManager;
|
||||
Messenger = messenger;
|
||||
|
||||
BuildUI();
|
||||
CommunicationManager = communicationManager;
|
||||
BtnInvitePlayer.Click += (s, e) =>
|
||||
@ -38,7 +43,7 @@ namespace Sledgemapper.UI
|
||||
|
||||
private void ShowAddPLayerWindow()
|
||||
{
|
||||
new PlayerWindow(CommunicationManager).ShowInModalWindow(Desktop, "Invite player");
|
||||
new PlayerWindow(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "Invite player");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,21 @@
|
||||
/* Generated by MyraPad at 28/08/2021 22:04:11 */
|
||||
using Myra.Graphics2D.UI;
|
||||
using Sentry;
|
||||
using Sledgemapper.Messages;
|
||||
using System;
|
||||
using TinyMessenger;
|
||||
|
||||
namespace Sledgemapper.UI
|
||||
{
|
||||
public partial class PlayerWindow
|
||||
{
|
||||
protected readonly CommunicationManager CommunicationManager;
|
||||
protected CommunicationManager CommunicationManager { get; }
|
||||
protected TinyMessengerHub Messenger { get; }
|
||||
|
||||
public PlayerWindow(CommunicationManager communicationManager)
|
||||
public PlayerWindow(CommunicationManager communicationManager, TinyMessenger.TinyMessengerHub messenger)
|
||||
{
|
||||
CommunicationManager = communicationManager;
|
||||
CommunicationManager = communicationManager;
|
||||
Messenger = messenger;
|
||||
|
||||
BuildUI();
|
||||
BtnNewCampaign.Click += OnButtonInvitePlayerClicked;
|
||||
@ -29,11 +33,13 @@ namespace Sledgemapper.UI
|
||||
var successful = false;
|
||||
try
|
||||
{
|
||||
await CommunicationManager.Api.InvitePlayer(State.Instance.CampaignName, localContent.Content.TxtCampaign.Text);
|
||||
await CommunicationManager.Api.InvitePlayer(State.Instance.CampaignId, localContent.Content.TxtCampaign.Text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Messenger.Publish(new ErrorMessage(this, "Error inviting player"));
|
||||
SentrySdk.CaptureException(ex);
|
||||
|
||||
}
|
||||
this.GetContainingWindow().Close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user