コード例 #1
0
ファイル: AuthorsController.cs プロジェクト: SweDark/Library
        public async Task <IActionResult> DeleteConfirmed(AuthorDeleteVm vm)
        {
            if (ModelState.IsValid)
            {
                var deleteAuthor = new Author();
                deleteAuthor.Id   = vm.Id;
                deleteAuthor.Name = vm.Name;


                try
                {
                    authorservice.DeleteAuthor(deleteAuthor, vm.BookIds, loanservice.GetAllCurrentLoans());
                    return(RedirectToAction(nameof(Index)));
                }
                catch (OperationCanceledException ex)
                {
                    var test    = ex;
                    var message = ex.Message;

                    ViewBag.message = ("You probably tried to delete an author with a loaned book!");

                    return(RedirectToAction(nameof(Index), new { ex = ViewBag.message }));
                }
                //authorservice.DeleteAuthor(deleteAuthor);
            }
            return(RedirectToAction("Error", "Home", ""));
        }
コード例 #2
0
        public IActionResult Delete(AuthorDeleteVm vm)
        {
            var deletedAuthor = new Author();

            deletedAuthor.ID   = vm.ID;
            deletedAuthor.Name = vm.Name;
            authorService.DeleteAuthor(deletedAuthor);
            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
        // GET: Delete author
        public IActionResult Delete(int id)
        {
            var authorToDelete = authorService.GetAuthorById(id);
            var vm             = new AuthorDeleteVm();

            vm.ID   = id;
            vm.Name = authorToDelete.Name;
            return(View(vm));
        }
コード例 #4
0
ファイル: AuthorsController.cs プロジェクト: SweDark/Library
        //// GET: Authors/Delete/5
        public async Task <IActionResult> Delete(int id)
        {
            if (ModelState.IsValid)
            {
                var vm     = new AuthorDeleteVm();
                var author = authorservice.GetAuthorObject(id);
                vm.Id      = author.Id;
                vm.Name    = author.Name;
                vm.Books   = author.Books;
                vm.BookIds = vm.Books.Select(x => x.ID).ToList();

                return(View(vm));
            }
            return(RedirectToAction("Error", "Home", ""));
        }