Exemple #1
0
        public async Task <IActionResult> GetAllAsync(string expand = null)
        {
            IEnumerable <LendingRecord> records = await LendingService.GetAllRecordsAsync();

            var resourceCollection = await RecordAssembler.ConvertToResourceCollectionAsync(records, expand);

            return(new ObjectResult(resourceCollection));
        }
Exemple #2
0
        public void SetUp()
        {
            loanRepository   = Mock.Of <ILoanRepository>();
            bookRepository   = Mock.Of <IBookRepository>();
            lendeeRepository = Mock.Of <ILendeeRepository>();

            sut = new LendingService(bookRepository, lendeeRepository, loanRepository);
        }
Exemple #3
0
 //
 // GET: /Book/
 public BookController(
     //BookMetadataService bookMetadataService,
     //BookService bookService,
     )
 {
     this.bookMetadataService  = new BookMetadataService();
     this.bookService          = new BookService();
     this.viewmodelTransalator = new BookViewModelTransalator();
     this.lendingService       = new LendingService();
 }
Exemple #4
0
        public async Task <IActionResult> GetByIdAsync(string id, string expand = null)
        {
            var record = await LendingService.GetByIdAsync(id);

            if (record == null)
            {
                return(HttpNotFound());
            }

            var resource = await RecordAssembler.ConvertToResourceAsync(record, expand);

            return(new ObjectResult(resource));
        }
Exemple #5
0
        public void GivenABookDBAndAUserDBWithALendingService_WhenLendBook_ThenAddInfoToLendingDB()
        {
            //Given
            LendingService lendingService = new LendingService();

            //When
            var actualbool = lendingService.LendBook("1111111111111", "123456");
            var actualData = DB_Lending.Lendings.FirstOrDefault(lend => lend.INSS == "1111111111111");

            //Then
            Assert.True(actualbool);
            Assert.Equal("1111111111111", actualData.INSS);
        }
        public async Task <IHttpActionResult> CheckinAsync(string bookId)
        {
            try
            {
                var lendingRecord = await LendingService.CheckinAsync(bookId);

                var resource = await RecordAssembler.ConvertToResourceAsync(lendingRecord);

                return(Ok(resource));
            }
            catch (DomainOperationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (InvalidOperationException)
            {
                return(BadRequest("that book is already checked in"));
            }
        }
        public async Task <IHttpActionResult> CheckoutAsync(string bookId)
        {
            try
            {
                var lendingRecord = await LendingService.CheckoutAsync(bookId);

                var resource = await RecordAssembler.ConvertToResourceAsync(lendingRecord);

                return(CreatedAtRoute(Startup.DefaultRouteName, new { controller = "lendingRecord", id = lendingRecord.Id }, resource));
            }
            catch (DomainOperationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (InvalidOperationException)
            {
                return(BadRequest("that book is already checked out"));
            }
        }