package Controllers;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;








import models.Reminder;
import models.User;
import flexjson.JSONSerializer;
import MVC.Controller;



/**
 * @author Alexander
 *
 */
public class ReminderCtl extends Controller {

	@Override
	public void doRequest(String actionName, Integer id) throws Exception {
		
		EntityManager em = this.getServletContext().getEM();
		
		if(actionName.equals("get")) {	
			List<?> list = em.createNamedQuery("Reminder.findAll").getResultList();
			
			JSONSerializer serializer = new JSONSerializer();
			this.getRequest().setAttribute("json", serializer.serialize(list));

			forward("/json.jsp");
			
		}
		
		if(actionName.equals("edit")) {
			
		}
		if(actionName.equals("delete")) {
			
		}
		if(actionName.equals("add")) {
		    System.out.println(this.getRequest().getParameterMap());
			Reminder r = new Reminder();
			r.setText(getRequest().getParameter("text"));
			r.setFrequency(Byte.parseByte(getRequest().getParameter("frequency")));
			r.setCreationDate(new Date());
			
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			r.setDatestart(formatter.parse(this.getRequest().getParameter("startingat")));

			r.setUser(em.find(User.class, 1));
			
			em.getTransaction().begin();
			em.persist(r);
			em.getTransaction().commit();
		}
		

	}
	
	

}

@@ -922,33 +922,148 @@
 %22delete%22)) %7B%0D%0A%09%09
-%09
+    em.getTransaction().begin();%0D%0A%09%09    em.remove(em.find(Reminder.class, id));%0D%0A%09%09    em.getTransaction().commit();
 %0D%0A%09%09%7D%0D%0A%09%09if(acti

Implement delete action in ReminderCtl