コード例 #1
0
        public async Task <Dto.Game?> UpdateAsync(int id, Dto.GameInput input)
        {
            Game entity = _mapper.Map <Dto.GameInput, Game>(input);
            Game?result = await _gameRepository.UpdateAsync(id, entity);

            return(result is null
            ? null
            :_mapper.Map <Game, Dto.Game>(result));
        }
コード例 #2
0
        public async Task <Dto.Game?> CreateAsync(Dto.GameInput input)
        {
            Game entity = _mapper.Map <Dto.GameInput, Game>(input);
            int  userId = _sessionService.GetCurrentUserId();
            User user   = await _userService.GetUserById(userId) ?? throw new IllegalStateException(nameof(User));

            entity.GameMaster = user.Id;
            entity.GameUsers.Add(new GameUser(user.Id, user, entity.Id, entity));
            await _gameRepository.InsertAsync(entity);

            Calendar calendar = _mapper.Map <Calendar>(input.Calendar);

            calendar.Game   = entity;
            calendar.GameId = entity.Id;
            await _calendarRepository.InsertAsync(calendar);

            entity.Calendar   = calendar;
            entity.CalendarId = calendar.Id;
            await _gameRepository.UpdateAsync(entity.Id, entity);

            _sessionService.SetCurrentGameId(entity.Id);
            return(_mapper.Map <Game, Dto.Game>(entity));
        }