This commit is contained in:
parent
e18cbb157c
commit
155cb4ea9a
13 changed files with 99 additions and 58 deletions
43
Sledgemapper.Api/Handlers/GetCampaignMapsCommandHandler.cs
Normal file
43
Sledgemapper.Api/Handlers/GetCampaignMapsCommandHandler.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Infrastructure.Data;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class GetCampaignMapsCommandHandler : IRequestHandler<GetCampaignMapsCommand, List<Session>>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly SledgemapperDbContext _dbcontext;
|
||||
|
||||
public GetCampaignMapsCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_dbcontext = dbcontext;
|
||||
}
|
||||
|
||||
public async Task<List<Session>> Handle(GetCampaignMapsCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||
_dbcontext.Attach(user);
|
||||
|
||||
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignName == command.CampaignName && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
|
||||
|
||||
var maps = campaign.Maps.Select(session => new Session { SessionName = session.SessionName, SessionId = session.SessionId }).ToList();
|
||||
return maps;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue