package booksshop;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import java.util.*;

public class BooksAction extends Action {
    public ActionForward execute(ActionMapping actionMapping,
                                 ActionForm actionForm,
                                 HttpServletRequest servletRequest,
                                 HttpServletResponse servletResponse) {
       BooksActionForm booksActionForm = (BooksActionForm) actionForm;

       Books obj = new Books();

       if (booksActionForm.getDeleteisbn()!=null) {
           obj.deletebook(booksActionForm.getDeleteisbn());
           return actionMapping.findForward("deletesuccess");
       } else {
               obj.addbook(booksActionForm.getTitle() , booksActionForm.getAuthor(), booksActionForm.getPublisher(), Integer.parseInt(booksActionForm.getPages()), Float.parseFloat(booksActionForm.getPrice()), booksActionForm.getIsbn());
               return actionMapping.findForward("addsuccess");
       }

    }
}
