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); }
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); } }
// 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)); }
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)); }); }
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); }); }
public async Task AddAuthorAsync([FromBody] Author author) { await _authorRepository.AddAuthorAsync(author); }