Ejemplo n.º 1
0
        public async Task AddAuthorAsync(string name, string surname, IList <BookDTO> books, DateTime activeYear)
        {
            var author = await _authorRepository.GetAuthorAsync(name); // should check for name and surname here

            if (author != null)
            {
                throw new Exception($"author with name {name} already exist");
            }
            author = new Author(Guid.NewGuid(), name, surname, books, activeYear);
            await _authorRepository.AddAuthorAsync(author);
        }
Ejemplo n.º 2
0
 public async Task <Author> AddAuthorAsync(Author author)
 {
     try
     {
         return(await _repo.AddAuthorAsync(author));
     }
     catch (DataException e)
     {
         _logger.Error(e.Message);
         throw new DataException(e.Message);
     }
 }
Ejemplo n.º 3
0
        // POST api/values
        public async Task <IHttpActionResult> Post(AuthorViewModel viewModel)
        {
            var newAuthor = new Author(
                new Name(
                    viewModel.FirstName,
                    viewModel.LastName
                    )
                );

            await _authorRepository.AddAuthorAsync(newAuthor);

            return(Created($"{Request.RequestUri}/{newAuthor.Id}", newAuthor));
        }
Ejemplo n.º 4
0
        public MutationType(IAuthorRepository authorRepository)
        {
            Field <AuthorType>()
            .Name("createAuthor")
            .Argument <NonNullGraphType <StringGraphType> >("firstName", "the firstName of the new author")
            .Argument <NonNullGraphType <StringGraphType> >("lastName", "the lastName of the new author")
            .ResolveAsync(async context =>
            {
                var firstName = context.GetArgument <string>("firstName");
                var lastName  = context.GetArgument <string>("lastName");

                var newAuthor = new AuthorEntity()
                {
                    FirstName = firstName, LastName = lastName
                };
                return(await authorRepository.AddAuthorAsync(newAuthor));
            });
        }
Ejemplo n.º 5
0
        public BooksMutation(IBookRepository bookRepository, IAuthorRepository authorRepository, IAuthorMessageService authorMessageService, IBookMessageService bookMessageService)
        {
            FieldAsync <BookType>(
                "createBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookAddedType> > {
                Name = "book"
            }),
                resolve: async context =>
            {
                var book = context.GetArgument <Book>("book");
                await bookRepository.AddBookAsync(book);
                bookMessageService.AddBookMessage(book);
                return(book);
            });

            FieldAsync <BookType>(
                "updateBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookUpdatedType> > {
                Name = "book"
            }),
                resolve: async context =>
            {
                var book = context.GetArgument <Book>("book");
                await bookRepository.UpdateBookAsync(book);
                bookMessageService.UpdateBookMessage(book);
                return(book);
            });

            FieldAsync <BookType>(
                "deleteBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id   = context.GetArgument <int>("id");
                var book = await bookRepository.GetBookAsync(id);
                await bookRepository.DeleteBookAsync(book);
                bookMessageService.DeleteBookMessage(book);
                return(book);
            });

            FieldAsync <AuthorType>(
                "createAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <AuthorAddedType> > {
                Name = "author"
            }),
                resolve: async context =>
            {
                var author = context.GetArgument <Author>("author");
                await authorRepository.AddAuthorAsync(author);
                authorMessageService.AddAuthorMessage(author);
                return(author);
            });

            FieldAsync <AuthorType>(
                "updateAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookUpdatedType> > {
                Name = "author"
            }),
                resolve: async context =>
            {
                var author = context.GetArgument <Author>("author");
                await authorRepository.UpdateAuthorAsync(author);
                authorMessageService.UpdateAuthorMessage(author);
                return(author);
            });


            FieldAsync <AuthorType>(
                "deleteAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id     = context.GetArgument <int>("id");
                var author = await authorRepository.GetAuthorAsync(id);
                await authorRepository.DeleteAuthorAsync(author);
                authorMessageService.DeleteAuthorMessage(author);
                return(author);
            });
        }
Ejemplo n.º 6
0
 public async Task AddAuthorAsync([FromBody] Author author)
 {
     await _authorRepository.AddAuthorAsync(author);
 }