public void AddNewReaderHistory(ReaderHistoryBusinessModel readerHistoryBusiness, int readerId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                this.readerHistoryFacade.GiveBookToStudent(readerHistoryBusiness);
                this.readerHistoryFacade.AddNewReaderHistory(readerHistoryBusiness, readerId);

                scope.Complete();
            }
        }
        public ReaderHistoryMapperTest()
        {
            this.readerHistoryMapper = new ReaderHistoryMapper();

            this.readerEntityToMap = new Reader { FirstName = "Bob", LastName = "Hopkins" };

            this.readerModelToMap = new ReaderBusinessModel { FirstName = "Bob", LastName = "Hopkins" };

            this.inventoryEntityToMap = new Inventory { Number = "0000000001-001" };

            this.inventoryModelToMap = new InventoryBusinessModel { Number = "0000000001-001" };

            this.readerHistoryEntityToMap = new ReaderHistory
            {
                ReaderHistoryId = 1,
                StartDate = Convert.ToDateTime("2013.12.12"),
                ReturnDate = Convert.ToDateTime("2013.12.20"),
                FinishDate = Convert.ToDateTime("2013.12.28"),
                Reader = this.readerEntityToMap,
                Inventory = this.inventoryEntityToMap
            };

            this.readerHistoryEntityToCompareWith = new ReaderHistory
            {
                ReaderHistoryId = 1,
                StartDate = Convert.ToDateTime("2013.12.12"),
                ReturnDate = Convert.ToDateTime("2013.12.20"),
                FinishDate = Convert.ToDateTime("2013.12.28"),
                Reader = this.readerEntityToMap,
                Inventory = this.inventoryEntityToMap
            };
            this.ReaderHistoryModelToMap = new ReaderHistoryBusinessModel
            {
                Id = 1,
                StartDate = Convert.ToDateTime("2013.12.12"),
                ReturnDate = Convert.ToDateTime("2013.12.20"),
                FinishDate = Convert.ToDateTime("2013.12.28"),
                ReaderBusiness = this.readerModelToMap,
                InventoryBusiness = this.inventoryModelToMap
            };
            this.ReaderHistoryModelToCompareWith = new ReaderHistoryBusinessModel
            {
                Id = 1,
                StartDate = Convert.ToDateTime("2013.12.12"),
                ReturnDate = Convert.ToDateTime("2013.12.20"),
                FinishDate = Convert.ToDateTime("2013.12.28"),
                ReaderBusiness = this.readerModelToMap,
                InventoryBusiness = this.inventoryModelToMap
            };
        }
        public void GiveBookToStudent(ReaderHistoryBusinessModel readerHistoryBusinessModel)
        {
            ReaderHistoryMapper readerHistoryMapper = new ReaderHistoryMapper();
            ReaderHistory readerHistory = new ReaderHistory();

            readerHistory = readerHistoryMapper.Map(readerHistoryBusinessModel);

            Inventory inventory = this.uow.Inventories.GetAll().Where(inv => inv.Number == readerHistory.Inventory.Number).Select(inv => inv).Single();

            if (inventory.IsAvailable == true)
            {
                inventory.IsAvailable = false;
            }
            else
            {
                throw new Exception();
            }

            this.uow.Inventories.Update(inventory);
            uow.Commit();

        }
 public void UpdateReaderHistory(ReaderHistoryBusinessModel readerHistoryBusiness)
 {
     this.readerHistoryFacade.UpdateReaderHistory(readerHistoryBusiness);
    
 }
        public void UpdateReaderHistory(ReaderHistoryBusinessModel readerHistoryBusiness)
        {
            ReaderHistoryMapper mapper = new ReaderHistoryMapper();
            ReaderHistory readerHistory = new ReaderHistory();

            readerHistory = mapper.Map(readerHistoryBusiness);
            this.uow.ReadersHistories.Update(readerHistory);

            Inventory inventory = this.uow.Inventories.GetById(readerHistoryBusiness.InventoryBusiness.InventoryId);

            if (inventory.IsAvailable == false)
            {
                if (readerHistoryBusiness.ReturnDate != null)
                {
                    inventory.IsAvailable = true;
                }
                else
                {
                    inventory.IsAvailable = false;
                }
            }
            else
            {
                throw new Exception("This inventory already exist in the Library");
            }

            uow.Commit();
        }
        public ReaderHistoryBusinessModel GetReaderHistoryById(int readerHistoryId)
        {
            ReaderHistoryMapper mapper = new ReaderHistoryMapper();
            ReaderHistoryBusinessModel readerHistoryBusiness = new ReaderHistoryBusinessModel();
            readerHistoryBusiness = mapper.Map(this.uow.ReadersHistories.GetById(readerHistoryId));

            return readerHistoryBusiness;
        }
        public void AddNewReaderHistory(ReaderHistoryBusinessModel readerHistoryBusiness, int readerId)
        {
            ReaderHistoryMapper readerHistoryMapper = new ReaderHistoryMapper();
            ReaderHistory readerHistory = new ReaderHistory();

            readerHistory = readerHistoryMapper.Map(readerHistoryBusiness);
            var reader = uow.Readers.GetById(readerId);
            Inventory inventory = this.uow.Inventories.GetAll().Where(inv => inv.Number == readerHistory.Inventory.Number).Select(inv => inv).Single();

            uow.ReadersHistories.Add(new ReaderHistory
            {
                StartDate = readerHistory.StartDate,
                FinishDate = readerHistory.FinishDate,
                Reader = reader,
                Inventory = this.uow.Inventories.GetById(inventory.InventoryId)

            });
            uow.Commit();
        }