function copy(value) {
    var result = value;
    if (value && typeof(value) === "object") {
      if (value instanceof Array) {
        result = copyArray(value);
      } else if (value instanceof Entity) {
        result = value.copy();
      }else{
        //TODO Might be throwing error instead, because in this case nested Entity objects will become ordinary objects.
        result = angular.copy(value);
      }
    }
    return result;
  }
// inner function to detect type of property value -- simple or complex

inner function to detect type of property value -- simple or complex
inner function to detect type of property value -- simple or complex
function copy(value) {
    var result = value;
    if (value && typeof(value) === "object") {
      if (value instanceof Array) {
        result = copyArray(value);
      } else if (value instanceof Entity) {
        result = value.copy();
      }else{
        result = angular.copy(value);
      }
    }
    return result;
  }
function copy ( value ) { var result = value ; if ( value && typeof ( value ) === "object" ) { if ( value instanceof Array ) { result = copyArray ( value ) ; } else if ( value instanceof Entity ) { result = value . copy ( ) ; } else { result = angular . copy ( value ) ; } } return result ; }
inner function to detect type of property value -- simple or complex
inner function to detect type of property value -- simple or complex
//TODO Might be throwing error instead, because in this case nested Entity objects will become ordinary objects.
