Example #1
0
        private Character ModifyCharacter(CharacterRepository characterRepo, Character character)
        {
            var dbCharacter = characterRepo.GetById(character.Id);

            dbCharacter.Name              = character.Name;
            dbCharacter.Age               = character.Age;
            dbCharacter.Story             = character.Story;
            dbCharacter.NarrativeFunction = character.NarrativeFunction;
            dbCharacter.Gender            = character.Gender;

            var memoriesToRemove = dbCharacter.Memories.Where(dbm => !character.Memories.Any(m => dbm.Id == m.Id)).ToList();

            foreach (var memoryToRemove in memoriesToRemove)
            {
                dbCharacter.Memories.Remove(memoryToRemove);
            }

            foreach (var memory in character.Memories)
            {
                var dbMemory = dbCharacter.Memories.FirstOrDefault(c => memory.Id != 0 && c.Id == memory.Id);
                if (dbMemory == null)
                {
                    dbMemory = new Memory();
                    dbCharacter.Memories.Add(dbMemory);
                }

                dbMemory.Description = memory.Description;
            }

            character = characterRepo.Modify(dbCharacter);
            return(character);
        }
Example #2
0
        private Plot ModifyPlot(PlotRepository plotRepo, CharacterRepository characterRepo, Plot plot)
        {
            var dbPlot = plotRepo.GetById(plot.Id);

            dbPlot.Name        = plot.Name;
            dbPlot.Description = plot.Description;

            var charactersToRemove = dbPlot.Characters.Where(dbc => !plot.Characters.Any(c => dbc.Id == c.Id || dbc.Character.Id == c.Character.Id)).ToList();

            foreach (var characterToRemove in charactersToRemove)
            {
                dbPlot.Characters.Remove(characterToRemove);
            }

            foreach (var characterInPlot in plot.Characters)
            {
                var dbCharacter = dbPlot.Characters.FirstOrDefault(c => (characterInPlot.Id != 0 && c.Id == characterInPlot.Id) ||
                                                                   c.Character.Id == characterInPlot.Character.Id);
                if (dbCharacter == null)
                {
                    dbCharacter = new CharacterInPlot
                    {
                        Character = characterRepo.GetById(characterInPlot.Character.Id)
                    };
                    dbPlot.Characters.Add(dbCharacter);
                }

                dbCharacter.Description = characterInPlot.Description;
            }

            plot = plotRepo.Modify(dbPlot);
            return(plot);
        }
Example #3
0
        public IActionResult GetCharacter([FromQuery] long characterId)
        {
            var character = _repository.GetById(characterId);

            if (character == null)
            {
                return(BadRequest("Character does not exist."));
            }

            return(Ok(character));
        }
Example #4
0
 public IHttpActionResult GetCharacter(string id)
 {
     try
     {
         CharacterDTO character = Repository.GetById(id).DTO;
         return(Ok(character));
     }
     catch (NullReferenceException nre)
     {
         return(NotFound());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #5
0
        public CharacterQuery(CharacterRepository characterRepo, IUsersIdentityService accountService)
        {
            Name = "CharacterQuery";

            Field <ListGraphType <CharacterGraphType> >("all",
                                                        arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                                        resolve: context => characterRepo.GetAll()
                                                        .ApplyPaginationAndOrderBy(context)
                                                        .ToList().Where(c => !accountService.CurrentUser.UserName.Contains("-") ||
                                                                        !c.Hosts.Any() ||
                                                                        c.Hosts.Any(h => h.Host.Account.UserName.StartsWith(accountService.CurrentUser.UserName.Split('-').First()))) //TODO: Remove this line, only to send both runs pre game
                                                        );

            Field <CharacterGraphType>("byId",
                                       arguments: new QueryArguments(
                                           new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "character id"
            }
                                           ),
                                       resolve: context => characterRepo.GetById(context.GetArgument <int>("id")));
        }
 public override Character GetEntityById(Guid id)
 {
     return(_characterRepository.GetById(id));
 }
Example #7
0
 public Character GetById(long id)
 {
     return(_characterRepository.GetById(id));
 }