public async Task <HttpResponseMessage> Put(string id)
        {
            MessageWithStatusCode nameFormatErrorMsg;

            if (IsValidName(id, SystemConfiguration.Counter.DataDirectory, out nameFormatErrorMsg) == false)
            {
                return(GetMessageWithObject(new
                {
                    Error = nameFormatErrorMsg.Message
                }, nameFormatErrorMsg.ErrorCode));
            }

            if (Authentication.IsLicensedForCounters == false)
            {
                return(GetMessageWithObject(new
                {
                    Error = "Your license does not allow the use of Counters!"
                }, HttpStatusCode.BadRequest));
            }

            var docKey = Constants.Counter.Prefix + id;

            var isCounterStorageUpdate = ParseBoolQueryString("update");
            var counterStorage         = SystemDatabase.Documents.Get(docKey, null);

            if (counterStorage != null && isCounterStorageUpdate == false)
            {
                return(GetMessageWithString($"Counter Storage {id} already exists!", HttpStatusCode.Conflict));
            }

            var dbDoc = await ReadJsonObjectAsync <CounterStorageDocument>().ConfigureAwait(false);

            CountersLandlord.Protect(dbDoc);
            var json = RavenJObject.FromObject(dbDoc);

            json.Remove("Id");

            SystemDatabase.Documents.Put(docKey, null, json, new RavenJObject(), null);

            return(GetEmptyMessage(HttpStatusCode.Created));
        }
Example #2
0
        public async Task <HttpResponseMessage> Put(string id)
        {
            var docKey = "Raven/Counters/" + id;

            bool isCounterStorageUpdate = CheckQueryStringParameterResult("update");

            if (IsCounterStorageNameExists(id) && !isCounterStorageUpdate)
            {
                return(GetMessageWithString(string.Format("Counter Storage {0} already exists!", id), HttpStatusCode.Conflict));
            }

            var dbDoc = await ReadJsonObjectAsync <DatabaseDocument>();

            CountersLandlord.Protect(dbDoc);
            var json = RavenJObject.FromObject(dbDoc);

            json.Remove("Id");

            Database.Documents.Put(docKey, null, json, new RavenJObject(), null);

            return(GetEmptyMessage(HttpStatusCode.Created));
        }