Example #1
0
        public async Task CreateCustomObject()
        {
            var testCustomObjectModel = new CreateCustomObjectRequest <TestCustomObjectModel>();

            testCustomObjectModel.CreateCustomObject = new TestCustomObjectModel();
            testCustomObjectModel.CreateCustomObject.IntegerField = 111;
            testCustomObjectModel.CreateCustomObject.FloatField   = 111.111;
            testCustomObjectModel.CreateCustomObject.BooleanField = true;
            testCustomObjectModel.CreateCustomObject.StringField  = "Test1";
            testCustomObjectModel.CreateCustomObject.ArrayField   = new List <int>()
            {
                123, 123, 123
            };
            testCustomObjectModel.CreateCustomObject.Permissions = new Sdk.Modules.CustomObjectModule.Models.Permissions()
            {
                UpdatePermissions = new Sdk.Modules.CustomObjectModule.Models.UpdatePermissions()
                {
                    AccessState = Sdk.Modules.CustomObjectModule.Models.Access.open
                }
            };
            var response = await this.client.CustomObjectsClient.CreateCustomObjectsAsync(ClassName, testCustomObjectModel);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.Created);
            Assert.IsTrue(response.Result != null);
        }
Example #2
0
        public async Task CreateRelationObject()
        {
            var response = await this.client.CustomObjectsClient.RetriveCustomObjectsAsync <TestCustomObjectModel>(ClassName);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);

            var parentItem = response.Result.Items.First();
            var createCustomObjectRequest = new CreateCustomObjectRequest <TestRelativeObject>();

            createCustomObjectRequest.CreateCustomObject = new TestRelativeObject()
            {
                RelativeString = "This item relative to " + parentItem.Id
            };

            var updateResponse = await this.client.CustomObjectsClient.CreateRelationObjectAsync(ClassName, parentItem.Id, RelativeClassName, createCustomObjectRequest);

            Assert.IsTrue(updateResponse.StatusCode == HttpStatusCode.Created);
            Assert.IsTrue(response.Result != null);
        }
Example #3
0
        public async Task <HttpResponse <T> > CreateCustomObjectsAsync <T>(String className,
                                                                           CreateCustomObjectRequest <T> customObject) where T : BaseCustomObject
        {
            if (className == null)
            {
                throw new ArgumentNullException("className");
            }
            if (customObject == null)
            {
                throw new ArgumentNullException("customObject");
            }

            var requestUri = String.Format(QuickbloxMethods.CreateCustomObjectMethod, className);
            var headers    = RequestHeadersBuilder.GetDefaultHeaders().GetHeaderWithQbToken(this.quickbloxClient.Token);

            //var nameValueCollection = new List<KeyValuePair<String, String>>();
            //var properties = customObject.CreateCustomObject.GetType().GetRuntimeProperties();
            //foreach (var property in properties.Where(p => p.GetCustomAttribute<JsonPropertyAttribute>() != null))
            //{
            //    var jsonProperty = property.GetCustomAttribute<JsonPropertyAttribute>();

            //    var propertyValue = property.GetValue(customObject.CreateCustomObject);
            //    if (propertyValue != null)
            //    {
            //        if (property.PropertyType.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IList)))
            //        {
            //            var items = propertyValue as IEnumerable;
            //            var enumerator = items.GetEnumerator();

            //            StringBuilder stringBuilder = new StringBuilder();
            //            while (enumerator.MoveNext())
            //            {
            //                stringBuilder.Append(enumerator.Current + ",");
            //            }

            //            var pair = new KeyValuePair<string, string>(jsonProperty.PropertyName, stringBuilder.ToString());
            //            nameValueCollection.Add(pair);
            //        }
            //        else
            //        {
            //            var pair = new KeyValuePair<string, string>(jsonProperty.PropertyName, propertyValue.ToString());
            //            nameValueCollection.Add(pair);
            //        }
            //    }

            //}

            //if (customObject.Filter != null)
            //{
            //    requestUri += "?" + UrlBuilder.BuildFilter((FilterAggregator)customObject.Filter);
            //}

            //var updateCustomObject = await HttpService.PutAsync<T, T>(this.quickbloxClient.ApiEndPoint,
            //   requestUri,
            //   customObject.CreateCustomObject,
            //   headers);

            var createFileResponse =
                await HttpService.PostAsync <T, T>(quickbloxClient.ApiEndPoint,
                                                   requestUri,
                                                   customObject.CreateCustomObject,
                                                   headers);

            return(createFileResponse);
        }
Example #4
0
        public async Task <HttpResponse <T> > CreateRelationObjectAsync <T>(String parentClassName, String parentId, String childClassName, CreateCustomObjectRequest <T> createCustomObjectRequest) where T : BaseCustomObject
        {
            if (parentClassName == null)
            {
                throw new ArgumentNullException("parentClassName");
            }
            if (childClassName == null)
            {
                throw new ArgumentNullException("childClassName");
            }
            if (parentId == null)
            {
                throw new ArgumentNullException("parentId");
            }
            if (createCustomObjectRequest == null)
            {
                throw new ArgumentNullException("createCustomObjectRequest");
            }
            if (createCustomObjectRequest.CreateCustomObject == null)
            {
                throw new ArgumentNullException("createCustomObjectRequest.CreateCustomObject");
            }

            var requestUri = String.Format(QuickbloxMethods.CreateRelationMethod, parentClassName, parentId, childClassName);
            var headers    = RequestHeadersBuilder.GetDefaultHeaders().GetHeaderWithQbToken(this.quickbloxClient.Token);

            var nameValueCollection = new List <KeyValuePair <String, String> >();
            var properties          = createCustomObjectRequest.CreateCustomObject.GetType().GetRuntimeProperties();

            foreach (var property in properties.Where(p => p.GetCustomAttribute <JsonPropertyAttribute>() != null))
            {
                var jsonProperty = property.GetCustomAttribute <JsonPropertyAttribute>();

                var propertyValue = property.GetValue(createCustomObjectRequest.CreateCustomObject);
                if (propertyValue != null)
                {
                    if (property.PropertyType.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IList)))
                    {
                        var items      = propertyValue as IEnumerable;
                        var enumerator = items.GetEnumerator();

                        StringBuilder stringBuilder = new StringBuilder();
                        while (enumerator.MoveNext())
                        {
                            stringBuilder.Append(enumerator.Current + ",");
                        }

                        var pair = new KeyValuePair <string, string>(jsonProperty.PropertyName, stringBuilder.ToString());
                        nameValueCollection.Add(pair);
                    }
                    else
                    {
                        var pair = new KeyValuePair <string, string>(jsonProperty.PropertyName, propertyValue.ToString());
                        nameValueCollection.Add(pair);
                    }
                }
            }

            var createRelationResponse = await HttpService.PostAsync <T>(this.quickbloxClient.ApiEndPoint,
                                                                         requestUri,
                                                                         nameValueCollection,
                                                                         headers);

            return(createRelationResponse);
        }