Compare commits
2 Commits
85e2f699bf
...
099fca8ceb
Author | SHA1 | Date | |
---|---|---|---|
|
099fca8ceb | ||
|
5276055c4d |
@ -29,7 +29,18 @@ namespace Sledgemapper.Api.Handlers
|
||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||
_dbcontext.Attach(user);
|
||||
|
||||
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.InvitedUsers).FirstAsync();
|
||||
|
||||
var campaign = await _dbcontext
|
||||
.Campaigns
|
||||
.Where(campaign => campaign.CampaignId == command.CampaignId)
|
||||
.Include(c => c.InvitedUsers)
|
||||
|
||||
.Include(c => c.Owner)
|
||||
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
|
||||
|
||||
|
||||
|
||||
//var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.InvitedUsers).FirstAsync();
|
||||
|
||||
var players = campaign.InvitedUsers.Select(user => new Player { Initials = user.Initials, UserName = user.UserName , UserId = new Guid(user.Id)}).ToList();
|
||||
return players;
|
||||
|
@ -1,43 +1,53 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Infrastructure.Data;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Infrastructure.Data;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class InvitePlayerToCampaignCommandHandler : IRequestHandler<InvitePlayerToCampaignCommand, bool>
|
||||
{
|
||||
private readonly SledgemapperDbContext _dbContext;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly SledgemapperDbContext _dbcontext;
|
||||
|
||||
public InvitePlayerToCampaignCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext)
|
||||
public InvitePlayerToCampaignCommandHandler(IMediator mediator, SledgemapperDbContext dbContext)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_dbcontext = dbcontext;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<bool> Handle(InvitePlayerToCampaignCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||
var user = await _dbContext.Users.FindAsync(command.UserId);
|
||||
|
||||
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);
|
||||
var campaign = await _dbContext
|
||||
.Campaigns
|
||||
.Where(campaign => campaign.CampaignId == command.CampaignId)
|
||||
.Include(c => c.InvitedUsers)
|
||||
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user))
|
||||
.FirstAsync(cancellationToken);
|
||||
|
||||
|
||||
var invitedUser =
|
||||
await _dbContext.Users.FirstOrDefaultAsync(iUser => iUser.Email == command.Email,
|
||||
cancellationToken);
|
||||
_dbContext.Attach(invitedUser);
|
||||
_dbContext.Attach(campaign);
|
||||
campaign.InvitedUsers.Add(invitedUser);
|
||||
_dbcontext.Campaigns.Update(campaign);
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
|
||||
await _dbContext.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -231,6 +231,7 @@ namespace Sledgemapper.UI
|
||||
MenuCampaingNew.Enabled = true;
|
||||
MenuMapNew.Enabled = false;
|
||||
MenuMapOpen.Enabled = false;
|
||||
MenuCampaignPlayers.Enabled = false;
|
||||
lblCampaign.Text = "n/a";
|
||||
lblMap.Text = "n/a";
|
||||
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
|
||||
|
@ -45,7 +45,7 @@ namespace Sledgemapper.UI
|
||||
grid1.Widgets.Add(TxtCampaign);
|
||||
|
||||
BtnNewCampaign = new TextButton();
|
||||
BtnNewCampaign.Text = "New";
|
||||
BtnNewCampaign.Text = "Invite";
|
||||
BtnNewCampaign.Padding = new Thickness(10, 5);
|
||||
BtnNewCampaign.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
|
||||
BtnNewCampaign.Id = "BtnNewCampaign";
|
||||
|
Loading…
Reference in New Issue
Block a user