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> UpdateBulkAsync(CouponListDto items) { using (var client = CloudantClient()) { var response = await client.PostAsJsonAsync(_dbName + "/_bulk_docs", items); if (response.IsSuccessStatusCode) { return(true); } string msg = "Failure to PUT. Status Code: " + response.StatusCode + ". Reason: " + response.ReasonPhrase; Console.WriteLine(msg); return(false); } }
public async Task <List <CouponDto> > GetWithLimitByTarih(string tarih, int updateCouponCount) { string lotteryTime = tarih.Substring(0, 4) + "/" + tarih.Substring(4, 2) + "/" + tarih.Substring(6, 2); CouponSelectorWithLimitByTarih couponSelector = CouponSelectorWithLimitByTarih.Build(lotteryTime, updateCouponCount); using (var client = CloudantClient()) { var response = await client.PostAsJsonAsync(_dbName + "/_find", couponSelector); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); CouponListDto couponList = JsonConvert.DeserializeObject <CouponListDto>(responseJson); return(couponList.docs); } string msg = "Failure to GET. Status Code: " + response.StatusCode + ". Reason: " + response.ReasonPhrase; Console.WriteLine(msg); return(new List <CouponDto>()); } }
private async Task UpdateUserWinCounts() { Cekilis cekilis = CekilisCache.cekilisList.Last(); if (cekilis == null) { return; } /* * List<User> userList = await _userService.GetPushCekilis(); * if (userList == null || !userList.Any()) * { * CouponUpdateFinished(); * return; * } */ List <CouponDto> couponList = await _couponService.GetWithLimitByTarih(cekilis.tarih, updateCouponCount); if (couponList == null || !couponList.Any()) { CouponUpdateFinished(); return; } foreach (CouponDto couponDto in couponList) { int winCount = GetWinCount(couponDto, cekilis); couponDto.WinCount = winCount; } CouponListDto couponListDto = new CouponListDto(); couponListDto.docs = couponList; await _couponService.UpdateBulkAsync(couponListDto); /* * foreach (var user in userList) * { * List<CouponDto> userCouponList = couponList.Where(c => c.User.Equals(user.user_id)).ToList(); * if (userCouponList == null || !userCouponList.Any()) * { * continue; * } * * foreach (CouponDto couponDto in userCouponList) * { * int winCount = GetWinCount(couponDto, cekilis); * couponDto.WinCount = winCount; * } * * CouponListDto couponListDto = new CouponListDto(); * couponListDto.docs = userCouponList; * await _couponService.UpdateBulkAsync(couponListDto); * * //if (maxWinCount >= 3) * //{ * // PushNotification push = PushNotificationCoupon.Build(maxWinCount, cekilis.tarih_view, user.token); * // await _pushService.SendPush(push); * //} * } */ }