/// <summary> /// Execute PUT request for object /// </summary> /// <param name="id">Posted object id</param> /// <param name="data">Type to put</param> public void Put(string id, IDataGeneratable data) { RestClientService.RestClient.Put($"{UrlResolver.GetUrl(data)}/{id}", data); ObjectToPostId objectCreated = new ObjectToPostId(data, id); RequestHelper.HandleTheResponse("PUT"); Storage.UpdateItem(data.GetType(), objectCreated); }
/// <summary> /// Execute POST request for object /// </summary> /// <param name="data">Type to post</param> public void Post(IDataGeneratable data) { RestClientService.RestClient.Post(UrlResolver.GetUrl(data), data); ObjectToPostId objectCreated = new ObjectToPostId(data, RestClientService.RestClient.PostResponseId); RequestHelper.HandleTheResponse("POST"); Storage.SaveItem(data.GetType(), objectCreated); }
/// <summary> /// Update the stored item /// </summary> /// <param name="objectType">Type of object to update</param> /// <param name="objectCreated">New object with stale id</param> public void UpdateItem(Type objectType, ObjectToPostId objectCreated) { List <ObjectToPostId> listSpecificItems = _dataCreated[objectType]; ObjectToPostId updatedObj = listSpecificItems.First(el => el.PostId == objectCreated.PostId); int index = listSpecificItems.IndexOf(updatedObj); listSpecificItems[index] = objectCreated; _dataCreated[objectType] = listSpecificItems; }
/// <summary> /// Save the posted item /// </summary> /// <param name="objectType">Type of object to save</param> /// <param name="objectCreated">New object with id</param> public void SaveItem(Type objectType, ObjectToPostId objectCreated) { if (_dataCreated.ContainsKey(objectType)) { _dataCreated[objectType].Add(objectCreated); } else { _dataCreated.Add(objectType, new List <ObjectToPostId> { objectCreated }); } }