コード例 #1
0
        protected override void DoDelete(VisitedPlaceDataObject entity, LambdaExpression securityFilterExpression, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            var    userUri = DataProviderHelper.GetWebIdRootURL(entity.UserProfileUri);
            string visitedPlaceDocumentName = "myvisitedplaces.ttl";
            string visitedPlaceDocumentUri  = $"{userUri}/public/{visitedPlaceDocumentName}";

            StringBuilder sb;
            string        payload = "";

            if (!entity.IsNew)
            {
                // existing entity => we need to delete existing entry, before inserting modified one
                var existingEntity = DoGet(entity, securityFilterExpression, null, context, parameters);

                sb = new StringBuilder();
                sb.AppendLine($":{entity.Id} ");

                sb.AppendLine($"   a <http://generativeobjects.com/apps#VisitedPlace> ;");
                sb.AppendLine($"   <http://schema.org/startDate> \"{existingEntity.Date.ToString("yyyy-MM-dd")}\" ;");
                sb.AppendLine($"   <http://schema.org/description> \"\"\"{existingEntity.Description}\"\"\" ; ");
                sb.AppendLine($"   <http://generativeobjects.com/apps#VisitedPlaceType> \"{existingEntity.Typeofplace.ToString()}\" ; ");

                if (existingEntity.Typeofplace == PlaceTypesEnum.Country && entity.CountryURI != null)
                {
                    sb.AppendLine($"   <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> <{existingEntity.CountryURI}> . ");
                }
                else
                {
                    sb.AppendLine($"   <http://dbpedia.org/ontology/Place> <{existingEntity.PlaceURI}> . ");
                }


                payload += $"DELETE DATA {{{sb.ToString()}}} ";
            }

            var token = DataProviderHelper.GetSolidToken();

            var statusPatch = DataProviderHelper.SendPatch(visitedPlaceDocumentUri, payload, token);

            if (statusPatch != HttpStatusCode.OK)
            {
                throw new GOServerException("Failed to delete the visited place information");
            }
        }