public Mapper() { AuthorMapper = new AuthorMapper(); BookMapper = new BookMapper(); PublisherMapper = new PublisherMapper(); UserMapper = new UserMapper(); }
public async Task <PrintingEditionsModelItem> GetById(long id) { var response = new PrintingEditionsModelItem(); if (id == 0) { response.Errors.Add(ErrorConstants.ModelIsNull); return(response); } var product = await _printingEditionRepository.GetByProductIdAsync(id); if (product == null) { response.Errors.Add(ErrorConstants.ImpossibleToFindProduct); return(response); } var productModel = PrintingEditionMapper.MapEntityToModel(product.PrintingEdition); foreach (var item in product.Authors) { var author = AuthorMapper.MapEntityToModel(item); productModel.Authors.Add(author); } return(productModel); }
public async Task <BaseModel> UpdateAsync(AuthorsModelItem model) { var response = new BaseModel(); if (model == null) { response.Errors.Add(ErrorConstants.ModelIsNull); return(response); } var author = await _authorRepository.GetByIdAsync(model.Id); if (author == null) { response.Errors.Add(ErrorConstants.ImpossibleToFindAuthor); return(response); } var updatedAuthor = AuthorMapper.MapModelToUpdateEntity(author, model); var result = await _authorRepository.UpdateAsync(updatedAuthor); if (!result) { response.Errors.Add(ErrorConstants.ImpossibleToUpdateAuthor); } return(response); }
public void UpdateAuthor(AuthorBusinessModel author) { var mapper = new AuthorMapper(); this.uow.Authors.Update(mapper.Map(author)); this.uow.Commit(); }
public AuthorBusinessModel GetAuthorById(int id) { var mapper = new AuthorMapper(); var author = this.uow.Authors.GetById(id); return(mapper.Map(author)); }
public void CreateAuthor(AuthorBusinessModel author) { var mapper = new AuthorMapper(); var authorNew = mapper.Map(author); this.uow.Authors.Add(authorNew); this.uow.Commit(); author.Id = authorNew.Id;// updates the author.Id to Id value from DB }
// Creates and Author and stores it in the database public void AddAuthor(AddAuthorViewModel viewModel) { var author = AuthorMapper.Map(viewModel); using (var context = this.CreateContext()) { context.Authors.Add(author); context.SaveChanges(); } }
public ActionResult <AuthorDto> GetAuthor([FromRoute] Guid id) { var author = AuthorRepository.GetById(id); if (author == null) { return(NotFound()); } return(Ok(AuthorMapper.ToAuthorDto(author))); }
public async Task <AuthorsModel> GetAuthorsAsync() { var authorModel = new AuthorsModel(); var authors = await _authorRepository.GetAllAsync(); foreach (var author in authors) { var model = AuthorMapper.MapEntityToModel(author); authorModel.Items.Add(model); } return(authorModel); }
public async Task <Author> Handle(GetAuthorByIdQuery request, CancellationToken cancellationToken) { // load from database AuthorEntity entity = await _authorsRepository.GetByIdAsync(request.AuthorId); if (entity is null) { return(null); } return(AuthorMapper.MapToModel(entity)); }
public AuthorMapperTests() { Fixture fixture = new Fixture { RepeatCount = 1 }; fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book))); fixture.Customizations.Add(new TypeRelay(typeof(ItemBusinessModel), typeof(BookBusinessModel))); this.author = fixture.Create<Author>(); this.authorModel = fixture.Create<AuthorBusinessModel>(); this.mapper = new AuthorMapper(); }
public Types.Author NewAuthor(ResolveFieldContext context, AuthorInput author) { if (author == null) { return(null); } var newAuthor = AuthorMapper.ConvertAuthorInputToModelAuthor(author); newAuthor = authorsDataSource.NewAuthor(newAuthor); return(AuthorMapper.ConvertModelAuthorToGraphQLAuthor(newAuthor, null)); }
public ActionResult <AuthorDto> CreateAuthor([FromBody] CreateAuthorDto authorDto) { if (authorDto == null) { return(BadRequest()); } var author = AuthorMapper.ToAuthor(authorDto); AuthorRepository.Create(author); _unitOfWork.Commit(); return(CreatedAtRoute("GetAuthor", new { id = author.Id }, AuthorMapper.ToAuthorDto(author))); }
public async Task <AuthorsModelItem> GetByIdAsync(long id) { var responce = new AuthorsModelItem(); var author = await _authorRepository.GetByIdAsync(id); if (author == null) { responce.Errors.Add(ErrorConstants.ImpossibleToFindAuthor); return(responce); } var authorModel = AuthorMapper.MapEntityToModel(author); return(authorModel); }
public AuthorMapperTests() { Fixture fixture = new Fixture { RepeatCount = 1 }; fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book))); fixture.Customizations.Add(new TypeRelay(typeof(ItemBusinessModel), typeof(BookBusinessModel))); this.author = fixture.Create <Author>(); this.authorModel = fixture.Create <AuthorBusinessModel>(); this.mapper = new AuthorMapper(); }
public async Task <AuthorsModel> GetAllAsync(AuthorsFilteringModel model) { var authorModel = new AuthorsModel(); var filterModel = FilterMapper.MapAuthorsFilteringModel(model); var authors = await _authorRepository.GetFilteredAsync(filterModel); if (authors == null || !authors.Data.Any()) { authorModel.Errors.Add(ErrorConstants.ImpossibleToFindAuthor); } foreach (var author in authors.Data) { var resultModel = AuthorMapper.MapResponseModelToModelItem(author); authorModel.Items.Add(resultModel); } authorModel.TotalCount = authors.TotalItemsCount; return(authorModel); }
public override async Task <IList <AuthorDetailDTO> > GetResultsAsync() { var authors = dbContext.GetCollection <Author>().AsQueryable(); var authorDetails = new List <AuthorDetailDTO>(); foreach (var author in authors) { var bookTitles = dbContext.GetCollection <Book>().AsQueryable() .Where(a => a.AuthorId == (AuthorId)author.Id) .Select(b => b.Title.Value) .ToList(); authorDetails.Add(AuthorMapper.MapTo(author)); } return(authorDetails); }
public async Task <BaseModel> CreateAsync(AuthorsModelItem model) { var response = new BaseModel(); if (model == null) { response.Errors.Add(ErrorConstants.ModelIsNull); return(response); } var author = AuthorMapper.MapModelToEntity(model); var result = await _authorRepository.CreateAsync(author); if (!result) { response.Errors.Add(ErrorConstants.ImpossibleToCreateAuthor); } return(response); }
public Types.Author EditAuthor(int id, AuthorInput author) { if (author == null) { return(null); } var existingAuthor = authorsDataSource.GetAuthor(id); if (existingAuthor == null) { return(null); } existingAuthor.Name = author.Name; existingAuthor.Email = author.Email; var books = booksDataSource.GetBooksByAuthor(id); return(AuthorMapper.ConvertModelAuthorToGraphQLAuthor(existingAuthor, books)); }
public override async Task <IList <AuthorDetailDTO> > GetResultsAsync() { var authorCollection = dbContext.GetCollection <Author>(); var authors = await authorCollection.FindAsync(a => a.Books.Any(bId => bId.BookId == BookId)); var authorDetails = new List <AuthorDetailDTO>(); foreach (var author in authors.ToEnumerable()) { var books = new List <string>(); foreach (var bookRecord in author.Books) { var book = await bookRepository.GetByIdAsync(bookRecord.BookId); books.Add(book.Title.Value); } authorDetails.Add(AuthorMapper.MapTo(author)); } return(authorDetails); }
public List <AuthorBusinessModel> GetAllAuthors() { var mapper = new AuthorMapper(); return(this.uow.Authors.GetAll().Select(mapper.Map).ToList()); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { CategoryMapper.Map(modelBuilder); AuthorMapper.Map(modelBuilder); BookMapper.Map(modelBuilder); }
public AuthorBusinessModel GetAuthorById(int id) { var mapper = new AuthorMapper(); var author = this.uow.Authors.GetById(id); return mapper.Map(author); }
public List<AuthorBusinessModel> GetAllAuthors() { var mapper = new AuthorMapper(); return this.uow.Authors.GetAll().Select(mapper.Map).ToList(); }
public async Task <AuthorDetailDTO> GetById(string id) { var author = await repository.GetByIdAsync(new AuthorId(id)); return(AuthorMapper.MapTo(author)); }
public AuthorService(AuthorMapper authorMapper, IAuthorRepository authorRepository) { _authorMapper = authorMapper; _authorRepository = authorRepository; }
public AuthorRepository(IContext context) { this.Context = context; this.Mapper = new AuthorMapper(context); }
private Author ConvertToGraphQLAuthor(Model.Author modelAuthor, bool includeBooks = false) { var modelBooks = includeBooks ? booksDataSource.GetBooksByAuthor(modelAuthor.Id) : null; return(AuthorMapper.ConvertModelAuthorToGraphQLAuthor(modelAuthor, modelBooks)); }
static void Main(string[] args) { var lMapper = new AuthorMapper(); //Database.InitializeDatabase(); //Database.ClearDatabase(); //Author lAuthor = new Author() { FirstName = "Karel", LastName = "Němec", Dead = new DateTime(2003, 10, 12), Genre = Author.Sex.Male }; //AuthorMapper lMapper = new AuthorMapper(); //int lCount = lMapper.Insert(lAuthor); //Console.WriteLine("Přidáno " + lCount + " záznamů"); //AuthorMapper lMapper = new AuthorMapper(); //var lAllAuthors = lMapper.Select(); //foreach (var lItem in lAllAuthors) //{ // Console.WriteLine(lItem.ToString()); //} //Console.ReadKey(); var lListToInsert = new List<Author>(); foreach (var lCount in Enumerable.Range(0, 69)) { Author lAuthor = GetRandomAuthor(); Thread.Sleep(3); lListToInsert.Add(lAuthor); Console.WriteLine(lAuthor); } foreach (var lAuthor in lListToInsert) { if (lMapper.Insert(lAuthor) != 1) { Console.WriteLine("NEPŘIDÁN: " + lAuthor); } else { Console.WriteLine("PŘIDÁN: " + lAuthor); } } //var lMapper = new AuthorMapper(); //var lItems = lMapper.Select(); //var lDefault = new Author() { FirstName = "Zdeněk", LastName = "Gold", Genre = Author.Sex.Male, Born = new DateTime(1988, 10, 8) }; //foreach (var nItem in lItems) //{ // lDefault.Id = nItem.Id; // if (lMapper.Update(lDefault) != 1) // { // Console.WriteLine(string.Format("Neaktualizovano! {0}",lDefault.ToString())); // } // Console.WriteLine(nItem.Id); //} //var lMapper = new AuthorMapper(); //var lItems = lMapper.Select(); //foreach (var nItem in lItems) //{ // if (lMapper.Delete(nItem) != 1) // { // Console.WriteLine("Neodstraněno! " + nItem.ToString()); // } // Console.WriteLine(nItem.Id); //} lMapper = new AuthorMapper(); Console.WriteLine("Počet záznamů: " + lMapper.GetCount()); }
public void TestInitialize() { _fixture = new Fixture(); _target = new AuthorMapper(); }