public async Task <ApiResponse <Guild> > Handle(CreateGuildCommand request, CancellationToken cancellationToken) { var master = await _memberRepository.GetForGuildOperationsAsync(request.MasterId, cancellationToken); var createdGuild = await _guildRepository.InsertAsync(new Guild(request.Name, master), cancellationToken); return(new ApiResponse <Guild>(createdGuild)); }
public async Task <IActionResult> PostAsync([FromBody] CreateGuildCommand command, CancellationToken cancellationToken) { var result = await _mediator.Send(command, cancellationToken); return(result.Failures.Any() ? BadRequest(result.GenerateFailuresOutput()) as IActionResult : CreatedAtRoute("get-guild", new { id = result.Data.Id }, result.Data)); }
public static Faker <CreateGuildCommand> Valid(Guid?leaderId = null) { return(new Faker <CreateGuildCommand>().CustomInstantiator(x => { var command = new CreateGuildCommand { Name = x.Company.CatchPhrase(), LeaderId = leaderId ?? Guid.NewGuid() }; const string routename = "get-guild"; var urlHelper = UrlHelperMockBuilder.Create().SetupLink(routename).Build(); command.SetupForCreation(urlHelper, routename, x => new { x.Id }); return command; })); }
public async Task <Result <GuildDto> > Handle(GetGuildByDiscordIdQuery request, CancellationToken cancellationToken) { var guild = await _context.Guilds.Include(guild => guild.GuildSetting).FirstOrDefaultAsync(guild => guild.DiscordGuildId == request.DiscordId, cancellationToken); if (guild == null) { //If the guild doesn't exist yet we register it here. var createGuildCommand = new CreateGuildCommand { DiscordGuildId = request.DiscordId, }; return(await _mediator.Send(createGuildCommand)); } var mappedGuild = _mapper.Map <GuildDto>(guild); mappedGuild.Setting = _mapper.Map <GuildSettingDto>(guild.GuildSetting); return(await Result <GuildDto> .SuccessAsync(mappedGuild)); }
public EventCommandCreateGuild(CreateGuildCommand refCommand, EventPage page, FrmEvent editor) { InitializeComponent(); mMyCommand = refCommand; mCurrentPage = page; mEventEditor = editor; InitLocalization(); cmbVariable.Items.Clear(); cmbVariable.Items.AddRange(PlayerVariableBase.Names); if (mMyCommand.VariableId != null && mMyCommand.VariableId != Guid.Empty) { cmbVariable.SelectedIndex = PlayerVariableBase.ListIndex(mMyCommand.VariableId); } else if (cmbVariable.Items.Count > 0) { cmbVariable.SelectedIndex = 0; } }
public async Task <Result <GuildDto> > Handle(CreateGuildCommand command, CancellationToken cancellationToken) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (string.IsNullOrEmpty(command.DiscordGuildId)) { throw new ArgumentNullException(nameof(command.DiscordGuildId)); } var guild = _mapper.Map <Guild>(command); guild.GuildSetting = new GuildSetting { AllowNsfw = true, Id = Guid.NewGuid(), IsEnabled = true, Prefix = "$", Sort = Sort.Hot, MaxPlaylists = _limitSettings.DefaultMaxPlaylists, MaxQueueItems = _limitSettings.DefaultMaxItemsInQueue, MaxSubscriptions = _limitSettings.DefaultMaxSubscriptions }; guild.GuildSettingId = guild.GuildSetting.Id; await _context.Guilds.AddAsync(guild, cancellationToken); await _context.SaveChangesAsync(); var mappedGuild = _mapper.Map <GuildDto>(guild); mappedGuild.Setting = _mapper.Map <GuildSettingDto>(guild.GuildSetting); return(await Result <GuildDto> .SuccessAsync(mappedGuild)); }
public async Task <IActionResult> PostAsync([FromBody] CreateGuildCommand command, CancellationToken cancellationToken) { command.SetupForCreation(Url, "get-guild", x => new { id = x.Id }); return(await _mediator.Send(command, cancellationToken)); }