예제 #1
0
 public Mapper()
 {
     AuthorMapper    = new AuthorMapper();
     BookMapper      = new BookMapper();
     PublisherMapper = new PublisherMapper();
     UserMapper      = new UserMapper();
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public void UpdateAuthor(AuthorBusinessModel author)
        {
            var mapper = new AuthorMapper();

            this.uow.Authors.Update(mapper.Map(author));
            this.uow.Commit();
        }
예제 #5
0
        public AuthorBusinessModel GetAuthorById(int id)
        {
            var mapper = new AuthorMapper();
            var author = this.uow.Authors.GetById(id);

            return(mapper.Map(author));
        }
예제 #6
0
 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
 }
예제 #7
0
        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
        }
예제 #8
0
        // 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();
            }
        }
예제 #9
0
        public ActionResult <AuthorDto> GetAuthor([FromRoute] Guid id)
        {
            var author = AuthorRepository.GetById(id);

            if (author == null)
            {
                return(NotFound());
            }

            return(Ok(AuthorMapper.ToAuthorDto(author)));
        }
예제 #10
0
        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));
        }
예제 #12
0
        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();
        }
예제 #13
0
        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));
        }
예제 #14
0
        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)));
        }
예제 #15
0
        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);
        }
예제 #16
0
        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();
        }
예제 #17
0
        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);
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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));
        }
예제 #21
0
        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);
        }
예제 #22
0
        public List <AuthorBusinessModel> GetAllAuthors()
        {
            var mapper = new AuthorMapper();

            return(this.uow.Authors.GetAll().Select(mapper.Map).ToList());
        }
예제 #23
0
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     CategoryMapper.Map(modelBuilder);
     AuthorMapper.Map(modelBuilder);
     BookMapper.Map(modelBuilder);
 }
예제 #24
0
 public AuthorBusinessModel GetAuthorById(int id)
 {
     var mapper = new AuthorMapper();
     var author = this.uow.Authors.GetById(id);
     return mapper.Map(author);
 }
예제 #25
0
 public void UpdateAuthor(AuthorBusinessModel author)
 {
     var mapper = new AuthorMapper();
     this.uow.Authors.Update(mapper.Map(author));
     this.uow.Commit();
 }
예제 #26
0
 public List<AuthorBusinessModel> GetAllAuthors()
 {
     var mapper = new AuthorMapper();
     return this.uow.Authors.GetAll().Select(mapper.Map).ToList();
 }
예제 #27
0
        public async Task <AuthorDetailDTO> GetById(string id)
        {
            var author = await repository.GetByIdAsync(new AuthorId(id));

            return(AuthorMapper.MapTo(author));
        }
예제 #28
0
 public AuthorService(AuthorMapper authorMapper, IAuthorRepository authorRepository)
 {
     _authorMapper     = authorMapper;
     _authorRepository = authorRepository;
 }
예제 #29
0
 public AuthorRepository(IContext context)
 {
     this.Context = context;
     this.Mapper  = new AuthorMapper(context);
 }
예제 #30
0
        private Author ConvertToGraphQLAuthor(Model.Author modelAuthor, bool includeBooks = false)
        {
            var modelBooks = includeBooks ? booksDataSource.GetBooksByAuthor(modelAuthor.Id) : null;

            return(AuthorMapper.ConvertModelAuthorToGraphQLAuthor(modelAuthor, modelBooks));
        }
예제 #31
0
        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());
        }
예제 #32
0
        public void TestInitialize()
        {
            _fixture = new Fixture();

            _target = new AuthorMapper();
        }