Update model for a sampling point Instruction is not allowed to be updated (because this is a link to a pdf in blob storage)
Ejemplo n.º 1
0
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointUpdateAsync"/>
        /// </summary>
        public Task <SamplingPoint> SamplingPointUpdateAsync(string surveyId, SamplingPoint samplingPoint)
        {
            if (samplingPoint == null)
            {
                throw new ArgumentNullException("samplingPoint");
            }

            var updatedSamplingPoint = new UpdateSamplingPoint
            {
                Name              = samplingPoint.Name,
                Description       = samplingPoint.Description,
                FieldworkOfficeId = samplingPoint.FieldworkOfficeId,
                GroupId           = samplingPoint.GroupId,
                Stratum           = samplingPoint.Stratum
            };

            var uri = new Uri(SurveysApi, $"{surveyId}/{SamplingPointsControllerName}/{samplingPoint.SamplingPointId}");

            return(Client.PatchAsJsonAsync(uri, updatedSamplingPoint)
                   .ContinueWith(
                       responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                   .ContinueWith(
                       stringTask => JsonConvert.DeserializeObject <SamplingPoint>(stringTask.Result))
                   .FlattenExceptions());
        }
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointUpdateAsync"/>
        /// </summary>
        public Task<SamplingPoint> SamplingPointUpdateAsync(string surveyId, SamplingPoint samplingPoint)
        {
            if (samplingPoint == null)
            {
                throw new ArgumentNullException("samplingPoint");
            }

            var updatedSamplingPoint = new UpdateSamplingPoint
            {
                Name = samplingPoint.Name,
                Description = samplingPoint.Description,
                FieldworkOfficeId = samplingPoint.FieldworkOfficeId,
                GroupId = samplingPoint.GroupId,
                Stratum = samplingPoint.Stratum
            };

            string uri = string.Format(@"{0}{1}/{2}/{3}", SurveysApi.AbsoluteUri, surveyId, SamplingPointsControllerName, samplingPoint.SamplingPointId);

            return Client.PatchAsJsonAsync(uri, updatedSamplingPoint)
                         .ContinueWith(
                             responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                         .ContinueWith(
                             stringTask => JsonConvert.DeserializeObject<SamplingPoint>(stringTask.Result))
                         .FlattenExceptions();
        }