Exemplo n.º 1
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));
        }
        public async Task <Result <long> > Handle(RegisterProfileCommand request, CancellationToken cancellationToken)
        {
            if (this.repository.UserExists(request.Profile.Email))
            {
                return(Results.Fail <long>("Profile already exists."));
            }

            var applicationUser = await this.CreateUser(request.Profile.Email, request.Profile.Password);

            var profile = this.mapper.Map <GeekProfile>(request.Profile);

            profile.User = applicationUser;

            this.repository.Add(profile);

            return(Results.Ok(profile.Id));
        }