Adds method to provides a default response for create/update actions
 It saves the record/resource and return response with good status and headers
541174
def save_and_respond(resource, options={}, &block)
      creation = resource.new_record?
      resource.attributes = options[:attributes] unless options[:attributes].nil?
      respond_to do |format|
        # if ((block_given? and block.arity == 1) ? yield(resource) : (block_given? and block.arity == 2) ? yield(resource, format) : resource.save)
        if (block_given? ? yield(resource, format) : resource.save)
          status = (creation ? :created : :ok)
          response.headers["X-Return-Code"] = "success"
          response.headers["X-Saved-Record-Id"] = resource.id.to_s
          format.html { params[:dialog] ? head(status) : redirect_to(options[:url] || resource) }
          format.json { render :json => resource.to_json, :status => status, :location => resource}
          format.xml  { render  :xml => resource.to_xml,  :status => status, :location => resource }
        else
          response.headers["X-Return-Code"] = "invalid"
          format.html { render :action => (resource.new_record? ? "new" : "edit")}
          format.json { render :json => resource.errors.to_json, :status => :unprocessable_entity }
          format.xml  { render  :xml => resource.errors.to_xml,  :status => :unprocessable_entity }
        end
      end
    end
1180146
def get_or_create_from_legacy_response(self, response, **kwargs):
        '''
        
        '''
        response_cls = self.response_class(**kwargs).get_or_create(**kwargs)
        if not getattr(response_cls, self.column):
            setattr(response_cls, self.column, self.accessor(response))
            _action_and_commit(response_cls, session.add)
1102983
protected function OnSuccess()
    {
        $action = Action::Update();
        $isNew = !$this->layout->Exists();
        if ($isNew)
        {
            $action = Action::Create();
            $this->layout->SetUser(self::Guard()->GetUser());
        }
        $oldFile = $isNew ? '' : PathUtil::LayoutTemplate($this->layout);
        $this->layout->SetName($this->Value('Name'));
        $this->layout->Save();
        $logger = new Logger(self::Guard()->GetUser());
        $logger->ReportLayoutAction($this->layout, $action);
        if ($this->CanAssignGroup())
        {
            $this->SaveRights();
        }
        if ($isNew)
        {
            $this->SaveAreas();
        }
        $this->UpdateFiles($oldFile);
        $args = array('layout'=>$this->layout->GetID());
        Response::Redirect(BackendRouter::ModuleUrl(new AreaList(), $args));
    }
931759
public function addAction() {

        $edit_form = $this->container->get("haven_core.category.form_handler")->createNewForm();

        $request = $this->container->get('request_modifier')->setRequest($this->container->get("request"))
                ->slug(array("name"))
                ->getRequest();

        $edit_form->bind($request);

        if ($edit_form->isValid()) {
            $this->container->get("haven_core.category.persistence_handler")->save($edit_form->getData());
            $this->container->get("session")->getFlashBag()->add("success", "create.success");

            return new RedirectResponse($this->container->get('router')->generate(str_replace('update', "list", $this->container->get("request")->get("_route"))));
        }

        $this->container->get("session")->getFlashBag()->add("error", "create.error");

        $template = str_replace(":create.html.twig", ":new.html.twig", $this->container->get("request")->get('_template'));
        $params = array(
            'edit_form' => $edit_form->createView()
        );

        return new Response($this->container->get('templating')->render($template, $params));
    }
751869
def build_response(session_end = true)
      response_object = build_response_object(session_end)
      response = Hash.new
      response[:version] = @version
      response[:sessionAttributes] = @session_attributes unless @session_attributes.empty?
      response[:response] = response_object
      response.to_json
    end
922054
def update
      respond_to do |wants|
        result = resource_get.update_attributes(resource_params)
        call_hook :after_update_attributes, result
        if result
          flash[:notice] = t 'messages.record_updated', model: t("models.#{resource_name}")
          wants.html { redirect_to(resource_get) }
          wants.json  { head :ok }
        else
          wants.html { render :action => "edit" }
          wants.json  { render :json => resource_get.errors, :status => :unprocessable_entity }
        end
      end
    end
466542
protected function OnSuccess()
    {
        $action = Action::Update();
        if (!$this->container->Exists())
        {
            $action = Action::Create();
            $this->container->SetUser(self::Guard()->GetUser());
        }
        $this->container->SetName($this->Value('Name'));
        $this->container->Save();
        
        $logger = new Logger(self::Guard()->GetUser());
        $logger->ReportContainerAction($this->container, $action);
        
        if ($this->CanAssignGroup())
        {
            $this->SaveRights();
        }
        Response::Redirect(BackendRouter::ModuleUrl(new ContainerList()));
    }
155625
def default_action_block
      proc do
        begin
          record = if resource.singular
                    parent_model = resource.parent.model.find(parent_resource_id)
                    parent_model.send resource.name
                  else
                    record = model.find(params[:id])
                  end

          record.update(instance_eval(&@strong_params))
          body record.reload
        rescue ActionController::ParameterMissing => error
          body error.message
          status :bad_request
        end
      end
    end
