public async Task <ImageFile> DownloadFile(string id) { int index1 = NthIndexOf(id, ':', 1); int index2 = NthIndexOf(id, ':', 2); string userId = id.Substring(index1 + 1, index2 - index1 - 1); if (VerifyTheToken(userId)) { var hc = CouchDBConnect.GetClient("files"); var response = await hc.GetAsync("/files/" + id); if (!response.IsSuccessStatusCode) { return(null); } var content = await response.Content.ReadAsStringAsync(); ImageFile file = (ImageFile)JsonConvert.DeserializeObject(content, typeof(ImageFile)); return(file); } else { return(null); } }
public async Task <int> Delete(string id) { int index1 = NthIndexOf(id, ':', 1); int index2 = NthIndexOf(id, ':', 2); string userId = id.Substring(index1 + 1, index2 - index1 - 1); if (VerifyTheToken(userId)) { var hc = CouchDBConnect.GetClient("files"); ImageFile imageRemove = null; imageRemove = await DownloadFile(id); if (imageRemove != null) { string uri = "/files/" + id + "?rev=" + imageRemove._rev; var response = await hc.DeleteAsync(uri); if (!response.IsSuccessStatusCode) { return(-1); } return(1); } return(-1); } else { return(-1); } }
//Validate if userSubscriptions exist async Task <UserSubscriptions> DoesSubscriptionExist(string id) { var httpClient = CouchDBConnect.GetClient("subscriptions"); var response = await httpClient.GetAsync("subscriptions/" + id); return(response.IsSuccessStatusCode ? (UserSubscriptions)JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync(), typeof(UserSubscriptions)) : null); }
[Route("GetList/{id}")] //all image by id (user) public async Task <IEnumerable <ImageFile> > GetList(string id) { if (VerifyTheToken(id)) { var hc = CouchDBConnect.GetClient("files"); List <ImageFile> imagesList = new List <ImageFile>(); var query = "/files/_all_docs?startkey=\"userid:" + id + ":\"&endkey=\"userid:" + id + ":\uffff\"&include_docs=true"; var response = await hc.GetAsync(query); if (!response.IsSuccessStatusCode) { return(null); } await GetListFromDB(imagesList, response); return(imagesList); } else { return(null); } }