public async Task <HttpResponseMessage> DocPut(string docId) { var json = await ReadJsonAsync(); var putResult = Database.Documents.Put(docId, GetEtag(), json, InnerHeaders.FilterHeadersToObject(), GetRequestTransaction()); return(GetMessageWithObject(putResult, HttpStatusCode.Created)); }
public async Task <HttpResponseMessage> DocsPost() { var json = await ReadJsonAsync(); var id = Database.Documents.Put(null, Etag.Empty, json, InnerHeaders.FilterHeadersToObject(), GetRequestTransaction()); return(GetMessageWithObject(id)); }
public async Task <HttpResponseMessage> DatabasesPut(string id) { if (IsSystemDatabase(id)) { return(GetMessageWithString("System database document cannot be changed!", HttpStatusCode.Forbidden)); } MessageWithStatusCode databaseNameFormat = CheckNameFormat(id, Database.Configuration.DataDirectory); if (databaseNameFormat.Message != null) { return(GetMessageWithString(databaseNameFormat.Message, databaseNameFormat.ErrorCode)); } Etag etag = GetEtag(); string error = CheckExistingDatbaseName(id, etag); if (error != null) { return(GetMessageWithString(error, HttpStatusCode.BadRequest)); } var dbDoc = await ReadJsonObjectAsync <DatabaseDocument>(); if (dbDoc.Settings.ContainsKey("Bundles") && dbDoc.Settings["Bundles"].Contains("Encryption")) { if (!dbDoc.SecuredSettings.ContainsKey(Constants.EncryptionKeySetting) || !dbDoc.SecuredSettings.ContainsKey(Constants.AlgorithmTypeSetting)) { return(GetMessageWithString(string.Format("Failed to create '{0}' database, because of not valid encryption configuration.", id), HttpStatusCode.BadRequest)); } } //TODO: check if paths in document are legal DatabasesLandlord.Protect(dbDoc); var json = RavenJObject.FromObject(dbDoc); json.Remove("Id"); var metadata = (etag != null) ? InnerHeaders.FilterHeadersToObject() : new RavenJObject(); var docKey = "Raven/Databases/" + id; var putResult = Database.Documents.Put(docKey, etag, json, metadata, null); return((etag == null) ? GetEmptyMessage() : GetMessageWithObject(putResult)); }
public async Task <HttpResponseMessage> DatabasesPut(string id) { Etag etag = GetEtag(); if (etag == null) { Tuple <string, HttpStatusCode> databaseNameFormat = CheckDatabaseNameFormat(id); if (databaseNameFormat.Item1 != null) { return(GetMessageWithString(databaseNameFormat.Item1, databaseNameFormat.Item2)); } } var docKey = "Raven/Databases/" + id; string error = CheckDatbaseName(id, etag); if (error != null) { return(GetMessageWithString(string.Format(error, id), HttpStatusCode.BadRequest)); } var dbDoc = await ReadJsonObjectAsync <DatabaseDocument>(); if (dbDoc.Settings.ContainsKey("Bundles") && dbDoc.Settings["Bundles"].Contains("Encryption")) { if (!dbDoc.SecuredSettings.ContainsKey(Constants.EncryptionKeySetting) || !dbDoc.SecuredSettings.ContainsKey(Constants.AlgorithmTypeSetting)) { return(GetMessageWithString(string.Format("Failed to create '{0}' database, becuase of not valid encryption configuration.", id), HttpStatusCode.BadRequest)); } } DatabasesLandlord.Protect(dbDoc); var json = RavenJObject.FromObject(dbDoc); json.Remove("Id"); var metadata = (etag != null) ? InnerHeaders.FilterHeadersToObject() : new RavenJObject(); var putResult = Database.Documents.Put(docKey, etag, json, metadata, null); return((etag == null) ? GetEmptyMessage() : GetMessageWithObject(putResult)); }