Esempio n. 1
0
        public IActionResult Delete(long idPatron)
        {
            var patronToDelete = patronRepository.FindByID(idPatron);

            if (patronToDelete == null)
            {
                return(NotFound("Could not find patron with id : " + idPatron + ". Please try again with valid id."));
            }
            Patron             patron = patronRepository.Remove(idPatron);
            ICollection <Book> temp   = patron.checkedoutBooks as ICollection <Book>;

            if (patron.patronid == -1)
            {
                return(StatusCode(500, "This patron can not be deleted from database as it has checked out " + temp.Count + " and have not returned"));
            }
            return(Ok("Patron id :" + idPatron + " deleted successfully!"));
        }
Esempio n. 2
0
        public IActionResult Delete(int id)
        {
            var patron = _patronRepository.FindByID(id);

            if (patron == null)
            {
                return(Ok("Patron doesn't exist!"));
            }

            var books = _patronRepository.Remove(id);

            if (books.Count > 0)
            {
                String book = "";
                foreach (Book b in books)
                {
                    book += b.bookid + ",";
                }
                book = book.Substring(0, book.Length - 1);
                return(Ok("Patron not deleted as books with IDs " + book + " not checked out"));
            }
            return(Ok("Patron successfully deleted!"));
        }