public void CreateBook(BookWithAuthorsShort book)
        {
            //book.Tags = new List<TagBusinessModel>();

            //var autlist = book.AuthorsId.Split(',').Select(int.Parse).ToList();
            //var newTagsId = book.TagsId.Split(',').Select(int.Parse).ToList();

            var mapper  = new BookWithAuthorsShortMapper();
            var bookNew = mapper.Map(book);

            foreach (var aut in book.Authors)
            {
                var author = this.uow.Authors.GetById(aut.id);
                bookNew.Authors.Add(author);
            }

            foreach (var tag in book.Tags)
            {
                var t = this.uow.Tags.GetById(tag.id);
                bookNew.Tags.Add(t);
            }

            this.uow.Items.Add(bookNew);
            this.uow.Commit();
            book.Id = bookNew.Id; // updates the book.Id to Id value from DB
        }
        public void CreateBook(BookWithAuthorsShort book)
        {
            //book.Tags = new List<TagBusinessModel>();

            //var autlist = book.AuthorsId.Split(',').Select(int.Parse).ToList();
            //var newTagsId = book.TagsId.Split(',').Select(int.Parse).ToList();

            var mapper = new BookWithAuthorsShortMapper();
            var bookNew = mapper.Map(book);

            foreach (var aut in book.Authors)
            {
                var author = this.uow.Authors.GetById(aut.id);
                bookNew.Authors.Add(author);
            }

            foreach (var tag in book.Tags)
            {
                var t = this.uow.Tags.GetById(tag.id);
                bookNew.Tags.Add(t);
            }

            this.uow.Items.Add(bookNew);
            this.uow.Commit();
            book.Id = bookNew.Id; // updates the book.Id to Id value from DB
        }
        public BookWithAuthorsShort GetBookById(int id)
        {
            var mapper = new BookWithAuthorsShortMapper();
            var item   = this.uow.Items.GetById(id);

            return(mapper.Map(item as Book));
        }
 public void EntityToModelMappingTest()
 {
     
     var book = this.fixture.Create<Book>();
     var bookMapper = new BookWithAuthorsShortMapper();
     var bookModel = bookMapper.Map(book);
     Assert.AreEqual(book.Id, bookModel.Id, "Id is not correct");
     Assert.AreEqual(book.Name, bookModel.Name, "Name is not correct");
     Assert.AreEqual(book.PageCount, bookModel.PageCount, "PageCount is not correct");
     Assert.AreEqual(book.Publisher, bookModel.Publisher, "Publisher is not correct");
     Assert.AreEqual(book.Year, bookModel.Year, "Year is not correct");
     Assert.IsNotNull(bookModel.Authors);
     Assert.IsNotNull(bookModel.Tags);
     Assert.IsNotNull(bookModel.Inventories);
     Assert.IsNotNull(bookModel.ReservedItems);
 }
Exemplo n.º 5
0
        public void ModelToEntityMappingTest()
        {
            var bookModel  = this.fixture.Create <BookWithAuthorsShort>();
            var bookMapper = new BookWithAuthorsShortMapper();
            var book       = bookMapper.Map(bookModel);

            Assert.AreEqual(bookModel.Id, book.Id, "Id is not correct");
            Assert.AreEqual(bookModel.Name, book.Name, "Name is not correct");
            Assert.AreEqual(bookModel.PageCount, book.PageCount, "PageCount is not correct");
            Assert.AreEqual(bookModel.Publisher, book.Publisher, "Publisher is not correct");
            Assert.AreEqual(bookModel.Year, book.Year, "Year is not correct");
            Assert.IsNotNull(book.Authors);
            Assert.IsNotNull(book.Tags);
            Assert.IsNotNull(book.Inventories);
            Assert.IsNotNull(book.ReservedItems);
        }
        public void UpdateBook(BookWithAuthorsShort book)
        {

            //book.Tags = new List<TagBusinessModel>();
            var mapper = new BookWithAuthorsShortMapper();

            //var autlist = book.AuthorsId.Split(',').Select(int.Parse).ToList();
            //var newTagsId = book.TagsId.Split(',').Select(int.Parse).ToList();

            var bookOld = this.uow.Items.GetById(book.Id) as Book;

            bookOld.Authors.Clear();
            bookOld.Tags.Clear();
            
            var bookMapped = mapper.Map(book);

            foreach (var aut in book.Authors)
            {
                var author = this.uow.Authors.GetById(aut.id);
                bookOld.Authors.Add(author);
            }

            foreach (var tag in book.Tags)
            {
                var t = this.uow.Tags.GetById(tag.id);
                bookOld.Tags.Add(t);
            }
            
            bookOld.Name = bookMapped.Name;
            bookOld.PageCount = bookMapped.PageCount;
            bookOld.Publisher = bookMapped.Publisher;
            bookOld.Year = bookMapped.Year;

            this.uow.Items.Update(bookOld);

            this.uow.Commit();
        }
