public async Task <CouchDbCreateDocumentResult> PostServiceMachine(MachineBody machineBody) { string database = "machines"; string id = ""; if (!string.IsNullOrEmpty(machineBody.id)) { id = machineBody.id; } else { id = Guid.NewGuid().ToString("N"); } foreach (var macUsers in machineBody.owners) { macUsers.id = Guid.NewGuid().ToString("N"); } foreach (var macApp in machineBody.applications) { macApp.id = Guid.NewGuid().ToString("N"); } CouchDbCreateDocumentResult createResponse = await _couchDbClient.CreateDocumentAsync(database, id, machineBody); return(createResponse); }
public async Task <ActionResult <ServiceManagementResponse> > CreateServiceMachine([FromBody] MachineBody body) { CouchDbCreateDocumentResult postMachine; try { if ((body.owners == null || body.owners.Count == 0) || (body.applications == null || body.applications.Count == 0) || string.IsNullOrEmpty(body.address) || body.port == 0) { return(StatusCode(StatusCodes.Status409Conflict, $"Unable to create machine. \n\nDue to missing parameters")); } postMachine = await ManagementService.PostServiceMachine(body); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Internal Server no issue, from \nMachine: {body}. \n\nException: {e.Message}")); } return(Ok(postMachine.IsSuccessful)); }