Beispiel #1
0
        /// <summary>
        /// <para>Sorts a sheet according to the sort criteria.</para>
        ///
        /// <para>Mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/sort</para>
        /// </summary>
        /// <param name="id"> the sheet Id </param>
        /// <param name="sortSpecifier"> the sort criteria </param>
        /// <returns> the sheet (note that if there is no such resource, this method will throw a ResourceNotFoundException rather than returning null). </returns>
        /// <exception cref="System.InvalidOperationException"> if any argument is null or an empty string </exception>
        /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception>
        /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception>
        /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception>
        /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due to rate limiting) </exception>
        /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception>
        public virtual Sheet SortSheet(long id, SortSpecifier sortSpecifier)
        {
            HttpRequest request = null;

            try
            {
                request = CreateHttpRequest(new Uri(this.Smartsheet.BaseURI, "sheets/" + id + "/sort"), HttpMethod.POST);
            }
            catch (Exception e)
            {
                throw new SmartsheetException(e);
            }

            request.Entity = serializeToEntity <SortSpecifier>(sortSpecifier);

            HttpResponse response = this.Smartsheet.HttpClient.Request(request);

            Object obj = null;

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                obj = this.Smartsheet.JsonSerializer.deserialize <Sheet>(
                    response.Entity.GetContent());
                break;

            default:
                HandleError(response);
                break;
            }

            this.Smartsheet.HttpClient.ReleaseConnection();

            return((Sheet)obj);
        }
        private static void SortSheet(SmartsheetClient smartsheet, long sheetId)
        {
            Sheet         sheet     = smartsheet.SheetResources.GetSheet(sheetId, null, null, null, null, null, null, null);
            SortSpecifier specifier = new SortSpecifier();
            SortCriterion criterion = new SortCriterion();

            criterion.ColumnId     = (long)sheet.Columns[0].Id;
            criterion.Direction    = SortDirection.DESCENDING;
            specifier.SortCriteria = new SortCriterion[] { criterion };
            sheet = smartsheet.SheetResources.SortSheet(sheetId, specifier);
            Assert.AreEqual(sheet.Rows[0].Cells[0].DisplayValue, "C");
        }
        private void TestSortSheet()
        {
            Sheet sheet = CreateSheet();

            SortSpecifier specifier = new SortSpecifier();
            SortCriterion criterion = new SortCriterion();

            criterion.ColumnId     = sheet.Columns[1].Id.Value;
            criterion.Direction    = SortDirection.DESCENDING;
            specifier.SortCriteria = new SortCriterion[] { criterion };
            sheet = smartsheet.SheetResources.SortSheet(sheet.Id.Value, specifier);
            Assert.AreEqual(sheet.Rows[0].Cells[1].DisplayValue, "C");

            DeleteSheet(sheet.Id.Value);
        }