public async Task <ActionResult <NestContractView> > CloseContract( [FromRoute] Guid contractId, [FromServices] INestContractRepository repository, [FromServices] IQueryProcessor queryProcessor, CancellationToken cancellationToken) { var contract = await repository.Get(contractId, cancellationToken); if (contract == null || contract.UserId != HttpContext.GetUserId()) { throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.ContractNotFound, $"Contract {contractId} fot found"); } contract.Close(); await repository.Save(contract, cancellationToken); return(Ok(await queryProcessor.Process <NestContractQuery, NestContractView>(new NestContractQuery( guildId: HttpContext.GetGuildId(), nestContractId: contractId), cancellationToken))); }
/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="guildId"></param> /// <param name="id"></param> /// <param name="nestId"></param> /// <param name="reward"></param> /// <param name="characterName"></param> /// <param name="cancellationToken"></param> /// <exception cref="LimitExceededException"></exception> /// <returns></returns> /// <exception cref="NestNotFoundException"></exception> /// <exception cref="ContractAlreadyExistsException"></exception> public async Task <NestContract> Create(Guid userId, Guid guildId, Guid id, Guid nestId, String reward, String characterName, CancellationToken cancellationToken = default) { var nest = await _nestGetter.Get(nestId, guildId, cancellationToken); if (nest == null) { throw new NestNotFoundException(nestId); } var existsContract = await _repository.Get(id, cancellationToken); if (existsContract != null) { if (existsContract.Reward != reward || existsContract.CharacterName != characterName || existsContract.UserId != userId || existsContract.NestId != nestId) { throw new ContractAlreadyExistsException(id); } return(existsContract); } var activeCount = await _repository.GetActiveCount(userId, cancellationToken); if (activeCount >= 35) { throw new LimitExceededException(35); } var nc = new NestContract(id: id, userId: userId, nestId: nestId, characterName: characterName, reward: reward); nc.SetTimeOut(168); return(nc); }