public GCCMotoInsuranceModel CreateOne(GCCMotoInsuranceModel obj) { try { obj.CreateDate = Convert.ToDateTime(DateTime.Now.ToLocalTime()); _collection.InsertOne(obj); return(obj); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(null); } }
private dynamic HttpRequest(string Url, dynamic Method, string key, GCCMotoInsuranceModel body) { try { var client = new RestClient(Url); var request = new RestRequest(Method); if (body != null) { string[] images = {}; dynamic motoInfo = new { info = new { bsx = body.data.info.bsx, sokhung = body.data.info.sokhung, somay = body.data.info.somay }, images = body.data.images != null ? body.data.images : images }; string data = JsonConvert.SerializeObject(motoInfo); string package = JsonConvert.SerializeObject(body.package); request.AlwaysMultipartFormData = true; request.AddParameter("product_code", body.product_code); request.AddParameter("agency_id", body.agency_id); request.AddParameter("program", body.program); request.AddParameter("package", package); request.AddParameter("request_code", body.request_code); request.AddParameter("buy_fullname", body.buy_fullname); request.AddParameter("buy_bod", body.buy_bod); request.AddParameter("buy_address", body.buy_address); request.AddParameter("buy_phone", body.buy_phone); request.AddParameter("buy_cmnd", body.buy_cmnd); request.AddParameter("buy_email", body.buy_email); request.AddParameter("buy_gender", body.buy_gender); request.AddParameter("url_callback", body.url_callback); request.AddParameter("data", data); } IRestResponse response = client.Execute(request); return(JsonConvert.DeserializeObject <dynamic>(response.Content)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(null); } }
public long UpdateOne(GCCMotoInsuranceModel noti) { long updateCount = 0; try { updateCount = _collection.ReplaceOne(c => c.Id == noti.Id, noti).ModifiedCount; } catch (Exception ex) { updateCount = -1; _logger.LogError(ex, ex.Message); } return(updateCount); }
public dynamic SendInfo(string key, GCCMotoInsuranceModel body) { try { var url = Url.GCC_BASE_URL + string.Format(Url.GCC_PUSH_DATA, ConfigRequest.GCC_CLIENT_SECRET, key); dynamic request = HttpRequest(url, Method.POST, key, body); if (request != null && request.code != null) { return(request); } else { return(null); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(null); } }
public ActionResult <ResponseContext> MotoInsurance(GCCMotoInsuranceModel body) { try { var response = new ResponseContext { code = (int)Common.ResponseCode.ERROR, message = "", data = null }; var product = _gccProductService.FindOneByProductName(body.product_name); if (product != null) { var currProgram = _gccMotoProgramService.FindProgramByTitle(body.programTitle); var currMoto = _gccMotoProgramService.FindMotoByName(body.package.motoName); if (currProgram != null && currMoto != null) { body.state = GccState.NEW; body.program = currProgram.name; body.agency_id = product.agency_id; body.product_code = product.product_code; body.package.motorcycle_id = currMoto.motoId.ToString(); body.buy_gender = body.buy_gender == "Nam" ? "m" : "f"; body.request_code = ConfigRequest.GCC_REQUEST_CODE + DateTime.Now.ToString("yyyyMMddHHmmssffff"); body.url_callback = ConfigRequest.GCC_CALLBACK + "?requestCode=" + body.request_code; var currPerson = _gccMotoService.CreateOne(body); if (currPerson != null) { var token = _gccService.GetToken(); if (!string.IsNullOrEmpty(token)) { var sendObj = _gccMotoService.SendInfo(token, currPerson); if (sendObj != null) { switch ((int)sendObj.code) { case 200: currPerson.state = GccState.SENT_TO_GCC_SUCCEESS; currPerson.link = sendObj.result.payment; response.data = new { link = sendObj.result.payment }; response.code = (int)Common.ResponseCode.SUCCESS; response.message = GCCMessage.SUCCESS; break; case 201: currPerson.state = GccState.SENT_TO_GCC_ERROR; currPerson.message = response.message = GCCMessage.RESPONSE_DUPLICATE; break; case 400: currPerson.state = GccState.SENT_TO_GCC_ERROR; currPerson.message = response.message = string.Format(GCCMessage.RESPONSE_ERROR, sendObj.message); break; } _gccMotoService.UpdateOne(currPerson); } else { response.message = GCCMessage.CANT_PUSH_DATA; currPerson.state = GccState.SENT_TO_GCC_ERROR; currPerson.message = GCCMessage.CANT_PUSH_DATA; _gccMotoService.UpdateOne(currPerson); } } else { response.message = GCCMessage.CANT_GET_KEY; } } else { response.message = GCCMessage.CANT_SAVE; } } else { if (currMoto == null) { response.message = string.Format(GCCMessage.NOT_FIND_KIND_OF_MOTO, body.package.motoName); } else { response.message = string.Format(GCCMessage.NOT_FIND_PROGRAM, body.programTitle); } } } else { response.message = GCCMessage.NOT_FIND_PRODUCT; } return(Ok(response)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, new ResponseMessage { status = "ERROR", message = ex.Message })); } }