public ActionResult <Result <ITeamProfile> > CreateTeam([FromBody] CreateTeamRequest request)
        {
            var userFromSession = _userSessionStore.FindUserOrThrow(HttpContext.Session);
            var team            = _teamStore.CreateTeam(request, userFromSession);
            var teamProfile     = _teamProfileFactory.Create(team);

            return(Result <ITeamProfile> .Successful(teamProfile));
        }
        public Result IsValid(CreateTeamRequest request, IUser loggedInUser)
        {
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                return(Result.Failure("New team must have a name"));
            }

            return(Result.Successful());
        }
        public ITeam CreateTeam(CreateTeamRequest request, IUser teamCreator)
        {
            const string sql = @"
				INSERT INTO public.team
				(name, owner_user_id, profile_content, owner_user_id, created_time)
				VALUES
				(@Name, @OwnerUserId, @ProfileContent, @OwnerUserId, @CreatedTime)
				RETURNING team_id;"                ;

            using (var connection = AppDataConnection.Create())
            {
                var args = new
                {
                    request.Name,
                    request.ProfileContent,
                    OwnerUserId = teamCreator.UserId,
                    CreatedAt   = teamCreator.DefaultTimezone.CurrentTime(),
                };

                var teamId = connection.Query <Id <Team> >(sql, args).Single();
                return(TryFindTeam(teamId, out var team) ? team : throw new Exception("Somehow that team you saved doesn't exist now?"));
            }
        }