예제 #1
0
        public IActionResult CreateLending(LendingCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Lending = lendingService.CreateLending(model.Lending);
                if (model.Lending == null)
                {
                    TempData["Message"] = "There are not book copies available!";
                }

                lendingService.Commit();

                return(RedirectToAction("Details", "Client", new { id = model.Lending.ClientId }));
            }

            model.SelectClient = clientService.GetClients().Select(c => new SelectListItem
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            });
            model.SelectBook = bookService.GetBooks().Select(b => new SelectListItem
            {
                Text  = b.Title,
                Value = b.Id.ToString()
            });
            model.SelectLibrary = libraryService.GetLibraries().Select(l => new SelectListItem
            {
                Text  = l.Name,
                Value = l.Id.ToString()
            });

            return(View(model));
        }
예제 #2
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                Lending = lendingService.ReturnLentBook(Lending);
                lendingService.Commit();
                TempData["Message"] = "Book returned!";


                return(RedirectToPage("/Clients/ClientDetails", new { id = Lending.ClientId }));
            }

            return(Page());
        }
예제 #3
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                Lending = lendingService.CreateLending(Lending);
                if (Lending == null)
                {
                    TempData["Message"] = "There are not book copies available!";
                    return(RedirectToPage("/Lendings/LendingList"));
                }

                lendingService.Commit();
                Client.Id = Lending.ClientId;

                return(RedirectToPage("/Clients/ClientDetails", new { id = Client.Id }));
            }

            SelectBook = bookService.GetBooks().Select(b => new SelectListItem
            {
                Text  = b.Title,
                Value = b.Id.ToString()
            });
            SelectClient = clientService.GetClients().Select(c => new SelectListItem
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            });
            SelectLibrary = libraryService.GetLibraries().Select(l => new SelectListItem
            {
                Text  = l.Name,
                Value = l.Id.ToString()
            });


            return(Page());
        }