Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public PlotQuery(PlotRepository plotRepo, IUsersIdentityService accountService)
        {
            Name = "PlotQuery";

            Field <ListGraphType <PlotGraphType> >("all",
                                                   arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                                   resolve: context => plotRepo.GetAll()
                                                   .ApplyPaginationAndOrderBy(context)
                                                   .ToList().Where(p => !accountService.CurrentUser.UserName.Contains("-") || p.Characters.Any(c => c.Character.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 <PlotGraphType>("byId",
                                  arguments: new QueryArguments(
                                      new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "plot id"
            }
                                      ),
                                  resolve: context => plotRepo.GetById(context.GetArgument <int>("id")));
        }