private void AssignNewIdentityTo <T>(T entity) { PropertyInfo idProp = FindUniqueIdProperty <T>(); //found prop try { object newId = _idGenerator.New(); idProp.SetValue(entity, newId, null); } catch (Exception ex) { string msg = String.Format("Error setting identity property. Type mismatch: {0}", ex.Message); throw new Exception(msg); } }
/// <summary> /// /// </summary> /// <param name="tenantId"></param> /// <param name="handle"></param> /// <param name="fatherHandle">Different from null only when you want to upload /// a document that is an attachment of another document</param> /// <param name="fatherHandleDescriptorId">Descriptor id that contains reference /// to <paramref name="fatherHandle"/></param> /// <returns></returns> private async Task <HttpResponseMessage> InnerUploadDocument( TenantId tenantId, DocumentHandle handle, DocumentHandle fatherHandle, DocumentDescriptorId fatherHandleDescriptorId) { var documentId = _identityGenerator.New <DocumentDescriptorId>(); Logger.DebugFormat("Incoming file {0}, assigned {1}", handle, documentId); var errorMessage = await UploadFromHttpContent(Request.Content); Logger.DebugFormat("File {0} processed with message {1}", _blobId, errorMessage ?? "OK"); if (errorMessage != null) { return(Request.CreateErrorResponse( HttpStatusCode.BadRequest, errorMessage )); } CreateDocument(documentId, _blobId, handle, fatherHandle, fatherHandleDescriptorId, _fileName, _customData); Logger.DebugFormat("File {0} uploaded as {1}", _blobId, documentId); var storedFile = _blobStore.GetDescriptor(_blobId); return(Request.CreateResponse( HttpStatusCode.OK, new UploadedDocumentResponse { Handle = handle, Hash = storedFile.Hash, HashType = "md5", Uri = Url.Content("/" + tenantId + "/documents/" + handle) } )); }