예제 #1
0
        /// <summary>
        /// Call a resource of the APROPLAN API with the GET method
        /// </summary>
        /// <param name="resourceName">The resource name to get</param>
        /// <param name="filter">The filter to apply to the get</param>
        /// <param name="pathToLoad">The linked property to load in the same time</param>
        /// <param name="additionalHeaders">Additional headers to add to the HTTP request</param>
        /// <returns></returns>
        public async Task <HttpResponse> GetRaw(string resourceName, Filter filter, PathToLoad pathToLoad, Guid?projectId = null, IDictionary <String, String> additionalParams = null)
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();

            if (filter != null)
            {
                queryParams.Add("filter", filter.ToString());
            }
            if (pathToLoad != null)
            {
                queryParams.Add("pathtoload", pathToLoad.ToString());
            }
            if (projectId.HasValue)
            {
                queryParams.Add("projectid", projectId.Value.ToString());
            }

            if (additionalParams != null)
            {
                foreach (String key in additionalParams.Keys)
                {
                    queryParams.Add(key, additionalParams[key]);
                }
            }

            return(await Request(ApiRootUrl + resourceName, ApiMethod.Get, queryParams));
        }
예제 #2
0
        /// <summary>
        /// To retrieve an entity by its id
        /// </summary>
        /// <typeparam name="T">The type of entity to retrieve</typeparam>
        /// <param name="id">The id of the entity to retrieve</param>
        /// <param name="pathToLoad">To know which property to load from the entity</param>
        /// <returns>The entity corresponding to the id</returns>
        public async Task <T> GetEntityById <T>(Guid id, Guid?projectId = null, PathToLoad pathToLoad = null, Dictionary <string, string> queryParams = null) where T : Entity
        {
            List <T> entities = await GetEntityList <T>(projectId, Filter.Eq("Id", id), pathToLoad, queryParams);

            if (entities.Count == 1)
            {
                return(entities[0]);
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// To update new entity
        /// </summary>
        /// <typeparam name="T">The type of the entity to update</typeparam>
        /// <param name="entity">The entity to update</param>
        /// <returns>The entity updated</returns>
        public async Task <T> UpdateEntity <T>(T entity, Guid?projectId = null, Filter filter = null, PathToLoad pathToLoad = null, Dictionary <string, string> queryParams = null) where T : Entity
        {
            T[] entities = null;
            if (entity != null)
            {
                entities = new[] { entity };
            }

            if (queryParams == null)
            {
                queryParams = new Dictionary <string, string>();
            }
            if (filter != null)
            {
                queryParams.Add("filter", filter.ToString());
            }
            if (pathToLoad != null)
            {
                queryParams.Add("pathtoload", pathToLoad.ToString());
            }

            T[] newEntities = await UpdateEntities <T>(entities, projectId);

            return(newEntities.Length == 0 ? null : newEntities[0]);
        }
예제 #4
0
        /// <summary>
        /// To retrieve the list of id of a type of entity into APROPLAN depending of a filter, pathtoload and sortorder
        /// </summary>
        /// <typeparam name="T">The type of entity to retrieve</typeparam>
        /// <param name="filter">The filter to apply</param>
        /// <param name="pathToLoad">To know which property to load from the entity</param>
        /// <returns>The list of ids corresponding to criteria</returns>
        public async Task <List <Guid> > GetEntityIds <T>(Guid?projectId = null, Filter filter = null, PathToLoad pathToLoad = null, Dictionary <string, string> queryParams = null) where T : Entity
        {
            string resourceName = GetEntityResourceName <T>(GetEntityResourceType.Ids);
            string res          = (await GetRaw(resourceName, filter, pathToLoad, projectId, queryParams)).Data;
            var    ids          = JsonConvert.DeserializeObject <List <Guid> >(res, new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Local
            });

            return(ids);
        }
예제 #5
0
        /// <summary>
        /// To retrieve a list of entities corresponding to a list of ids
        /// </summary>
        /// <typeparam name="T">The type of entity to retrieve</typeparam>
        /// <param name="ids">The list of id to retrieve of the specific entity type</param>
        /// <param name="pathToLoad">To know which property to load from the entity</param>
        /// <returns>The list of entities corresponding to the list of id</returns>
        public async Task <List <T> > GetEntityByIds <T>(Guid[] ids, Guid?projectId = null, PathToLoad pathToLoad = null, Dictionary <string, string> queryParams = null) where T : Entity
        {
            if (ids.Length == 1)
            {
                T entity = await GetEntityById <T>(ids[0], projectId, pathToLoad, queryParams);

                return(new List <T>()
                {
                    entity
                });
            }
            object[] idsObj = new object[ids.Length];
            int      i      = 0;

            foreach (Guid id in ids)
            {
                idsObj[i++] = id;
            }
            List <T> entities = await GetEntityList <T>(projectId, Filter.In("Id", idsObj), pathToLoad, queryParams);

            return(entities);
        }