Exemplo n.º 1
0
        public Expression <Func <DemoContext, Person> > AddActor(DemoContext db, AddActorArgs args)
        {
            var person = new Person {
                Id        = (uint)new Random().Next(),
                FirstName = args.FirstName,
                LastName  = args.LastName,
            };

            db.People.Add(person);
            var actor = new Actor {
                MovieId = args.MovieId,
                Person  = person,
            };

            db.Actors.Add(actor);
            db.SaveChanges();

            return((ctx) => ctx.People.First(p => p.Id == person.Id));
        }
Exemplo n.º 2
0
        public Expression <Func <DemoContext, Person> > AddActor(DemoContext db, [MutationArguments] AddActorArgs args, GraphQLValidator validator)
        {
            if (string.IsNullOrEmpty(args.FirstName))
            {
                validator.AddError("Name argument is required");
            }
            if (db.Movies.FirstOrDefault(m => m.Id == args.MovieId) == null)
            {
                validator.AddError("MovieId not found");
            }
            // ... do more validation

            if (validator.HasErrors)
            {
                return(null);
            }

            //  we're here and valid
            var person = new Person
            {
                Id        = (uint)new Random().Next(),
                FirstName = args.FirstName,
                LastName  = args.LastName,
            };

            db.People.Add(person);
            var actor = new Actor
            {
                MovieId = args.MovieId,
                Person  = person,
            };

            db.Actors.Add(actor);
            db.SaveChanges();

            return((ctx) => ctx.People.First(p => p.Id == person.Id));
        }
Exemplo n.º 3
0
        public Expression <Func <DemoContext, IEnumerable <Person> > > AddActor2(DemoContext db, [MutationArguments] AddActorArgs args)
        {
            var person = new Person
            {
                Id        = (uint)new Random().Next(),
                FirstName = args.FirstName,
                LastName  = args.LastName,
            };

            db.People.Add(person);
            var actor = new Actor
            {
                MovieId = args.MovieId,
                Person  = person,
            };

            db.Actors.Add(actor);
            db.SaveChanges();

            return((ctx) => ctx.People.Where(p => p.FirstName == person.FirstName));
        }