public void Add(XObject obj, bool checkUploadFile = false) 
 {
     if (obj == null)
         throw new ArgumentNullException("obj", "Can not be null.");
     CurrentOperationType = OperationType.Add;
     var id = ExecuteTemplate<int>(EndPoint.@object, XHttpMethod.POST, obj);
     obj.Id = id;
     if (checkUploadFile)
         CheckNeedUploadFiles(obj);
 }
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     var xObj = new XObject();
     var jsonObj = JObject.Load(reader);
     xObj.Id = (int)jsonObj["object_id"];
     xObj.TypeId = (int)jsonObj["object_type_id"];
     xObj.SchemaId = (int)jsonObj["schema_id"];
     xObj.SetId = (int)jsonObj["set_id"];
     foreach (var property in jsonObj as IDictionary<string, JToken>)
         if (!XField.IsSystemReservedFieldName(property.Key))
             xObj.Fields.Add(new XField(property.Key, property.Value.ToString()));
     return xObj;
 }
 private JObject CreateJObject(XObject xObject)
 {
     var jObj = new JObject();
     jObj.Add("object_type_id", xObject.TypeId);
     switch (FlexiWebService.CurrentOperationType)
     {
         case OperationType.Add:
             jObj.Add("schema_id", xObject.SchemaId);
             jObj.Add("set_id", xObject.SetId);
             break;
         case OperationType.Update:
             jObj.Add("object_id", xObject.Id);
             break;
         default:
             throw new InvalidOperationException("Not define operation type");
     }
     foreach (var xField in xObject.Fields)
         jObj.Add(xField.Name, xField.Value);
     return jObj;
 }
 public void Update(XObject obj, bool checkUploadFile = false)
 {
     if (obj == null)
         throw new ArgumentNullException("obj", "Can not be null.");
     if (obj.Fields == null)
         throw new ArgumentNullException("Fields", "Can not be null.");
     if (obj.Fields.Count == 0)
         return;
     CurrentOperationType = OperationType.Update;
     ExecuteTemplate<bool>(EndPoint.@object, XHttpMethod.PUT, obj);
     if (checkUploadFile)
         CheckNeedUploadFiles(obj);
 }
 private void CheckNeedUploadFiles(XObject obj)
 {
     var fieldsInfo = FieldService.GetAll(obj.TypeId);
     var fieldsOfFileType = fieldsInfo.Where(info => info.Value.OriginType == "image" || info.Value.OriginType == "file").ToDictionary(info => info.Key);
     bool hasFileOrImageField = fieldsOfFileType.Count > 0;
     if (hasFileOrImageField)
         UploadFieldFileOrImage(obj.TypeId, obj.Id, obj.Fields.Where(field => fieldsOfFileType.ContainsKey(field.Name) && !String.IsNullOrEmpty(field.Value)));
 }
        private static XObject CreateXObject(IFlexiWebService service)
        {
            var random = new Random();
            var obj = new XObject { SchemaId = schemaId, SetId = setId, TypeId = typeId };
            var fieldsInfo = service.FieldService.GetAll(typeId, FieldMode.custom);
            foreach (var xFieldInfo in fieldsInfo)
            {
                var fieldInfo = xFieldInfo.Value;
                if (fieldInfo.OriginType == "file")
                {
                    const string fileName = "integration_test_upload_file.txt";
                    obj.Fields.Add(new XField(fieldInfo.Name, fileName));
                    continue;
                }
                if (fieldInfo.OriginType == "image")
                {
                    const string fileName = "importToolFX.ico";
                    obj.Fields.Add(new XField(fieldInfo.Name, fileName));
                    continue;
                }
                if (fieldInfo.IsEnum)
                {
                    var value = fieldInfo.EnumItems.Keys.FirstOrDefault();
                    obj.Fields.Add(new XField(fieldInfo.Name, value));
                    continue;
                }
                if (fieldInfo.IsMandatory && String.IsNullOrEmpty(fieldInfo.DefaultValue))
                {
                    obj.Fields.Add(new XField(fieldInfo.Name, "0"));
                    continue;
                }
                obj.Fields.Add(new XField(fieldInfo.Name, fieldInfo.DefaultValue));
            }
            obj.Fields.Add(new XField("display_name", "New Display Name" + random.Next(100)));

            return obj;
        }