예제 #1
0
 public function createRecordAction()
 {
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         $jsonData = $this->getRequest()->getPost('saleRecord');
         $saleRecord = Json::decode($jsonData);
         try {
             $this->saleRecordService->create($saleRecord);
         } catch (ValidationException $e) {
             $resultModel->setErrors($e->getValidationError());
             return $resultModel;
         }
         return $resultModel;
     }
 }
예제 #2
0
 public function createCustomerAction()
 {
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         try {
             $jsonData = $this->params()->fromPost('customer');
             $customer = new Customer(Json::decode($jsonData, Json::TYPE_ARRAY));
             $customer->setCreateTime(new \DateTime());
             //@todo 这一行抛出异常被捕获处理后,会不会执行下一行??
             $this->customerService->create($customer);
         } catch (ValidationException $e) {
             $resultModel->setErrors($e->getValidationError());
             return $resultModel;
         } catch (\Exception $e) {
             $resultModel->addErrors('undefined', $e->getMessage());
             return $resultModel;
         }
         return $resultModel;
     }
 }
예제 #3
0
 public function changePasswordAction()
 {
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         try {
             $jsonData = $this->params()->fromPost('password');
             $data = Json::decode($jsonData);
             $this->accountService->changePassword($this->authenticationService->getIdentity()->getId(), $data->password, $data->newPassword);
         } catch (ValidationException $ve) {
             return $resultModel->setErrors($ve->getValidationError());
         } catch (\Exception $e) {
             return $resultModel->addErrors('error', 'unknow error');
         }
         return $resultModel;
     }
 }