/// <summary> /// Updates the metadata for the specified resource. /// </summary> /// <param name="collectionName">Name of the target collection.</param> /// <param name="memberResourceId">The Id of the member resource.</param> /// <param name="atomEntry">Describes the resource to be modified.</param> /// <returns>A SyndicationItem that describes the updated resource.</returns> /// <exception cref="ArgumentNullException">Throws exception if collectionName is null/empty /// or atomEntry is null.</exception> /// <exception cref="ArgumentException">Throws exception if requested memberResourceId is not a unique identifier.</exception> SyndicationItem IAtomPubStoreWriter.UpdateMemberInfo(string collectionName, string memberResourceId, AtomEntryDocument atomEntry) { if (string.IsNullOrEmpty(collectionName)) { throw new ArgumentNullException("collectionName"); } if (string.IsNullOrEmpty(memberResourceId)) { throw new ArgumentNullException("memberResourceId"); } if (null == atomEntry) { throw new ArgumentNullException("atomEntry"); } using (ZentityContext context = CoreHelper.CreateZentityContext()) { ScholarlyWork resource = (ScholarlyWork)AtomPubHelper.GetMember(context, collectionName, memberResourceId, "Update"); resource.Files.Load(); // Bug Fix : 177689 - AtomPub (M2): Author node is appending after every PUT request instead of overwriting it. resource.Authors.Load(); resource.Contributors.Load(); UpdateResourceProperty(context, resource, atomEntry); context.SaveChanges(); return(ZentityAtomPubStoreReader.GenerateSyndicationItem(this.BaseUri, resource)); } }
/// <summary> /// Gets the specified resource. /// </summary> /// <param name="collectionName">The name of the resource type.</param> /// <param name="memberResourceId">The Guid of the resource to return.</param> /// <returns>A SyndicationItem for the specified resource.</returns> /// <exception cref="ArgumentNullException">Throws exception if collectionName is null/empty.</exception> SyndicationItem IAtomPubStoreReader.GetMember(string collectionName, string memberResourceId) { using (ZentityContext context = CoreHelper.CreateZentityContext()) { ScholarlyWork resource = (ScholarlyWork)AtomPubHelper.GetMember(context, collectionName, memberResourceId, "Read"); return(ZentityAtomPubStoreReader.GenerateSyndicationItem(this.BaseUri, resource)); } }
/// <summary> /// Deletes the specified resource. /// </summary> /// <param name="collectionName">The type of the resource.</param> /// <param name="memberResourceId">The Guid of the resource.</param> /// <returns>True if the operation succeeds, False otherwise.</returns> /// <exception cref="ArgumentNullException">Throws exception if collectionName is null/empty.</exception> /// <exception cref="ArgumentException">Throws exception if requested memberResourceId is not a unique identifier.</exception> bool IAtomPubStoreWriter.DeleteMember(string collectionName, string memberResourceId) { using (ZentityContext context = CoreHelper.CreateZentityContext()) { ScholarlyWork resource = (ScholarlyWork)AtomPubHelper.GetMember(context, collectionName, memberResourceId, "Delete"); // Load to delete all Core.File resource associated to requested scholarlywork. if (!resource.Files.IsLoaded) { resource.Files.Load(); } Zentity.Core.File[] resourceFiles = resource.Files.ToArray(); for (int i = 0; i < resourceFiles.Length; i++) { DeleteRelationships(context, resourceFiles[i]); context.DeleteObject(resourceFiles[i]); } DeleteRelationships(context, resource); // Delete associated Resource propertes resource.ResourceProperties.Load(); List <ResourceProperty> resProperties = resource.ResourceProperties.ToList(); foreach (ResourceProperty property in resProperties) { resource.ResourceProperties.Remove(property); context.DeleteObject(property); } context.DeleteObject(resource); context.SaveChanges(); return(true); } }