public IHttpActionResult Get(string id) { var phone = new data_validation.net.Web.Controllers.Helpers.RemoveSpecialCharacters(); var cleanPhone = phone.RemoveCharactersTelephone(id); var userIp = Request.GetOwinContext().Request.RemoteIpAddress; var userHost = Request.GetOwinContext().Request.Host.Value.ToString(); var isFraud = new IsFraudController(); var isFraudUser = isFraud.Check(User.Identity.Name, userIp, userHost); if (isFraudUser) { var errorMessage = new List<PhoneValidationViewModel>(); errorMessage.Add(new PhoneValidationViewModel { IsValid = "Fraud Triger On!" }); return Ok(errorMessage); } var helper = new data_validation.net.Web.Controllers.Helpers.CreditsDeduct(); var hasCredits = helper.IsValid(User.Identity.Name, 6, cleanPhone, "singleAPI", "telephone"); if (!hasCredits) { var errorMessage = new List<PhoneValidationViewModel>(); errorMessage.Add(new PhoneValidationViewModel { IsValid = "No Credits Left" }); return Ok(errorMessage); } var result = new List<PhoneValidationViewModel>(); if (cleanPhone.Length != 11 && cleanPhone.Length != 10) { result.Add(new PhoneValidationViewModel { IsValid = "Phone is invalid", Number = cleanPhone }); return Ok(result); } using (var context = new ApplicationDbContext()) { var tmpData = context.Database.SqlQuery<GetPhoneArea_Result>("GetPhoneArea2 @code", new SqlParameter("code", cleanPhone)).First(); if (tmpData.IsValid == "Valid") { result.Add(new PhoneValidationViewModel { Area = tmpData.AreaCovered, Number = cleanPhone, IsValid = tmpData.IsValid }); return Ok(result); } } result.Add(new PhoneValidationViewModel { Number = cleanPhone, IsValid = "Phone seems invalid" }); return Ok(result); }
public JsonResult TelephoneValidation(string id, string id2) { var apiNumber = id2; if (User.Identity.IsAuthenticated) { var helper = new Helpers.CreditsDeduct(); var res = helper.IsValid(User.Identity.Name, 6, id, "single", "email"); if (res == false) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Json(404, JsonRequestBehavior.AllowGet); } } else { var isValid = new IsValid(); bool tUser = isValid.ValidUser(apiNumber, id, "email"); if (tUser == false) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Json(410, JsonRequestBehavior.AllowGet); } } var removeSpecialCharacters = new RemoveSpecialCharacters(); var number = removeSpecialCharacters.RemoveCharactersTelephone(id); var result = new List<PhoneValidationViewModel>(); if (number.Length != 11 && number.Length != 10) { result.Add(new PhoneValidationViewModel { IsValid = "Phone is invalid", Number = id }); return Json(result, JsonRequestBehavior.AllowGet); } using (var context = new ApplicationDbContext()) { for (int i = 5; i >= 2; i--) { var tmpData = context.Database.SqlQuery<GetPhoneArea_Result>("GetPhoneArea2 @code", new SqlParameter("code", number.Substring(0, i))).First(); if (tmpData.IsValid == "Valid") { result.Add(new PhoneValidationViewModel { Area = tmpData.AreaCovered, Number = id, IsValid = tmpData.IsValid }); return Json(result, JsonRequestBehavior.AllowGet); } } } result.Add(new PhoneValidationViewModel { IsValid = "Phone seems invalid" }); return Json(result, JsonRequestBehavior.AllowGet); }
private List<PhoneValidationViewModel> Validate(DataTable csvData) { var results = new List<PhoneValidationViewModel>(); int invalidRecords = 0; int validRecords = 0; var removeSpecialCharacters = new RemoveSpecialCharacters(); foreach (DataRow res in csvData.Rows) { foreach (var number in res.ItemArray) { var cleanNumber = removeSpecialCharacters.RemoveCharactersTelephone(number.ToString()); if (cleanNumber.Length != 11 && cleanNumber.Length != 10) { results.Add(new PhoneValidationViewModel { IsValid = "Phone is invalid", Number = "=\"" + number.ToString() + "\"", }); invalidRecords++; } else { using (var context = new ApplicationDbContext()) { var tmpData = context.Database.SqlQuery<GetPhoneArea_Result>("GetPhoneArea2 @code", new SqlParameter("code", cleanNumber.Substring(0, 5))).First(); if (tmpData.IsValid == "Valid") { results.Add(new PhoneValidationViewModel { Area = tmpData.AreaCovered, Number = "=\"" + number.ToString() + "\"", IsValid = tmpData.IsValid }); validRecords++; break; } else { results.Add(new PhoneValidationViewModel { Area = tmpData.AreaCovered, Number = "=\"" + number.ToString() + "\"", IsValid = tmpData.IsValid }); invalidRecords++; break; } } } } } results.Add(new PhoneValidationViewModel { Number = invalidRecords.ToString(), Message = validRecords.ToString() }); return results; }