コード例 #1
0
        public async Task <ActionResult <GeekProfileResponse> > GetProfile([FromRoute] int id)
        {
            var query   = new GetProfileByIdQuery(id);
            var profile = await this.mediator.Send(query);

            return(this.Ok(profile));
        }
コード例 #2
0
        public async Task <IActionResult> GetById(
            [FromServices] IMediator mediator,
            int id)
        {
            var query = new GetProfileByIdQuery(id);

            var data = await mediator.Send(query);

            return(new JsonResult(data.Profile));
        }
コード例 #3
0
        public async Task <ActionResult <GeekProfileResponse> > RegisterProfileAsync([FromBody] CreateGeekProfileModel model)
        {
            var query  = new RegisterProfileCommand(model);
            var result = await this.mediator.Send(query);

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

            var profile = new GetProfileByIdQuery(result.Value);

            return(this.CreatedAtRoute(nameof(GetProfile), new { result.Value }, profile));
        }
コード例 #4
0
        public async Task <ActionResult <GeekProfileResponse> > UpdatePersonalProfile([FromBody] GeekProfileModel model)
        {
            var user = await this.mediator.Send(new GetCurrentUserQuery());

            var userProfile = await this.mediator.Send(new GetProfileByUserQuery(user.Id));

            var command = new UpdateProfileCommand(model, userProfile.Id);
            var result  = await this.mediator.Send(command);

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

            var query   = new GetProfileByIdQuery(result.Value);
            var profile = await this.mediator.Send(query);

            return(this.Ok(profile));
        }