public GCCPersonalInsurance CreateOne(GCCPersonalInsurance obj) { try { obj.CreateDate = Convert.ToDateTime(DateTime.Now.ToLocalTime()); _collection.InsertOne(obj); return(obj); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(null); } }
public long UpdateOne(GCCPersonalInsurance 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 ActionResult <ResponseContext> PersonalInsurance(GCCPersonalInsurance 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 currPackage = product.package.Split(";"); body.state = GccState.NEW; body.program = product.program; body.agency_id = product.agency_id; body.product_code = product.product_code; 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; if (currPackage.Length == 1) { body.package = product.package; } else { body.package = _gccProductService.MappingPackage(body.package); } var currPerson = _gccService.CreateOne(body); if (currPerson != null) { var token = _gccService.GetToken(); if (!string.IsNullOrEmpty(token)) { var sendObj = _gccService.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; } _gccService.UpdateOne(currPerson); } else { response.message = GCCMessage.CANT_PUSH_DATA; currPerson.state = GccState.SENT_TO_GCC_ERROR; currPerson.message = GCCMessage.CANT_PUSH_DATA; _gccService.UpdateOne(currPerson); } } else { response.message = GCCMessage.CANT_GET_KEY; } } else { response.message = GCCMessage.CANT_SAVE; } } 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 })); } }