Beispiel #1
0
        public static ResponseModels.AFElement Convert(LazyObjects.AFElement element)
        {
            ResponseModels.AFElement result = new ResponseModels.AFElement(element.ID, element.WebID, element.Name, element.Description, element.Path);

            //result.TemplateName = element.Template.Name;
            //result.CategoryNames = element.Categories.ToList();

            return(result);
        }
        public bool CreateElement(LazyPI.Common.Connection Connection, string DatabaseID, LazyPI.LazyObjects.AFElement Element)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/assetdatabases/{webId}/elements", Method.POST);

            request.AddUrlSegment("webId", DatabaseID);
            ResponseModels.AFElement body = DataConversions.Convert(Element);
            request.AddParameter("application/json; charset=utf-8", Newtonsoft.Json.JsonConvert.SerializeObject(body), ParameterType.RequestBody);

            var statusCode = webConnection.Client.Execute(request).StatusCode;

            return((int)statusCode == 204);
        }
        // These functions have direct references to WebAPI calls
        #region "Public Methods"
        public LazyObjects.AFElement Find(LazyPI.Common.Connection Connection, string ElementID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elements/{webId}");

            request.AddUrlSegment("webId", ElementID);

            var response = webConnection.Client.Execute <LazyPI.WebAPI.ResponseModels.AFElement>(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error finding element by ID. (See Inner Details)", response.ErrorException);
            }

            ResponseModels.AFElement data = response.Data;
            return(new LazyObjects.AFElement(Connection, data.WebId, data.Id, data.Name, data.Description, data.Path));
        }
        public bool Update(LazyPI.Common.Connection Connection, LazyObjects.AFElement Element)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elements/{webId}", Method.PATCH);

            request.AddUrlSegment("webId", Element.ID);

            ResponseModels.AFElement temp = new ResponseModels.AFElement();
            temp.WebID         = Element.ID;
            temp.Name          = Element.Name;
            temp.Description   = Element.Description;
            temp.Path          = Element.Path;
            temp.CategoryNames = Element.Categories.ToList();
            temp.TemplateName  = Element.Template.Name;

            request.AddBody(temp);

            var statusCode = webConnection.Client.Execute(request).StatusCode;

            return((int)statusCode == 204);
        }
        public bool Update(LazyPI.Common.Connection Connection, LazyObjects.AFElement Element)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
                var request = new RestRequest("/elements/{webId}", Method.PATCH);
                request.AddUrlSegment("webId", Element.ID);

                ResponseModels.AFElement temp = new ResponseModels.AFElement();
                temp.WebID = Element.ID;
                temp.Name = Element.Name;
                temp.Description = Element.Description;
                temp.Path = Element.Path;
                temp.CategoryNames = Element.Categories.ToList();
                temp.TemplateName = Element.Template.Name;

                request.AddBody(temp);

                var statusCode = webConnection.Client.Execute(request).StatusCode;

                return ((int)statusCode == 204);
        }