public static LatchOperationDto ToDto(this LatchOperation operation) { var dto = new LatchOperationDto { Id = operation.Id, OperationId = operation.OperationId, Name = operation.Name, Type = operation.Type, Action = operation.Action, ApplyToAllUsers = operation.ApplyToAllUsers, ApplyToAllNodes = operation.ApplyToAllNodes }; if (operation.UserIds != null && operation.UserIds.Any()) { dto.Users.AddRange(operation.UserIds.Select(x => new LatchOperationUserDto { Id = x })); } if (operation.NodeIds != null && operation.NodeIds.Any()) { dto.Nodes = operation.NodeIds; } return(dto); }
public UmbracoLatchResponse CreateOperation(LatchOperationRequestModel operation) { if (!AccountIsPaired) { var errorMessage = GetResponseMessage("accountUnpaired"); return(new UmbracoLatchResponse(false, errorMessage)); } var application = GetApplication(); var latch = new Latch(application.ApplicationId, application.Secret); var response = latch.CreateOperation(application.ApplicationId, operation.Name); if (response.Error != null) { var errorMessage = GetResponseMessage("error" + response.Error.Code); return(new UmbracoLatchResponse(false, errorMessage)); } if (response.Data == null || !response.Data.ContainsKey("operationId")) { var errorMessage = GetResponseMessage("createError"); return(new UmbracoLatchResponse(false, errorMessage)); } var latchOperation = new LatchOperation { Name = operation.Name, OperationId = response.Data["operationId"] as string, Type = operation.Type, Action = operation.Action, ApplyToAllUsers = operation.ApplyToAllUsers, ApplyToAllNodes = operation.ApplyToAllNodes }; latchRepo.InsertOperation(latchOperation, operation.Users, operation.Nodes); var successMessage = GetResponseMessage("createSuccess"); return(new UmbracoLatchResponse(true, successMessage)); }