protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{
		String p;
		if ((p = request.getParameter("delete_id")) != null)
		{
			// del
			Advertisement advertToDelete = this.advertRepo.getById(Integer
					.parseInt(p));
			
			if (advertToDelete.getAdvertiser().getUsername()
					.equals(request.getUserPrincipal().getName()))
			{
				response.getWriter().write(
						"Advert with title " + advertToDelete.getTitle()
								+ " is going to be deleted");
				
				advertRepo.deleteAdvertisement(advertToDelete);
			}
		}
		else if ((p = request.getParameter("sold_id")) != null)
		{
			int id = Integer.parseInt(p);
			
			Advertisement soldAdvert = this.advertRepo.getById(id);
			
			if (soldAdvert != null)
			{
				soldAdvert.setStatus(1); // 0 = unsold, 1 = sold
				this.advertRepo.updateAdvertisement(soldAdvert);
			}
			
			this.getServletContext().getRequestDispatcher("/advertisements")
					.forward(request, response);
			
		}
		else if ((p = request.getParameter("save_id")) != null)
		{
			Advertisement advertToUpdate = this.advertRepo.getById(Integer
					.parseInt(p));
			
			if (advertToUpdate.getAdvertiser().getUsername()
					.equals(request.getUserPrincipal().getName()))
			{				
				String title = request.getParameter("Title");
				String description = request.getParameter("Description");
				String price = request.getParameter("Price");
				
				if (advertToUpdate != null)
				{
					advertToUpdate.setTitle(title);
					advertToUpdate.setDescription(description);
					advertToUpdate.setPrice(price);
					
					this.advertRepo.updateAdvertisement(advertToUpdate);
				}
			}
			
			this.getServletContext().getRequestDispatcher("/advertisements")
					.forward(request, response);
		}
		else
		{
			String title = request.getParameter("Title");
			String description = request.getParameter("Description");
			String price = request.getParameter("Price");
			
			// add new Advert
			Advertisement advertToSave = new Advertisement();
			advertToSave.setTitle(title);
			User advertiser = this.userRepo.getByUsername(request
					.getUserPrincipal().getName());
			
			advertToSave.setAdvertiser(advertiser);
			advertToSave.setPrice(price);
			advertToSave.setDate(new Date().toString().substring(0, 10));
			advertToSave.setDescription(description);
			
			this.advertRepo.addAdvertisement(advertToSave);
			
			request.setAttribute("Advertisement", advertToSave);
			
			getServletContext()
					.getRequestDispatcher("/SingleAdvertisement.jsp").forward(
							request, response);
		}
	}