public IHttpActionResult Get(string id)
        {
            var card = new data_validation.net.Web.Controllers.Helpers.RemoveSpecialCharacters();
            var cleanNumber = card.RemoveSpecialCharactersCard(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<CardValidationViewModel>();
                errorMessage.Add(new CardValidationViewModel { 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, cleanNumber, "singleAPI", "card");

            if (!hasCredits)
            {
                var errorMessage = new List<CardValidationViewModel>();
                errorMessage.Add(new CardValidationViewModel { IsValid = "No Credits Left" });
                return Ok(errorMessage);
            }

            var cardType = new CardType();
            var result = cardType.CardLogic(cleanNumber);

            return Ok(result);
        }
        public IHttpActionResult Get(string id)
        {
            var iban = new data_validation.net.Web.Controllers.Helpers.RemoveSpecialCharacters();
            var cleanIban = iban.RemoveSpecialCharactersBasic(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<iBanBicModel>();
                errorMessage.Add(new iBanBicModel { 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, cleanIban, "singleAPI", "iban");

            if (!hasCredits)
            {
                var errorMessage = new List<iBanBicModel>();
                errorMessage.Add(new iBanBicModel { IsValid = "No Credits Left" });
                return Ok(errorMessage);
            }

            var resT = new BankValidationController();

            var temp = BankValidationController.Iban.CheckIban(id, true);

            var error = new List<iBanBicModel>();

            if (!temp.IsValid)
            {
                error.Add(new iBanBicModel { IsValid = temp.Message, BankCode = cleanIban });

                return Ok(error);
            }

            var result = resT.BicCountry(cleanIban.ToUpper());

            return Ok(result);
        }
        public ActionResult BulkAddress(IEnumerable<HttpPostedFileBase> fileToUpload)
        {
            var outputStream = new MemoryStream();
            int foundAddress = 0;
            int notFoundAddress = 0;
            int totalRecords = 0;
            using (var zip = new ZipFile())
            {
                string time = User.Identity.Name + DateTime.Now.Ticks;
                Directory.CreateDirectory(Server.MapPath("~/Tuploads/") + time);
                string folder = Server.MapPath("~/Tuploads/") + time + "/";
                foreach (var csvFile in fileToUpload)
                {
                    var results = new List<AddressModel>();
                    string targetFolder = folder + csvFile.FileName;
                    csvFile.SaveAs(targetFolder);
                    var csvToData = new CsvToDataTable();
                    var csvData = csvToData.GetDataTabletFromCSVFile(targetFolder, "address");
                    //Billing
                    int records = csvData.Rows.Count;

                    var helper = new Helpers.CreditsDeduct();
                    //if more than 1 file submited
                    totalRecords += records;

                    var resul = helper.IsValid(User.Identity.Name, records, "", "bulk", "address");

                    if (resul == false)
                    {
                        Response.StatusCode = (int)HttpStatusCode.BadRequest;
                        return Json(404, JsonRequestBehavior.AllowGet);
                    }

                    //If user has enough credits start cleansing
                    foreach (DataRow res in csvData.Rows)
                    {
                        StringBuilder tempString = new StringBuilder();

                        foreach (var item in res.ItemArray)
                        {
                            if (item.ToString().Length == 0)
                            {
                                continue;
                            }
                            tempString = tempString.Append(item + ",");
                        }
                        var dataCleansing = new DataCleansingLogich();
                        var tempResult = dataCleansing.Cleansing(tempString.ToString().Substring(0, tempString.Length - 1)).FirstOrDefault();

                        if (tempResult.IsValid == "Corrected")
                        {
                            foundAddress++;
                        }
                        else
                        {
                            notFoundAddress++;
                        }

                        results.Add(new AddressModel
                        {
                            AdministrativeCounty = tempResult.AdministrativeCounty,
                            BuildingName = tempResult.BuildingName,
                            BuildingNumber = tempResult.BuildingNumber,
                            City = tempResult.City,
                            Flat = tempResult.Flat,
                            IsValid = tempResult.IsValid,
                            Locality = tempResult.Locality,
                            PostCode = tempResult.PostCode,
                            Street = tempResult.Street,
                            TraditionalCounty = tempResult.TraditionalCounty
                        });
                    }

                    this.Data.AddressCleansingHistory.Add(new AddressCleansingHistory
                    {
                        AddressCorrected = foundAddress,
                        AddressNotFound = notFoundAddress,
                        RecordsUploaded = totalRecords,
                        UserName = User.Identity.Name,
                        DateSubmited = DateTime.Now
                    });

                    this.Data.SaveChanges();

                    MemoryStream output = new MemoryStream();
                    int i = 0;

                    if (results.Count() > 0)
                    {

                        StreamWriter write = new StreamWriter(output, Encoding.UTF8);
                        StringBuilder sb = new StringBuilder();

                        write.Write("Corrected address");
                        write.Write(Environment.NewLine);

                        foreach (var details in results)
                        {
                            sb.Append(details.Flat + "," + details.BuildingName + "," + details.BuildingNumber + "," + details.Street + "," + details.City + "," + details.Locality + "," + details.TraditionalCounty + "," + details.PostCode + "," + details.IsValid);
                            write.Write(sb);
                            write.Write(Environment.NewLine);
                            sb.Clear();
                        }
                        write.Flush();
                        output.Position = 0;
                    }
                    //If any records write them to csv file and return to user
                    if (fileToUpload.Count() == 1)
                    {
                        return File(output, "text/coma-separated-values", User.Identity.Name + "_" + DateTime.Now.Ticks + ".csv");
                    }
                    else
                    {
                        using (FileStream file = new FileStream(folder + "test" + i + ".csv", FileMode.Create, System.IO.FileAccess.Write))
                        {
                            byte[] bytes = new byte[output.Length];
                            output.Read(bytes, 0, (int)output.Length);
                            file.Write(bytes, 0, bytes.Length);
                            output.Close();
                        }
                        zip.AddFile(folder + "test" + i + ".csv", @"\");
                        i++;
                        if (i == fileToUpload.Count())
                        {
                            zip.Save(outputStream);
                        }
                    }
                }

                outputStream.Position = 0;
                outputStream.Seek(0, SeekOrigin.Begin);
                return File(outputStream, "application/octet-stream", "filename.zip");

            }
        }
        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);
        }