Exemplo n.º 1
0
        private async Task <HttpResponseMessage> PutRequest(string ContentItemCodeName, string MethodEndPointName)
        {
            string projectId = _configuration.GetValue <string>("ManagementOptions:ProjectId");

            var ids = KontentManagementHelper.GetIdentifiers(ContentItemCodeName);

            //Now build the PUT url
            string url =
                $"{RowlingAppConstants.KontentManagementBetaServiceUrlBase}{projectId}/items/codename/{ids.Item1.Codename}/variants/codename/{ids.Item2.Codename}/{MethodEndPointName}";

            //Commit the request to Kontent
            return(await _httpClient.PutAsync(url, null));
        }
Exemplo n.º 2
0
        public async Task <bool> UpdateTeamAsync(Team TeamToUpdate)
        {
            bool success = false;

            //Get a Kontent Management API client for v1 of the API
            ManagementClient client = _managementService.GetManagementClient();

            //Create identifiers for working with our item
            var ids = KontentManagementHelper.GetIdentifiers(TeamToUpdate.CodeName);

            //Specify fields we want to update in our content item
            Models.Generated.TeamForScore updateModel = new Models.Generated.TeamForScore()
            {
                TeamScore      = new Decimal(TeamToUpdate.TeamScore),
                TeamFramesleft = new Decimal(TeamToUpdate.TeamFramesLeft)
            };

            try
            {
                //Create a new version of the content item in Kontent
                success = await _managementBetaService.CreateContentItemNewVersion(TeamToUpdate.CodeName);

                //Commit the update to Kontent
                await client.UpsertContentItemVariantAsync(ids.Item3, updateModel);

                //Publish the version of the content item in Kontent
                success = await _managementBetaService.PublishContentItem(TeamToUpdate.CodeName);

                //Update the local memory object
                var localTeam = _allTeams.Find(t => t.CodeName == TeamToUpdate.CodeName);
                localTeam.TeamScore      = (int)updateModel.TeamScore;
                localTeam.TeamFramesLeft = (int)updateModel.TeamFramesleft;
            }
            catch (Exception ex)
            {
                //TODO: log the update error
                string message = ex.Message;
            }

            return(success);
        }