                
            }
         }
+        */
+    }
+    func updateSpot(currentbid : Bid, status :Int,  sender: UIButton!)-> Void
+    {
+        let prefQuery = PFQuery(className: "Spot")
+        prefQuery.getObjectInBackgroundWithId(DetailSpot.spotId){
+            (prefObj: PFObject?, error: NSError?) -> Void in
+            if error != nil {
+                self.showmessage("Error on Acceped bid")
+                print(error)
+                
+            } else if let prefObj = prefObj {
+                prefObj["StatusId"] = status
+                if(status == 2) //Accepted
+                {
+                    prefObj["AcctepedBidId"] = currentbid.bidId
+                }
+                prefObj.saveInBackgroundWithTarget(sender, selector: nil)
+                self.showmessage("Successfully Acceped bid")
+                
+            }
+        }
+    }
+    func updateBid(currentbid : Bid, status :Int,  sender: UIButton!)-> Void
+    {
+        let prefQuery = PFQuery(className: "Bid")
+        prefQuery.getObjectInBackgroundWithId(currentbid.bidId){
+            (prefObj: PFObject?, error: NSError?) -> Void in
+            if error != nil {
+                //self.showmessage("Error on Acceped bid")
+                print(error)
+            } else if let prefObj = prefObj {
+                prefObj["StatusId"] = status
+                prefObj.saveInBackgroundWithTarget(sender, selector: nil)
+                //self.showmessage("Successfully Acceped bid")
+                
+            }
+        }
     }
     
         func showmessage ( msg : String) -> Void

        
        if(DetailSpot.StatusId == 2)
        {
            //If any bid Accepted than Spot staus also 2
            cell.btnAccept.enabled = false
            cell.btnReject.enabled = false
        }
        if (bid.StatusId == 4 ||  bid.StatusId == 2)
        {
         cell.btnAccept.enabled = false
         cell.btnReject.enabled = false
            if (bid.StatusId == 4 )
            {
            cell.backgroundColor = UIColor.greenColor()
            }
            
            if ( bid.StatusId == 2)
            {
                cell.backgroundColor = UIColor.redColor()
            }
        }
        cell.btnAccept.addTarget(self, action: "btnAccept_click:", forControlEvents: .TouchUpInside)
        cell.btnReject.addTarget(self, action: "btnReject_click:", forControlEvents: .TouchUpInside)
        cell.btnAccept.tag = indexPath.row

       
        let currentbid : Bid = datas[sender.tag]
        print("btnAccept_click from main  at " + String(sender.tag) + "  value: " + String(currentbid.value))
         self.updateBid(currentbid, status :2,  sender: sender!)
         self.updateSpot(currentbid, status :2,  sender: sender!)
        self.tableView.reloadData()
       /*
        let prefQuery = PFQuery(className: "Spot")
        prefQuery.getObjectInBackgroundWithId(DetailSpot.spotId){
            (prefObj: PFObject?, error: NSError?) -> Void in
