public async Task <ResponseBase> DeleteTibiaCharacterAsync(int tibiaCharacterId)
        {
            var tibiaCharacter = _context.TibiaCharacter.Find(tibiaCharacterId);

            if (tibiaCharacter == null)
            {
                return(ResponseBase.ReturnFailed("Character cannot be deleted because it does not exist."));
            }

            tibiaCharacter.CharacterListRelations
            .Where(relation => relation.TibiaCharacterId == tibiaCharacterId)
            .Select(relation => _context.CharacterListRelation.Remove(relation));

            var removeCharacterRelationsFromDBResponse =
                await ResponseBaseMapper
                .SaveDbChangesAndMapResponse("Error ocurred when trying to clear related data to character list.", _context);

            if (removeCharacterRelationsFromDBResponse.Failed)
            {
                return(removeCharacterRelationsFromDBResponse);
            }

            _context.TibiaCharacter.Remove(tibiaCharacter);

            var response = await ResponseBaseMapper.SaveDbChangesAndMapResponse("Character deletion failed.", _context);

            return(response);
        }
Example #2
0
        public async Task <ResponseBase> RemoveCharacterListAsync(int characterListId)
        {
            var characterList = _context.CharacterList
                                .Where(charList => charList.CharacterListId == characterListId)
                                .FirstOrDefault();

            if (characterList == null)
            {
                return(ResponseBase.ReturnFailed("Character list with specified id does not exist."));
            }

            characterList.CharacterListRelations
            .Where(relation => relation.CharacterListId == characterListId)
            .Select(relation => _context.CharacterListRelation.Remove(relation));

            characterList.Account.CharacterList = null;

            var removeCharacterRelationsFromDBResponse =
                await ResponseBaseMapper
                .SaveDbChangesAndMapResponse("Error ocurred when trying to clear related data to character list.", _context);

            if (removeCharacterRelationsFromDBResponse.Failed)
            {
                return(removeCharacterRelationsFromDBResponse);
            }

            _context.CharacterList.Remove(characterList);

            var removeCharacterListFromDBResponse =
                await ResponseBaseMapper.SaveDbChangesAndMapResponse("Error ocurred when trying to delete character list.", _context);

            return(removeCharacterRelationsFromDBResponse);
        }
Example #3
0
        public async Task <ResponseBase> AddTibiaCharacterToListAsync(TibiaCharacter tibiaCharacter, int characterListId)
        {
            if (tibiaCharacter == null)
            {
                return(ResponseBase.ReturnFailed("Character provided in request was null."));
            }

            var characterList = _context.CharacterList.Find(characterListId);

            if (characterList == null)
            {
                return(ResponseBase.ReturnFailed("Specified character list did not exist."));
            }

            if (characterList.CharacterListRelations == null)
            {
                characterList.CharacterListRelations = new List <CharacterListRelation>();
            }

            characterList.CharacterListRelations.Add(new CharacterListRelation
            {
                TibiaCharacter = tibiaCharacter,
                CharacterList  = characterList
            });

            var dbResponse =
                await ResponseBaseMapper.SaveDbChangesAndMapResponse("Error ocurred when trying to add character to list.", _context);

            return(dbResponse);
        }
Example #4
0
        public async Task <ResponseBase> RemoveTibiaCharacterFromListAsync(int tibiaCharacterId, int characterListId)
        {
            var tibiaCharacter = _context.TibiaCharacter.Find(tibiaCharacterId);

            if (tibiaCharacter == null)
            {
                return(ResponseBase.ReturnFailed("Character that you tried to delete could not be found."));
            }

            var characterList = _context.CharacterList.Find(characterListId);

            if (characterList == null)
            {
                return(ResponseBase.ReturnFailed("Character list with specified id does not exist."));
            }

            characterList.CharacterListRelations
            .Where(relation => relation.CharacterListId == characterListId && relation.TibiaCharacterId == tibiaCharacterId)
            .Select(relation => _context.CharacterListRelation.Remove(relation));

            var dbResponse =
                await ResponseBaseMapper.SaveDbChangesAndMapResponse("Error ocurred when trying to delete character from list.", _context);

            return(dbResponse);
        }
        public async Task <ResponseBase> AddTibiaCharacterAsync(TibiaCharacter tibiaCharacter)
        {
            _context.TibiaCharacter.Add(tibiaCharacter);

            var response = await ResponseBaseMapper.SaveDbChangesAndMapResponse("Failed to add tibia character.", _context);

            return(response);
        }
Example #6
0
        public async Task <ResponseBase> CreateCharacterListAsync(int accountId)
        {
            var account = _context.Account.Find(accountId);

            if (account == null)
            {
                return(ResponseBase.ReturnFailed("Tried to create a character list for an account that did not exist."));
            }

            var characterList = new CharacterList
            {
                Account = account
            };

            _context.CharacterList.Add(characterList);

            var dbSaveResponse =
                await ResponseBaseMapper.SaveDbChangesAndMapResponse("Error ocurred when trying to create character list.", _context);

            return(dbSaveResponse);
        }
        public async Task <ResponseBase> UpdateTibiaCharacterAsync(int tibiaCharacterId, TibiaCharacter requestedTibiaCharacter)
        {
            if (requestedTibiaCharacter == null)
            {
                return(ResponseBase.ReturnFailed($"{ nameof(requestedTibiaCharacter) } update request object was null."));
            }

            var existingTibiaCharacter = _context.TibiaCharacter.Find(tibiaCharacterId);

            if (existingTibiaCharacter == null)
            {
                return(ResponseBase.ReturnFailed("Character cannot be updated because it does not exist."));
            }

            existingTibiaCharacter = MapUpdateRequest(existingTibiaCharacter, requestedTibiaCharacter);
            _context.TibiaCharacter.Update(existingTibiaCharacter);

            var response = await ResponseBaseMapper
                           .SaveDbChangesAndMapResponse(
                $"Error ocurred when trying to update tibia character with id: {existingTibiaCharacter.TibiaCharacterId}",
                _context);

            return(response);
        }