예제 #1
0
        public IActionResult Add(Rental rentals)
        {
            var result = _rentalsService.Add(rentals);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public async Task <IActionResult> Create([Bind("Id,StartDate,EndDate,CustomerId,BookId")] Rental rental)
        {
            if (ModelState.IsValid)
            {
                await _rentalsService.Add(rental);

                return(RedirectToAction(nameof(Index)));
            }

            var books = await _booksService.GetAllAvailableAsync();

            var customers = await _customersService.GetAllAsync();

            ViewData["BookId"]     = new SelectList(books, "Id", "Title", rental.BookId);
            ViewData["CustomerId"] = new SelectList(customers, "Id", "FullName", rental.CustomerId);
            return(View(rental));
        }