public function newAdsProductAction($id,Request $request)
    {
    	if(!$this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY') ){
    		return $this->redirectToRoute('fos_user_security_login');
    	}
    	 
    	$formData=new Formdata();
    	$adProduct=new AdsmanagerProduct();
    	$message=new Message();

    	
    	$form=$this->createForm(new AdsmanagerProductType(),$adProduct);
    	if(!$formData->isSetFormat($request))
    	{
    		return $this->render('AdsmanagerBundle:Product:newProductAds.html.twig',array("form"=>$form->createView()));
    	}
    	
    	if(!$formData->isValidFormat($request,$form,$message))
    	{
    		$message->show($this);
    		return $this->render('AdsmanagerBundle:Product:newProductAds.html.twig',array("form"=>$form->createView()));
    		 
    	}
    	
    	$image = $request->files->get('imagen');
    	
    	if(!$formData->isValidImage($image,$form,$adProduct,$message,'name')){
    		$message->show($this);
    		return $this->render('AdsmanagerBundle:Product:newProductAds.html.twig',array("form"=>$form->createView()));
    		 
    	}
    	$price=$request->request->get('price');
    	$adProduct->setPrice(str_replace('.', '', $price));
    	$adProduct->setIdAd($id);
    	$formData->insertData($this,$adProduct);
    	$message->setSuccessMessages("El Producto o servicio ha sido Ingresado Exitosamente.")->show($this);
    	$this->setNameIdImages ( $formData,$adProduct, $image );
    	 
    	if($image){
    		$formData->uploadImages($image,'images/ids/'.$id,$adProduct);
    		$this->resizeImages($id,$adProduct->getImages());
    	}
    	 
    	return $this->redirectToRoute('my_ads');
    }
    public function RateAction(Request $request){
    	
    	if(!$this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY') ){
    		return $this->redirectToRoute('fos_user_security_login');
    	}
    	
    	if (!$request->isXmlHttpRequest()) {
    		return new JsonResponse(array('message' => 'You can access this only using Ajax!'), 400);
    	}
    	
    	$request = $this->container->get('request');
    	$idAd = json_decode($request->request->get('idAd'));
    	$rate = json_decode($request->request->get('rate'));
    	
    	$adsRate=new AdsmanagerAdsRate();
    	$formData=new Formdata();
    	$userId = $this->get('security.context')->getToken()->getUser()->getId();
 	
    	if($this-> isRated($idAd,$userId)){
    		
    		$adsRate=$this->getDoctrine()
    		->getRepository("AdsmanagerBundle:AdsmanagerAdsRate")
    		->find($this->getRatedId($idAd,$userId));
    		$adsRate->setIdUser($userId);
    		$adsRate->setIdAds($idAd);
    		$adsRate->setRate($rate);
    		$formData->updateData($this);
    		$this->setRatedAds($idAd,$this->getRatedAdsValue($idAd));
    		$rated=$this->getRatedAds($idAd);
    		$response = array("code" => 100 , "success" => true ,"rated" => $rated[0]);
    		return new JsonResponse($response);
    	}

    	$adsRate->setIdUser($userId);
    	$adsRate->setIdAds($idAd);
    	$adsRate->setRate($rate);
    	$formData->insertData($this,$adsRate);
    	$this->setRatedAds($idAd,$this->getRatedAdsValue($idAd));
    	$rated=$this->getRatedAds($idAd);
    	$response = array("code" => 100 , "success" => true ,"rated" => $rated[0]);
    	return new JsonResponse($response);

    }