/// <inheritdoc />
        public async Task <bool> TryCreateAsync(CharacterSessionModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //TODO: look into transactions/locks
            await Context
            .CharacterSessions
            .AddAsync(model);

            //TODO: This can throw due to race condition
            int rowChangedCount = await Context.SaveChangesAsync();

            return(rowChangedCount != 0);
        }
        public async Task <CharacterSessionEnterResponse> EnterSession([FromRoute(Name = "id")] int characterId)
        {
            if (!await IsCharacterIdValidForUser(characterId, CharacterRepository))
            {
                return(new CharacterSessionEnterResponse(CharacterSessionEnterResponseCode.InvalidCharacterIdError));
            }

            int accountId = ClaimsReader.GetUserIdInt(User);

            //This checks to see if the account, not just the character, has an active session.
            //We do this before we check anything to reject quick even though the query behind this
            //may be abit more expensive
            //As a note, this checks (or should) CLAIMED SESSIONS. So, it won't prevent multiple session entries for an account
            //This is good because we actually use the left over session data to re-enter the instances on disconnect.
            if (await CharacterSessionRepository.AccountHasActiveSession(accountId))
            {
                return(new CharacterSessionEnterResponse(CharacterSessionEnterResponseCode.AccountAlreadyHasCharacterSession));
            }

            //They may have a session entry already, which is ok. So long as they don't have an active claimed session
            //which the above query checks for.
            bool hasSession = await CharacterSessionRepository.ContainsAsync(characterId);

            //We need to check active or not
            if (hasSession)
            {
                //If it's active we can just retrieve the data and send them off on their way
                CharacterSessionModel sessionModel = await CharacterSessionRepository.RetrieveAsync(characterId);

                //TODO: Handle case when we have an inactive session that can be claimed
                return(new CharacterSessionEnterResponse(sessionModel.ZoneId));
            }

            //If we've made it this far we'll need to create a session (because one does not exist) for the character
            //but we need player location data first (if they've never entered the world they won't have any
            //TODO: Handle location loading
            //TODO: Handle deafult
            if (!await CharacterSessionRepository.TryCreateAsync(new CharacterSessionModel(characterId, 1)))
            {
                return(new CharacterSessionEnterResponse(CharacterSessionEnterResponseCode.GeneralServerError));
            }

            //TODO: Better zone handling
            return(new CharacterSessionEnterResponse(1));
        }
        /// <inheritdoc />
        public Task UpdateAsync(int key, CharacterSessionModel model)
        {
            GeneralGenericCrudRepositoryProvider <int, CharacterSessionModel> crudProvider = new GeneralGenericCrudRepositoryProvider <int, CharacterSessionModel>(Context.CharacterSessions, Context);

            return(crudProvider.UpdateAsync(key, model));
        }