/// <summary> /// Add or update the attachment /// Calls the base class because there may be some generic behavior in it /// </summary> /// <param name="entityId">document id</param> /// <param name="fileName">name of the file</param> /// <param name="attachment">the attachment</param> /// <returns></returns> public override async Task <ILightAttachment> AddOrUpdateAttachmentAsync <T>(string entityId, string fileName, Stream attachment) { await base.AddOrUpdateAttachmentAsync <T>(entityId, fileName, attachment); //Calls the base class because there may be some generic behavior in it _typeToCollectionMap.TryGetValue(typeof(T), out var collection); Document doc = await GetByIdAsync <Document>(entityId); ILightAttachment upserted = GetLightAttachment(entityId, fileName, attachment); Attachment attachmentDB = GetAttachment(upserted); if (_mediaStorage != null) { attachmentDB.MediaLink = null; await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB, new RequestOptions() { PartitionKey = new PartitionKey(Undefined.Value) }); await _mediaStorage.InsertUpdateAsync(upserted); } else { await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB); } return(upserted); }
/// <summary> /// Google Cloud Firestore doesn't support attachments /// </summary> /// <param name="entityId">document id</param> /// <param name="fileName">name of the file</param> /// <param name="attachment">the attachment</param> /// <returns></returns> public override async Task <ILightAttachment> AddOrUpdateAttachmentAsync <T>(string entityId, string fileName, Stream attachment) { await base.AddOrUpdateAttachmentAsync <T>(entityId, fileName, attachment); //Calls the base class because there may be some generic behavior in it ILightAttachment upserted = GetLightAttachment(entityId, fileName, attachment); if (_mediaStorage != null) { _mediaStorage.InsertUpdateAsync(upserted); } return(upserted); }
/// <summary> /// Add or update the attachment /// Calls the base class because there may be some generic behavior in it /// </summary> /// <param name="entityId">document id</param> /// <param name="fileName">name of the file</param> /// <param name="attachment">the attachment</param> /// <returns></returns> public override async Task <ILightAttachment> AddOrUpdateAttachmentAsync <T>(string entityId, string fileName, Stream attachment) { await base.AddOrUpdateAttachmentAsync <T>(entityId, fileName, attachment); //Calls the base class because there may be some generic behavior in it Document doc = await GetByIdAsync <Document>(entityId); ILightAttachment upserted = GetLightAttachment(entityId, fileName, attachment); Attachment attachmentDB = GetAttachment(upserted); if (_mediaStorage != null) { attachmentDB.MediaLink = null; await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB); _mediaStorage.InsertUpdateAsync(upserted); } else { await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB); } return(upserted); }