def admin_load_subcategory():
    try:
        if admin_login_session() == 'admin':
            category_dao = CategoryDAO()
            category_vo_list = category_dao.view_category()
            return render_template('admin/addSubcategory.html', category_vo_list=category_vo_list)
        else:
            return redirect(url_for('admin_logout_session'))
    except Exception as ex:
        print('admin_view_category route exception occured>>>>>>>>>>', ex)
def admin_edit_subcategory():
    try:
        if admin_login_session() == 'admin':
            subcategory_vo = SubCategoryVO()
            subcategory_dao = SubCategoryDAO()
            category_dao = CategoryDAO()

            subcategory_vo.subcategory_id = request.args.get('subcategoryId')
            subcategory_vo_list = subcategory_dao.edit_subcategory(subcategory_vo)
            category_vo_list = category_dao.view_category()
            return render_template('admin/editSubcategory.html', category_vo_list=category_vo_list,
                                   subcategory_vo_list=subcategory_vo_list)
        else:
            return redirect(url_for('admin_logout_session'))
    except Exception as ex:
        print("in admin_edit_subcategory route exception occured>>>>>>>>>>", ex)
def admin_delete_category():
    try:
        if admin_login_session() == 'admin':

            category_vo = CategoryVO()
            category_dao = CategoryDAO()
            category_vo.category_id = request.args.get('categoryId')
            category_dao.delete_category(category_vo)
            return redirect(url_for('admin_view_category'))

        else:
            return redirect(url_for('admin_logout_session'))

    except Exception as ex:
        flash('Subcategory is connected with this category')
        print("admin_delete_category route exception occured>>>>>>>>>>", ex)
        return redirect(url_for('admin_view_category'))
def admin_update_category():
    try:
        if admin_login_session() == 'admin':

            category_vo = CategoryVO()
            category_dao = CategoryDAO()
            category_vo.category_id = request.form.get('categoryId')
            category_vo.category_name = request.form.get('categoryName')
            category_vo.category_description = request.form.get(
                'categoryDescription')

            category_dao.update_category(category_vo)
            return redirect(url_for('admin_view_category'))

        else:
            return redirect(url_for('admin_logout_session'))

    except Exception as ex:
        print("admin_update_category route exception occured>>>>>>>>>>", ex)