public function deleteAll() { $dbs = new MemberDBS(); if (DB::collection($dbs->getTable())->delete()) { $productDbs = new ProductDBS(); if (DB::collection($productDbs->getTable())->delete()) { return Response::json(array('message' => 'success')); } else { return Response::json(array('message' => 'error')); } } else { return Response::json(array('message' => 'error')); } }
public function deleteMember($key) { $dbs = new MemberDBS(); $doc = $dbs->where('_id', $key)->orWhere('memberName', $key); if (isset($doc->get()[0])) { $data = $doc->get()[0]['Order']; for ($i = 0; $i < count($data); $i++) { $item = $data[$i]; $ProductController = new ProductController(); if (!$ProductController->deleteOrderOfProduct($item['product'], $item['Order_id'])) { return Response::json(array('message' => 'error to update the order in product list')); } } if ($doc->delete()) { return Response::json(array('message' => 'success')); } else { return Response::json(array('message' => 'error to delete member')); } } else { return Response::json(array('message' => 'Member not found')); } }
public function deleteOrder($id) { $dbs = new MemberDBS(); $rd = DB::collection($dbs->getTable())->get(); for ($i = 0; $i < count($rd); $i++) { $mem = $rd[$i]; if (array_key_exists('Order', $mem)) { $data = $mem['Order']; $found = false; $payload = array(); $product = ''; for ($j = 0; $j < count($data); $j++) { $item = $data[$j]; if ($item['Order_id'] == $id) { $found = true; $product = $item['product']; } else { array_push($payload, $item); } } if ($found) { $doc = $dbs->where('_id', $mem['_id']); if ($doc->update(array('Order' => $payload))) { $ProductController = new ProductController(); if ($ProductController->deleteOrderOfProduct($product, $id)) { return Response::json(array('message' => 'success')); } else { return Response::json(array('message' => 'error to update the order in product list')); } } else { return Response::json(array('message' => 'error to update the order in member list')); } } } } return Response::json(array('message' => 'Order not found')); }