1152318
public function processUpdateSeoAction()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, $this->getModuleCode(), AccessManager::UPDATE)) {
            return $response;
        }

        // Error (Default: false)
        $error_msg = false;

        // Create the Form from the request
        $updateSeoForm = $this->getUpdateSeoForm($this->getRequest());

        // Pass the object id to the request
        $this->getRequest()->attributes->set($this->objectName . '_id', $this->getRequest()->get('current_id'));

        try {
            // Check the form against constraints violations
            $form = $this->validateForm($updateSeoForm, "POST");

            // Get the form field values
            $data = $form->getData();

            // Create a new event object with the modified fields
            $updateSeoEvent = $this->getUpdateSeoEvent($data);

            // Dispatch Update SEO Event
            $this->dispatch($this->updateSeoEventIdentifier, $updateSeoEvent);

            // Execute additional Action
            $response = $this->performAdditionalUpdateSeoAction($updateSeoEvent);

            if ($response == null) {
                // If we have to stay on the same page, do not redirect to the successUrl,
                // just redirect to the edit page again.
                if ($this->getRequest()->get('save_mode') == 'stay') {
                    return $this->redirectToEditionTemplate($this->getRequest());
                }

                // Redirect to the success URL
                return $this->generateSuccessRedirect($updateSeoForm);
            } else {
                return $response;
            }
        } catch (FormValidationException $ex) {
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
            /*} catch (\Exception $ex) {
                // Any other error
                $error_msg = $ex->getMessage();*/
        }

        // Load object if exist
        if (null !== $object = $this->getExistingObject()) {
            // Hydrate the form abd pass it to the parser
            $changeForm = $this->hydrateObjectForm($object);

            // Pass it to the parser
            $this->getParserContext()->addForm($changeForm);
        }

        if (false !== $error_msg) {
            $this->setupFormErrorContext(
                $this->getTranslator()->trans("%obj SEO modification", array('%obj' => $this->objectName)),
                $error_msg,
                $updateSeoForm,
                $ex
            );

            // At this point, the form has errors, and should be redisplayed.
            return $this->renderEditionTemplate();
        }
    }
1339414
function () {
            var self = this;
            var originalCreateAction = self.options.actions.createAction;
            self.options.actions.createAction = function (postData) {
                return $.Deferred(function ($dfd) {

                    var input = $.extend({}, postData);

                    originalCreateAction.method(input)
                        .done(function (result) {
                            $dfd.resolve({
                                "Result": "OK",
                                "Record": originalCreateAction.recordField ? result[originalCreateAction.recordField] : result,
                                originalResult: result
                            });
                        })
                        .fail(function (error) {
                            self._handlerForFailOnAbpRequest($dfd, error);
                        });
                });
            };
        }
1161358
function responseCallback(response, model, success) {
        // Add response to a hash that will eventually be returned through the promise
        responses[model.cid] = {
            success: success,
            response: response
          };
        // If we have reached the total of number of expected responses, then resolve or reject the promise
        if (responsesFailed + responsesSucceeded === numberOfSaves) {
          if (responsesFailed > 0) {
            // Rollback if any responses have failed
            if (options.rollback) {
              _.each(formModel.getTrackedModels(), function(model) {
                model.set(oldValues[model.cid]);
                if (responses[model.cid].success) {
                  model.save();
                }
              });
            }
            formModel.trigger('save-fail', responses);
            deferred.reject(responses);
          } else {
            formModel.trigger('save-success', responses);
            deferred.resolve(responses);
          }
        }
      }
751436
def users_create_or_update(self, data, **kwargs):
        ""
        api_path = "/api/v2/users/create_or_update.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
348368
def update(self, response, **kwargs):
        '''
        
        '''
        response_cls = self._get_instance(**kwargs)
        if response_cls:
            setattr(response_cls, self.column, self.accessor(response))
            _action_and_commit(response_cls, session.add)
        else:
            self.get_or_create_from_legacy_response(response, **kwargs)
895486
@RequestMapping(path="/{orderId}/status", method = RequestMethod.PUT)
    public ResponseEntity<Order> updateStatus(@PathVariable("orderId") Long orderId, @RequestParam("status") OrderStatus status){
        Order order = orderService.updateStatus(orderId, status);
        if(order != null){
            return new ResponseEntity<Order>(order, HttpStatus.OK);
        }
        return new ResponseEntity<Order>(HttpStatus.NOT_FOUND);
    }
272670
function defaultResponse(response) {
  var level =
    response.status < 300
      ? "info"
      : response.status < 500
        ? "warning"
        : "error";
  this.$emit("formMessage", {
    level: level,
    data: response.data,
    response: response
  });
}
986029
def create
      return false unless new_record?
      run_callbacks :save do
        run_callbacks :create do
          httparty = self.class.post(self.class.index_path, request_options.merge(:body => to_json))
          handle_save_response(httparty)
        end
      end
    end
751993
def add_response(self, response):
        
        key = self.merge_array_field_name
        response_json = response.json()
        value = self.combined_json[key]
        self.combined_json[self.merge_array_field_name] = value + response_json[key]