public HttpResponseMessage Payment() { validateBAL = new T_CardValidationBAL(); try { // zoneDTO = ConvertX.GetReqeustForm<M_ZoneDTO>(); tranDto = ConvertX.GetReqeustForm <T_CreditCardDTO>(); results = validateBAL.Validate(tranDto); mapMessage = Request.CreateResponse(HttpStatusCode.OK, results); } catch (Exception ex) { mapMessage = Request.CreateResponse(HttpStatusCode.BadRequest, ex.ToString()); } finally { } return(mapMessage); }
public T_CreditCardDTO Existing(object data) { SqlDataReader reader = null; List <SqlParameter> parameterList = new List <SqlParameter>(); objList = new List <T_CreditCardDTO>(); dataTable = null; string procName = "sp_T_CreditCard_FindbyColumn"; try { dataTable = new DataTable(); adapter = new SqlDataAdapter(); SqlConnection conn = OpenConnection(); if (data != null) { parameterList.AddRange(GetParameters(procName, data).ToArray()); } command = new SqlCommand(procName, conn); command.CommandType = CommandType.StoredProcedure; if (data != null) { command.Parameters.AddRange(parameterList.ToArray()); } reader = command.ExecuteReader(); obj = ConvertX.ConvertDataReaderToObjectList <T_CreditCardDTO>(reader).FirstOrDefault(); } catch (Exception ex) { } finally { reader.Close(); CloseConnection(); } return(obj); }
public List <MessageDTO> Validate(object dto) { responseList = new List <MessageDTO>(); MessageDTO errorMsg = null; T_CreditCardDTO requestDto = (T_CreditCardDTO)dto; T_CreditCardDTO responseDto = null; string fieldValue = ""; string format = ""; string opValue = ""; bool invalidCreditCard = false; try { dtolist = dao.FindByCardTypeObjList(dto); #region Validate from DB foreach (T_CardValidationDTO validateDto in dtolist) { opValue = validateDto.OperationValue; if (validateDto.Field == "CardNumber") { fieldValue = requestDto.CardNumber; } else if (validateDto.Field == "ExpireDate") { fieldValue = requestDto.ExpireDate.PadLeft(6, '0'); } switch (validateDto.ChkValidate) { case ChkValidate.Value: if (!ConvertX.Compare(validateDto.Operation, opValue, fieldValue, validateDto.CompareValue)) { errorMsg = new MessageDTO(); errorMsg.Status = false; errorMsg.StatusText = validateDto.InvalidCaption; responseList.Add(errorMsg); } break; case ChkValidate.SubString: fieldValue = fieldValue.Substring(validateDto.StartLength, validateDto.Length); if (!ConvertX.Compare(validateDto.Operation, opValue, fieldValue, validateDto.CompareValue)) { errorMsg = new MessageDTO(); errorMsg.Status = false; errorMsg.StatusText = validateDto.InvalidCaption; responseList.Add(errorMsg); } break; case ChkValidate.Length: fieldValue = fieldValue.Length.ToString(); if (!ConvertX.Compare(validateDto.Operation, opValue, fieldValue, validateDto.CompareValue)) { errorMsg = new MessageDTO(); errorMsg.Status = false; errorMsg.StatusText = validateDto.InvalidCaption; responseList.Add(errorMsg); } break; } } #endregion responseDto = cardDao.Existing(requestDto); invalidCreditCard = true; #region Validate from Program if (responseDto != null) { if (responseDto.HolderName.Trim() != requestDto.HolderName.Trim()) { invalidCreditCard = false; } else if (responseDto.CTypeCode.Trim() != requestDto.CTypeCode.Trim()) { invalidCreditCard = false; } else if (responseDto.ExpireDate.Trim() != requestDto.ExpireDate.Trim()) { invalidCreditCard = false; } else if (responseDto.CVV.Trim() != requestDto.CVV.Trim()) { invalidCreditCard = false; } if (!invalidCreditCard) { errorMsg = new MessageDTO(); errorMsg.Status = false; errorMsg.StatusText = "Invalid"; responseList.Add(errorMsg); } #endregion } else { errorMsg = new MessageDTO(); errorMsg.Status = false; errorMsg.StatusText = "Does not exist"; responseList.Add(errorMsg); } } catch (Exception ex) { Log((dto as T_CreditCardDTO).Page, "Error", ex.ToString()); } return(responseList); }