public ActionResult <Result <LeagueViewModel> > Create([FromBody] CreateLeagueRequest request)
        {
            var user      = _userSessionStore.FindUserOrThrow(HttpContext.Session);
            var league    = _leagueStore.Create(request, user);
            var viewModel = _leagueViewModelFactory.CreateDetailedViewModel(league);

            return(Result <LeagueViewModel> .Successful(viewModel));
        }
        public ILeague Create(CreateLeagueRequest createLeagueRequest, IUser createdByUser)
        {
            const string sql = @"
				INSERT INTO public.league
				(name, uri_path, game_id, rules, created_by_user_id)
				VALUES
				(@Name, @UriPath, @GameId, @Rules, @CreatedByUserId)
				RETURNING league_id;"                ;

            using (var connection = AppDataConnection.Create())
            {
                var sqlParams = new
                {
                    createLeagueRequest.Name,
                    createLeagueRequest.UriPath,
                    createLeagueRequest.GameId,
                    createLeagueRequest.Rules,
                    createdByUser.UserId,
                };

                return(Find(connection.Query <Id <League> >(sql, sqlParams).Single()));
            }
        }
Beispiel #3
0
        public void SetUp()
        {
            GivenRequest = new CreateLeagueRequest
            {
                Name    = "League Name",
                UriPath = "UriPath",
                GameId  = Id <Game> .NewId(),
            };

            GivenUser = new UserBuilder();

            var controllerContext = new MockControllerContext();

            _leagueStore            = new Mock <ILeagueStore>();
            _leagueViewModelFactory = new Mock <ILeagueViewModelFactory>();

            _userSessionStore = new Mock <IUserSessionStore>();
            _userSessionStore.Setup(x => x.FindUserOrThrow(controllerContext.HttpContext.Session)).Returns(GivenUser.Instance);

            _createLeagueController = new CreateLeagueController(_leagueStore.Object, _leagueViewModelFactory.Object, _userSessionStore.Object)
            {
                ControllerContext = controllerContext
            };
        }