public async Task <GeneralResponseDto> ReceiveRequest(ReceivePromotionInputDto InputDto) { GeneralResponseDto added = new GeneralResponseDto { status = 2, Message = "Failed" }; bool isExist = await _unitOfWork.Promotion.GetAnyAsync(p => p.MobileNumber == InputDto.MobileNumber); if (!isExist) { //create random id Random rnd = new Random(); int id = rnd.Next(1, rnd.Next(2, 500)) * 10; Promotion promotion = new Promotion { RequestId = id, MobileNumber = InputDto.MobileNumber, Action = InputDto.Action, IsHandled = false, RequestDate = DateTime.Now }; _unitOfWork.Promotion.CreateAsyn(promotion); if (await _unitOfWork.Commit() > default(int)) { added.status = 1; added.Message = "Success"; } } return(added); }
public async Task <GeneralResponseDto> HandleRequest(List <HandlePromotionInputDto> InputDto) { GeneralResponseDto updated = new GeneralResponseDto { status = 2, Message = "fail" }; foreach (var item in InputDto) { bool exists = await _unitOfWork.Promotion.GetAnyAsync(p => p.MobileNumber != item.MobileNumber); if (exists) { Promotion promotion = await _unitOfWork.Promotion.FirstOrDefaultAsync(p => p.MobileNumber == item.MobileNumber); if (promotion != null) { promotion.IsHandled = true; promotion.HandlingDate = DateTime.Now; } } } if (await _unitOfWork.Commit() > default(int)) { updated.status = 1; updated.Message = "Success"; } return(updated); }
public async Task <bool> HandledRequests(List <HandlePromotionInputDTO> inputDtos) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44306/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ////post Method var json = JsonConvert.SerializeObject(inputDtos); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("api/HandleRequests", stringContent); if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(stream); var content = streamReader.ReadToEnd(); if (!string.IsNullOrWhiteSpace(content)) { GeneralResponseDto responseDto = JsonConvert.DeserializeObject <GeneralResponseDto>(content); if (responseDto.status == 1) { return(true); } else { return(false); } } } return(false); } } catch (Exception ex) { WriteToFile(" error : " + ex); return(false); } }
public async Task <IHttpActionResult> HandleRequest(List <HandlePromotionInputDto> inputDto) { GeneralResponseDto result = await _promotionService.HandleRequest(inputDto); return(Ok(result)); }
public async Task <IHttpActionResult> ReceiveRequest(ReceivePromotionInputDto inputDto) { GeneralResponseDto result = await _promotionService.ReceiveRequest(inputDto); return(Ok(result)); }