public async Task <dynamic> DeleteAsync(string couponId) { CouponSelectorForId couponSelector = CouponSelectorForId.Build(couponId); using (var client = CloudantClient()) { CouponDto item = null; var response = await client.PostAsync(_dbName + "/_find", new StringContent(JsonConvert.SerializeObject(couponSelector), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); CouponListDto couponList = JsonConvert.DeserializeObject <CouponListDto>(responseJson); if (couponList != null && couponList.docs != null && couponList.docs.Count > 0) { item = couponList.docs[0]; } } if (item != null) { response = await client.DeleteAsync(_dbName + "/" + _urlEncoder.Encode(item._id.ToString()) + "?rev=" + _urlEncoder.Encode(item._rev.ToString())); if (response.IsSuccessStatusCode) { return(true); } string msg = "Failure to DELETE. Status Code: " + response.StatusCode + ". Reason: " + response.ReasonPhrase; Console.WriteLine(msg); } return(false);; } }
public async Task <dynamic> GetByCouponIdAsync(string couponId) { CouponSelectorForId couponSelector = CouponSelectorForId.Build(couponId); using (var client = CloudantClient()) { var response = await client.PostAsync(_dbName + "/_find", new StringContent(JsonConvert.SerializeObject(couponSelector), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); CouponList couponList = JsonConvert.DeserializeObject <CouponList>(responseJson); return(couponList.docs[0]); } string msg = "Failure to GET. Status Code: " + response.StatusCode + ". Reason: " + response.ReasonPhrase; Console.WriteLine(msg); return(new Coupon()); } }