コード例 #1
0
        /// <inheritdoc />
        public ResourceModel Save(ResourceModel model)
        {
            var converter = new ModelToResourceConverter(Graph, Serialization);

            var resourcesToSave = new HashSet <Resource>();

            // Get or create resource
            converter.FromModel(model, resourcesToSave);

            // Save all created or altered resources
            foreach (var resourceToSave in resourcesToSave)
            {
                Graph.Save(resourceToSave);
            }

            return(model);
        }
コード例 #2
0
        public ResourceModel Save(ResourceModel model)
        {
            return(ExecuteCall <ResourceModel>(delegate
            {
                var converter = new ModelToResourceConverter(Graph, Serialization);

                var resourcesToSave = new HashSet <Resource>();
                // Get or create resource
                var instance = converter.FromModel(model, resourcesToSave);

                // Save all created or altered resources
                foreach (var resourceToSave in resourcesToSave)
                {
                    Graph.Save(resourceToSave);
                }

                return new ResourceToModelConverter(TypeTree, Serialization).GetDetails(instance);
            }));
        }
コード例 #3
0
        public ResourceModel Update(string idString, ResourceModel model)
        {
            return(ExecuteCall <ResourceModel>(delegate
            {
                var resourcesToSave = new HashSet <Resource>();
                var converter = new ModelToResourceConverter(Graph, Serialization);

                Resource resource;
                if (!long.TryParse(idString, out var id) || (resource = Graph.Get(id)) == null)
                {
                    return RequestResult <ResourceModel> .NotFound($"Resource {idString} not found!");
                }

                // Get or create resource
                converter.FromModel(model, resourcesToSave, resource);

                // Save all created or altered resources
                foreach (var resourceToSave in resourcesToSave)
                {
                    Graph.Save(resourceToSave);
                }

                return new ResourceToModelConverter(TypeTree, Serialization).GetDetails(resource);
            }));