/// <summary> /// The wait async for cloud. /// </summary> /// <param name="entity"> /// The entity. /// </param> /// <param name="targetId"> /// The target id. /// </param> private void WaitAsyncForCloud(CloudRecordModel entity, int targetId) { HttpResponseMessage message = this.cloudService.CreateItem(entity).Result; IList <CloudRecordModel> entities = this.cloudService.GetItems(entity.UserId); int cloudId = FindId(entities, targetId); this.dbService.UpdateCloudId(targetId, cloudId); }
/// <summary> /// Creates a record. UserId is taken from the model. /// </summary> /// <param name="item"> /// The record to create. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public Task <HttpResponseMessage> CreateItem(CloudRecordModel item) { var message = this.httpClient.PostAsync( this.serviceApiUrl + CreateUrl, new StringContent(new JavaScriptSerializer().Serialize(item), Encoding.UTF8, "application/json")); message.Result.EnsureSuccessStatusCode(); return(message); }
public static RecordEntity ToRecordEntity(this CloudRecordModel cloudRecordModel) { return(new RecordEntity() { CloudId = cloudRecordModel.ToDoId, UserId = cloudRecordModel.UserId, IsCompleted = cloudRecordModel.IsCompleted, Name = cloudRecordModel.Name }); }
/// <summary> /// Updates a record. /// </summary> /// <param name="item"> /// The record to update. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <HttpResponseMessage> UpdateItem(CloudRecordModel item) { var httpMessage = this.httpClient.PutAsync( this.serviceApiUrl + UpdateUrl, new StringContent(new JavaScriptSerializer().Serialize(item), Encoding.UTF8, "application/json")); try { httpMessage.Result.EnsureSuccessStatusCode(); } catch (HttpRequestException e) { await Task.Delay(10000); httpMessage = this.httpClient.PutAsync( this.serviceApiUrl + UpdateUrl, new StringContent(new JavaScriptSerializer().Serialize(item), Encoding.UTF8, "application/json")); httpMessage.Result.EnsureSuccessStatusCode(); } return(httpMessage.Result); }
/// <summary> /// The update in cloud async. /// </summary> /// <param name="entity"> /// The entity. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> private Task UpdateInCloudAsync(CloudRecordModel entity) { return(Task.Run(() => this.cloudService.UpdateItem(entity))); }
/// <summary> /// The create in cloud async. /// </summary> /// <param name="entity"> /// The entity. /// </param> /// <param name="targetId"> /// The target Id. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> private Task CreateInCloudAsync(CloudRecordModel entity, int targetId) { return(Task.Run(() => this.WaitAsyncForCloud(entity, targetId))); }