basic player management
This commit is contained in:
parent
350a283b5e
commit
bab170552e
12 changed files with 244 additions and 91 deletions
39
Sledgemapper.Api/Handlers/GetCampaignsCommandHandler.cs
Normal file
39
Sledgemapper.Api/Handlers/GetCampaignsCommandHandler.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using MediatR;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Infrastructure.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class GetCampaignsCommandHandler : IRequestHandler<GetCampaignsCommand, List<Core.Entities.Campaign>>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly SledgemapperDbContext _dbcontext;
|
||||
|
||||
public GetCampaignsCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_dbcontext = dbcontext;
|
||||
}
|
||||
|
||||
public async Task<List<Core.Entities.Campaign>> Handle(GetCampaignsCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||
_dbcontext.Attach(user);
|
||||
var campaigns = _dbcontext.Campaigns.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user));
|
||||
|
||||
return campaigns.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return new List<Core.Entities.Campaign>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue