Beispiel #1
0
    private int GetMessageCost(string phone)
    {
        int    intCost = 0;
        string code    = "";

        phone_validity = new PhoneValidator();

        if (phone_validity.PhoneNumbersOk(phone))
        {
            if (phone.StartsWith("0"))
            {
                code = phone.Substring(1, 3);
            }
            else if (phone.StartsWith("256"))
            {
                code = phone.Substring(3, 3);
            }

            string ntwk = nCodes[code].ToString();
            string cost = rates[ntwk].ToString();
            intCost = int.Parse(cost);
            intCost = int.Parse(cost);
        }
        return(intCost);
    }
    public string SaveErrorSub(string name, string phone, string email)
    {
        string         ret = "";
        PhoneValidator pv  = new PhoneValidator();

        phone = bll.FormatPhoneNumber(phone);
        if (!pv.PhoneNumbersOk(phone))
        {
            ret = "Please Enter a valid Phone Number";
        }
        else if (!bll.IsValidEmailAddress(email))
        {
            ret = "Please Enter a valid Email Address";
        }
        else if (bll.IsSubEmail(email))
        {
            ret = "Email is already subscribed";
        }
        else if (bll.IsSubPhone(phone))
        {
            ret = "Phone is already subscribed";
        }
        else
        {
            datafile.SaveErrorSub(name, phone, email);
            ret = "Subscriber Saved Successfully";
        }
        return(ret);
    }
Beispiel #3
0
 public PhonesController(ApplicationDbContext context,
                         PhoneValidator phoneValidator,
                         FeedbackValidator feedbackValidator)
 {
     _context           = context;
     _phoneValidator    = phoneValidator;
     _feedbackValidator = feedbackValidator;
 }
        public void validatePhonenum2()
        {
            PhoneValidator phoneValid = new PhoneValidator();

            phoneValid.ValidatePhone("ABC-DEFG");
            bool validphone = phoneValid.ValidatePhone("ABC-DEFG");

            Assert.IsTrue(validphone);
        }
        public void validatePhonenum3()
        {
            PhoneValidator phoneValid = new PhoneValidator();

            phoneValid.ValidatePhone("418-4465987654");
            bool validphone = phoneValid.ValidatePhone("418-4465987654");

            Assert.IsTrue(validphone);
        }
        public void validatePhonenum()
        {
            PhoneValidator phoneValid = new PhoneValidator();

            phoneValid.ValidatePhone("418-4465");
            bool validphone = phoneValid.ValidatePhone("418-4465");

            Assert.IsFalse(validphone);
        }
Beispiel #7
0
        public Task HandleAsync(DeletePhoneCommand command)
        {
            var phoneId = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.RouteValues["Id"]);
            var phone   = _phoneRepository.Get(phoneId);

            PhoneValidator.Validate(phone, phone.Id);

            _phoneRepository.Delete(phone);

            return(Task.CompletedTask);
        }
Beispiel #8
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            var companyName = NameBox.Text;
            var nip         = NipBox.Text;
            var email       = EmailBox.Text;
            var street      = StreetBox.Text;
            var city        = CityBox.Text;
            var country     = CountryBox.Text;
            var zipCode     = ZipCodeBox.Text;
            var phone       = PhoneBox.Text;

            var nameValidator  = new NameValidator();
            var nipValidator   = new NipValidator();
            var mailValidator  = new MailValidator();
            var phoneValidator = new PhoneValidator();

            if (!nameValidator.ValidateName(companyName))
            {
                MessageBox.Show("Podałeś niedozwoloną nazwę firmy");
            }
            else if (!nipValidator.ValidateNip(nip))
            {
                MessageBox.Show("Podałeś nieprawidłowy nip");
            }
            else if (!mailValidator.ValidateMail(email))
            {
                MessageBox.Show("Podałeś nieprawidłowy adres Email");
            }

            else if (string.IsNullOrEmpty(street) || string.IsNullOrEmpty(zipCode) || string.IsNullOrEmpty(country) ||
                     string.IsNullOrEmpty(city))
            {
                MessageBox.Show("Pole adresowe nie może być puste");
            }


            else
            {
                var account        = new BankAccount();
                var companyAccount = new CompanyAccount(companyName, nip, email, zipCode, country,
                                                        phone, city, street, account)
                {
                    BankAccount = { Balance = 0.0 }
                };

                var filePath  = Environment.CurrentDirectory + @"\" + "Company_Accounts.xml";
                var listToXml = new ListToXml();
                listToXml.CompanyAccounts(companyAccount, filePath);
                Close();
            }
        }
Beispiel #9
0
    public string LogSMS(string list_code, string prefix, string message, string otherPhones, string areaID)
    {
        string output = "";

        phone_validator = new PhoneValidator();
        int list_id = int.Parse(list_code);

        string[] ArrayPhones = otherPhones.Split(',');
        data_table = data_file.GetActiveListNumbers(list_id);

        if ((data_table.Rows.Count > 0) || (ArrayPhones.Length > 0))
        {
            string user  = HttpContext.Current.Session["Username"].ToString();
            string mask  = HttpContext.Current.Session["Mask"].ToString();
            int    i     = 0;
            int    count = 0;
            foreach (DataRow dr in data_table.Rows)
            {
                string phone = phone_validator.Format(dr["PhoneNumber"].ToString().Trim());
                string name  = dr["PhoneName"].ToString();
                string msg   = GetformatMessage(phone, name, prefix, message);
                data_file.InsertSmsToSend(phone, msg, mask, user, areaID);
                count++;

                Reduct_credit(list_id, message, mask, user, phone);
            }
            if (count > 0)
            {
                i = 1;
            }

            for (; i < ArrayPhones.Length; i++, count++)
            {
                string phone = phone_validator.Format(ArrayPhones[i].ToString().Trim());
                string msg   = GetformatMessage(phone, "", prefix, message);
                data_file.InsertSmsToSend(phone, msg, mask, user, areaID);

                Reduct_creditforOtherPhones(ArrayPhones, message, mask, user, "YES");
            }

            output = "A list of " + count + " has been logged Successfully";
        }
        else
        {
            output = "No Active Phone number(s) on list";
        }
        return(output);
    }
        public Task <PhoneQueryResponse> HandleAsync(PhoneQuery query)
        {
            var phone = _phoneRepository.Get(query.Id);

            PhoneValidator.Validate(phone, query.Id);

            _dimensionsRepository.Get(phone.Id);
            _displayRepository.Get(phone.Id);
            _mediaRepository.GetAll().Where(m => m.PhoneId == query.Id);

            var mapped = _mapper.Map <PhoneViewModel>(phone);

            return(Task.FromResult(new PhoneQueryResponse {
                Phone = mapped
            }));
        }
Beispiel #11
0
        /// <summary>
        /// Phone
        /// </summary>
        /// <typeparam name="T">DataType</typeparam>
        public static void Phone <T>(params ValidationField <T>[] fields)
        {
            string        validatorKey = string.Format("{0}", typeof(PhoneValidator).FullName);
            DataValidator validator    = null;

            if (_validatorList.ContainsKey(validatorKey))
            {
                validator = _validatorList[validatorKey];
            }
            else
            {
                validator = new PhoneValidator();
                _validatorList.Add(validatorKey, validator);
            }
            SetValidation <T>(validator, fields);
        }
    public string LogSMSCommaSeparatedList(string[] phonesArr, string message, string VendorCode, string mask)
    {
        var output = "";

        _phoneValidator = new PhoneValidator();

        var arrayPhones = phonesArr;

        //List has phone numbers
        if (arrayPhones.Length > 0)
        {
            var user = HttpContext.Current.Session["Username"].ToString();
            //var mask = HttpContext.Current.Session["Mask"].ToString();
            var mail      = HttpContext.Current.Session["Email"].ToString();
            int smscredit = GetUserCredit(VendorCode, user);
            if (arrayPhones.Length < smscredit)
            {
                string reduce = Reduct_credit(arrayPhones.Length);
                if (reduce == "SAVED")
                {
                    for (var i = 0; i < arrayPhones.Length; i++)
                    {
                        if (_phoneValidator.NumberFormatIsValid(arrayPhones[i].Trim()))
                        {
                            var phone = _phoneValidator.Format(arrayPhones[i].Trim());
                            _db.InsertSmsToSend(phone, message, mask, user, VendorCode);
                            output += "SMS to Phone Number" + arrayPhones[i].Trim() + " logged Successfully <br/>";
                        }
                        else
                        {
                            output += "Invalid Number " + arrayPhones[i].Trim() + " Was Provided and not processed <br/>";
                        }
                    }
                }
            }
            else
            {
                output = "Dear customer, Your Current SMS Limit is too low to send these SMS(s)";
            }
        }
        else
        {
            output = "No Active Phone number(s) Entered";
        }

        return(output);
    }
    public string SaveInvoiceDetails(string fname, string mname, string lname, string phone, string email, string amount)
    {
        string         ret = "";
        PhoneValidator ph  = new PhoneValidator();

        if (!bll.IsValidEmailAddressOptional(email))
        {
            ret = "Please Provide a valid email address";
        }
        else if (!ph.PhoneNumbersOk(phone) && !phone.Equals(""))
        {
            ret = phone + " is not a valid phone number";
        }
        else
        {
        }
        return(ret);
    }
Beispiel #14
0
    private int GetTotalCost(string[] phones)
    {
        int messageCost = 0;

        phone_validity = new PhoneValidator();
        foreach (string phone in phones)
        {
            string s = phone;
            if (phone != null)
            {
                s = process_file.formatPhone(s);
                if (phone_validity.PhoneNumbersOk(s))
                {
                    messageCost = messageCost + GetMessageCost(s);
                }
            }
        }
        return(messageCost);
    }
Beispiel #15
0
        private void CreatePhoneValidator(IServiceCollection services)
        {
            Hashtable segment = new Hashtable();
            var       coll    = Configuration.GetSection("phone-segment").GetChildren();

            foreach (var prefix in coll)
            {
                if (string.IsNullOrEmpty(prefix.Value))
                {
                    continue;
                }
                foreach (var s in prefix.Value.Split(','))
                {
                    segment[s] = s;
                }
            }
            var pv = new PhoneValidator(segment);

            services.AddSingleton <PhoneValidator>(pv);
        }
        public Task HandleAsync(UpdatePhoneCommand command)
        {
            var phoneId = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.RouteValues["Id"]);

            var phone = _phoneRepository.Get(phoneId);

            PhoneValidator.Validate(phone, phone.Id);

            phone.Name         = command.Name;
            phone.Manufacturer = command.Manufacturer;
            phone.OS           = command.OS;
            phone.Price        = command.Price;
            phone.RAM          = command.RAM;
            phone.Weight       = command.Weight;
            phone.CPUModel     = command.CPUModel;

            _phoneRepository.Update(phone);

            return(Task.CompletedTask);
        }
        public virtual IEnumerable <RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(Title))
            {
                yield return(new RuleViolation("Title is required", "Title"));
            }

            if (String.IsNullOrEmpty(Description))
            {
                yield return(new RuleViolation("Description is required", "Description"));
            }

            if (String.IsNullOrEmpty(HostedBy))
            {
                yield return(new RuleViolation("HostedBy is required", "HostedBy"));
            }

            if (String.IsNullOrEmpty(Address))
            {
                yield return(new RuleViolation("Address is required", "Address"));
            }

            if (String.IsNullOrEmpty(Country))
            {
                yield return(new RuleViolation("Country is required", "Address"));
            }

            if (String.IsNullOrEmpty(ContactPhone))
            {
                yield return(new RuleViolation("Phone# is required", "ContactPhone"));
            }

            if (!PhoneValidator.IsValidNumber(ContactPhone, Country))
            {
                yield return(new RuleViolation("Phone# does not match country", "ContactPhone"));
            }

            yield break;
        }
Beispiel #18
0
        public static bool IsValidPhone(string phone)
        {
            if (Util.IsNullOrEmpty(phone))
            {
                return(false);
            }

            if (!PhoneRegex.IsMatch(phone))
            {
                return(false);
            }

            bool repeat = true;

            for (int i = 0; i < (phone.Length - 6); i++)
            {
                if (phone[i + 6] != '-')
                {
                    if (phone[i + 6] != phone[5])
                    {
                        repeat = false;

                        break;
                    }
                }
            }

            if (repeat)
            {
                return(false);
            }

            if (!PhoneValidator.ValidatePhone(phone))
            {
                return(false);
            }

            return(true);
        }
        public ValidationResponse PostPhoneValidation(PhoneValidator phoneValidator)
        {
            var response = new ValidationResponse();

            var accountRegistrationServiceClient = new AccountRegistrationService.AccountRegistrationServiceClient();

            try
            {
                accountRegistrationServiceClient.Open();
                var validationResponse = accountRegistrationServiceClient.ValidatePhoneNumber(phoneValidator.PhoneNumber);

                //Close the connection
                WCFManager.CloseConnection(accountRegistrationServiceClient);


                response.valid   = validationResponse.isValid;
                response.message = validationResponse.validationMessage;
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountRegistrationServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.valid   = false;
                response.message = WCFManager.UserFriendlyExceptionMessage;

                #endregion
            }

            return(response);
        }
    private void LoadCustomerContacts()
    {
        string         accountno  = txtaccountno.Text.Trim();
        string         phone      = txtPhone.Text.Trim();
        PhoneValidator phonevalid = new PhoneValidator();

        if (phonevalid.PhoneNumbersOk(phone))
        {
            phone = GetPhoneNumber(phone);
            DateTime fromDate = bll.ReturnDate(txtfromdate.Text.Trim(), 1);
            DateTime toDate   = bll.ReturnDate(txttodate.Text.Trim(), 2);
            dataTable = datapay.GetCustomercontacts(accountno, phone, fromDate, toDate);
            if (dataTable.Rows.Count > 0)
            {
                DataGrid1.CurrentPageIndex = 0;
                DataGrid1.DataSource       = dataTable;
                DataGrid1.DataBind();
                DataGrid1.Visible          = true;
                MultiView1.ActiveViewIndex = 0;
                ShowMessage(".", true);
            }
            else
            {
                DataGrid1.Visible          = false;
                MultiView1.ActiveViewIndex = -1;
                ShowMessage("No Record found", true);
            }
        }
        else
        {
            DataGrid1.Visible          = false;
            MultiView1.ActiveViewIndex = -1;
            ShowMessage("Please Enter a valid phone number", true);
            txtPhone.Focus();
        }
    }
Beispiel #21
0
        public Task HandleAsync(PhoneOrderCommand command)
        {
            var user = _usersRepository
                       .GetAll()
                       .Where(u => u.Email == _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Email).Value)
                       .FirstOrDefault();

            var phone = _phoneRepository.Get(command.PhoneId);

            PhoneValidator.Validate(phone, command.PhoneId);

            var order = new Orders
            {
                AddedDate        = DateTime.Now,
                CreditCardNumber = command.CreditCardNumber,
                NameOnCard       = command.NameOnCard,
                User             = user,
                PhoneId          = phone.Id
            };

            _ordersRepository.Insert(order);

            return(Task.CompletedTask);
        }
 //Não vi outro modo de resolver sem ser com ifs.
 // State pattern, polimorfismo ou matching pattern do c# 9 não fazem sentido aqui
 public static string GetFormattedPhone(string phoneNumber)
 {
     if (PhoneValidator.IsPublicService(phoneNumber))
     {
         return(PublicServicePhoneFormatter.GetFormattedPhone(phoneNumber));
     }
     if (PhoneValidator.IsServiceProvider(phoneNumber))
     {
         return(PhoneFormatter.GetFormattedServiceProviderNumber(phoneNumber));
     }
     if (PhoneValidator.IsNotGeophicNumber(phoneNumber))
     {
         return(GetNotGeographicFormattedNumber(phoneNumber));
     }
     if (PhoneValidator.IsResidentialNumber(phoneNumber))
     {
         return(GetResidentialFormattedNumber(phoneNumber));
     }
     if (PhoneValidator.IsMobileNumber(phoneNumber))
     {
         return(GetMobileFormattedNumber(phoneNumber));
     }
     return("Número de telefone não identificado: " + phoneNumber);
 }
    public InvoiceTran SaveInvoiceDetails(InvoiceTran inv)
    {
        InvoiceTran    resp = new InvoiceTran();
        PhoneValidator ph   = new PhoneValidator();

        if (!bll.IsValidEmailAddress(inv.Email) && !inv.Email.Equals(""))
        {
            resp.ErrorCode = "1";
            resp.Error     = "Please Provide a valid email address";
        }
        else if (!ph.PhoneNumbersOk(inv.Phone) && !inv.Phone.Equals(""))
        {
            resp.ErrorCode = "1";
            resp.Error     = inv.Phone + " is not a valid phone number";
        }
        else
        {
            inv.PayTypeCode    = datafile.GetPayTypeCodeByShortName(inv.ShortName);
            inv.User           = HttpContext.Current.Session["Username"].ToString();
            inv.RegionCode     = HttpContext.Current.Session["AreaCode"].ToString();
            inv.DistrictCode   = HttpContext.Current.Session["DistrictCode"].ToString();
            inv.Vat            = GetVatAmount(inv);
            resp.InvoiceSerial = datapay.SaveInvoiceDetails(inv);
            if (resp.InvoiceSerial.Equals(""))
            {
                resp.ErrorCode = "1";
                resp.Error     = "Failed to create Invoice serial number";
            }
            else
            {
                resp.ErrorCode = "0";
                resp.Error     = "Invoice created successfully[" + resp.InvoiceSerial + "]";
            }
        }
        return(resp);
    }
Beispiel #24
0
        public static void ShouldNotBeServiceProviderNumber(string phoneNumber)
        {
            var isServiceProvider = PhoneValidator.IsServiceProvider(phoneNumber);

            Assert.False(isServiceProvider);
        }
Beispiel #25
0
        public static void ShouldNOtBeNotGeophicNumber(string phoneNumber)
        {
            var isNotGeophicNumber = PhoneValidator.IsNotGeophicNumber(phoneNumber);

            Assert.False(isNotGeophicNumber);
        }
Beispiel #26
0
        public static void ShouldNotBeMobileNumber(string phoneNumber)
        {
            var isMobileNumber = PhoneValidator.IsMobileNumber(phoneNumber);

            Assert.False(isMobileNumber);
        }
 public HomeController(PhoneValidator pv)
 {
     validator = pv;
 }
Beispiel #28
0
        public static void ShouldNotBeResidentialNumber(string phoneNumber)
        {
            var isResidentialNumber = PhoneValidator.IsResidentialNumber(phoneNumber);

            Assert.False(isResidentialNumber);
        }
Beispiel #29
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            var firstName = FirstNameBox.Text;
            var lastName  = LastNameBox.Text;
            var pesel     = PeselBox.Text;
            var email     = EmailBox.Text;
            var doB       = DoB.Text;
            var street    = StreetBox.Text;
            var city      = CityBox.Text;
            var country   = CountryBox.Text;
            var zipCode   = ZipCodeBox.Text;
            var phone     = PhoneBox.Text;


            var nameValidator  = new NameValidator();
            var mailValidator  = new MailValidator();
            var peselValidator = new PeselValidator();
            var dobValidator   = new DateOfBirthValidator();
            var phoneValidator = new PhoneValidator();

            if (!nameValidator.ValidateName(firstName))
            {
                MessageBox.Show("Podałeś nieprawidłowę imię.");
            }
            else if (!nameValidator.ValidateName(lastName))
            {
                MessageBox.Show("Podałeś nieprawidłowe nazwisko");
            }
            else if (!peselValidator.ValidatePesel(pesel))
            {
                MessageBox.Show("Podałeś nieprawidłowy numer PESEL");
            }
            else if (!mailValidator.ValidateMail(email))
            {
                MessageBox.Show("Podałeś nieprawidłowy adres Email");
            }
            else if (!phoneValidator.ValidatePhoneNumber(phone))
            {
                MessageBox.Show("Nieprawidłowy numer telefonu");
            }

            else if (!dobValidator.ValidateDoB(doB))
            {
                MessageBox.Show("Nieprawidłowa data urodzenia");
            }
            else if (string.IsNullOrEmpty(street) || string.IsNullOrEmpty(zipCode) || string.IsNullOrEmpty(country) ||
                     string.IsNullOrEmpty(city))
            {
                MessageBox.Show("Pole adresowe nie może być puste");
            }


            else
            {
                var gender          = (Gender)Enum.Parse(typeof(Gender), GenderComboBox.Text);
                var account         = new BankAccount();
                var personalAccount = new PersonalAccount(firstName, lastName, doB, gender, pesel, email, street,
                                                          zipCode,
                                                          country, phone, city, account)
                {
                    BankAccount = { Balance = 0.0 }
                };

                var filePath  = Environment.CurrentDirectory + @"\" + "Personal_Accounts.xml";
                var listToXml = new ListToXml();
                listToXml.PersonalAccounts(personalAccount, filePath);

                Close();
            }
        }
Beispiel #30
0
        public static void ShouldNotBePublicServiceNumber(string phoneNumber)
        {
            var isPubService = PhoneValidator.IsPublicService(phoneNumber);

            Assert.False(isPubService);
        }