public JsonResult Update([FromBody] UpdateUserCommand command, [FromServices] UserHandle handle ) { if (command is null) { return new JsonResult(NotFound()) { StatusCode = 404 } } ; try { var resultCommand = (GenericCommandResult)handle.Handle(command); if (resultCommand.Success) { var user = (User)resultCommand.Data; var userDTO = new UserDTO(user.Id, user.Name, user.Email, user.Login, user.Password); } return(Json(resultCommand.Message)); } catch (Exception ex) { return(new JsonResult(BadRequest()) { StatusCode = 400, Value = new GenericCommandResult(false, "Error ", ex.Message) }); } }
public JsonResult Authenticate([FromBody] AuthCommand command, [FromServices] UserHandle handle, [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations ) { if (command is null) { return new JsonResult(NotFound()) { StatusCode = 404 } } ; try { var auth = (GenericCommandResult)handle.Handle(command); if (!auth.Success) { return(new JsonResult(BadRequest()) { StatusCode = 400, Value = new GenericCommandResult(false, auth.Message, command.Notifications) }); } else { var user = (User)auth.Data; var userDTO = new UserDTO(user.Id, user.Name, user.Email, user.Login, "*******"); return(Json(new { token = JWTToken(user.Name, signingConfigurations, tokenConfigurations), user = user })); } } catch (Exception e) { return(new JsonResult(BadRequest()) { StatusCode = 400, Value = e.Message }); } }