コード例 #1
0
        public async Task <Result <long> > Handle(RegisterSkillCommand request, CancellationToken cancellationToken)
        {
            if (this.repository.Exists(request.SkillId))
            {
                return(Results.Fail("Skill already exists."));
            }

            var skill = this.mapper.Map <Skill>(request.Skill);

            this.repository.Add(request.ProfileId, skill);

            return(Results.Ok(skill.Id));
        }
コード例 #2
0
        public async Task <ActionResult <SkillResponse> > RegisterSkillAsync([FromRoute] int profileId, [FromBody] SkillModel model)
        {
            var command = new RegisterSkillCommand(profileId, model);
            var result  = await this.mediator.Send(command);

            if (result.IsFailed)
            {
                return(this.UnprocessableEntity(result));
            }

            var user = await this.mediator.Send(new GetCurrentUserQuery());

            var notification = new EvaluateSkillNotification(user.Id, result.Value, model.Score);

            await this.mediator.Publish(notification);

            var query = new GetSkillQuery(result.Value);
            var skill = await this.mediator.Send(query);

            return(CreatedAtRoute(nameof(GetSkill), new { skillId = skill !.Id }, skill));