public async Task Post([FromBody] Model.Attributes newAttributes) { if (!isValidInput(newAttributes)) { return; } if (!isValidJsonString(newAttributes.Data.ToString())) { return; } if (!await IsAuthorized(newAttributes.URN)) { return; } // start the database Database.Attributes attributesDb = new Database.Attributes(); // this attribute is already there? string existingAttributes = await attributesDb.GetAttributes(newAttributes.URN); if (existingAttributes != null) { // ops, already there base.Response.StatusCode = (int)HttpStatusCode.Conflict; return; } // save await attributesDb.SaveAttributes(newAttributes); }
public async Task Put(string urn, [FromBody] Model.Attributes updatedAttributes) { if (!isValidInput(updatedAttributes)) { return; } if (!isValidJsonString(updatedAttributes.Data.ToString())) { return; } if (!urn.Equals(updatedAttributes.URN)) { base.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } if (!await IsAuthorized(urn)) { return; } // start the database Database.Attributes attributesDb = new Database.Attributes(); /* * should we check if the attribute is there or not? * if is not there, let's just create it then... * * // this attribute is already there? * Model.Attributes existingAttributes = await attributesDb.GetAttributes(urn); * if (existingAttributes == null) * { * // ops, not there yet... * base.Response.StatusCode = (int)HttpStatusCode.BadRequest; * return; * } */ await attributesDb.SaveAttributes(updatedAttributes); }