Exemplo n.º 7
0
        public ActionResult Edit(int id)
        {
            var item = this.itemManager.GetItemById(id);

            if (item == null)
            {
                return(this.HttpNotFound());
            }

            if (item is BookBusinessModel)
            {
                Book book = new BookMapper().Map(item as BookBusinessModel);
                BookWithAuthorsShort bookWithAuthors = new BookWithAuthorsShortMapper().Map(book);
                return(this.View("_EditBook", bookWithAuthors));
            }
            else if (item is MagazineBusinessModel)
            {
                return(this.View("_EditMagazine", item as MagazineBusinessModel));
            }
            else
            {
                return(this.View("_EditDisk", item as DiskBusinessModel));
            }
        }
        public void UpdateBook(BookWithAuthorsShort book)
        {
            //book.Tags = new List<TagBusinessModel>();
            var mapper = new BookWithAuthorsShortMapper();

            //var autlist = book.AuthorsId.Split(',').Select(int.Parse).ToList();
            //var newTagsId = book.TagsId.Split(',').Select(int.Parse).ToList();

            var bookOld = this.uow.Items.GetById(book.Id) as Book;

            bookOld.Authors.Clear();
            bookOld.Tags.Clear();

            var bookMapped = mapper.Map(book);

            foreach (var aut in book.Authors)
            {
                var author = this.uow.Authors.GetById(aut.id);
                bookOld.Authors.Add(author);
            }

            foreach (var tag in book.Tags)
            {
                var t = this.uow.Tags.GetById(tag.id);
                bookOld.Tags.Add(t);
            }

            bookOld.Name      = bookMapped.Name;
            bookOld.PageCount = bookMapped.PageCount;
            bookOld.Publisher = bookMapped.Publisher;
            bookOld.Year      = bookMapped.Year;

            this.uow.Items.Update(bookOld);

            this.uow.Commit();
        }
 public List<BookWithAuthorsShort> GetAllBooks()
 {
     var mapper = new BookWithAuthorsShortMapper();
     return this.uow.Items.GetAll().OfType<Book>().Select(mapper.Map).ToList();
 }
 public BookWithAuthorsShort GetBookById(int id)
 {
     var mapper = new BookWithAuthorsShortMapper();
     var item = this.uow.Items.GetById(id);
     return mapper.Map(item as Book);
 }
        public List <BookWithAuthorsShort> GetAllBooks()
        {
            var mapper = new BookWithAuthorsShortMapper();

            return(this.uow.Items.GetAll().OfType <Book>().Select(mapper.Map).ToList());
        }
Exemplo n.º 12
0
        public ActionResult Edit(int id)
        {
            var item = this.itemManager.GetItemById(id);

            if (item == null)
            {
                return this.HttpNotFound();
            }

            if (item is BookBusinessModel)
            {
                Book book = new BookMapper().Map(item as BookBusinessModel);
                BookWithAuthorsShort bookWithAuthors = new BookWithAuthorsShortMapper().Map(book);
                return this.View("_EditBook", bookWithAuthors);
            }
            else if (item is MagazineBusinessModel)
            {
                return this.View("_EditMagazine", item as MagazineBusinessModel);
            }
            else
            {
                return this.View("_EditDisk", item as DiskBusinessModel);
            }
        }