Ejemplo n.º 1
0
        public void UpdateContacts()
        {
            Console.WriteLine();
            Console.WriteLine("Update Contact Details");


            ContactInfo obj = new ContactInfo();

            Console.WriteLine("Enter the ContactId that you want to update");
            obj.ContactId = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Update the Fields that you want to update");
            //Console.Write("First Name\t:\t");
            //obj.firstName = Console.ReadLine();
            //Console.Write("Middle Name\t:\t");
            //obj.middleName = Console.ReadLine();
            //Console.Write("Last Name\t:\t");
            //obj.lastName = Console.ReadLine();
            //Console.Write("Date of Birth (YY/MM/DD)\t:\t");
            //obj.Birthday = Convert.ToDateTime(Console.ReadLine());


            //Console.Write("Email\t:\t");
            //obj.Email = Console.ReadLine();
            //Console.Write("Work Number\t:\t");
            //obj.WorkNumber = Console.ReadLine();
            //Console.Write("Home Number\t:\t");
            //obj.HomeNumber = Console.ReadLine();
            //Console.Write("Mobile Number\t:\t");
            //obj.MobileNumber = Console.ReadLine();
            //Console.Write("Active status\t:\t");
            //obj.IsActive = Convert.ToBoolean(Console.ReadLine());
            //WelcomePage w1 = new WelcomePage();
            //w1.Test2(obj.ContactId);
            var st1 = c1.ShowContactInfoById(obj.ContactId);

            Console.Write("First Name\t':{0}'\t Update FirstName:\t", st1.firstName);

            obj.firstName = Console.ReadLine().ToString();
            if (obj.firstName == "" || obj.firstName == null)
            {
                st1.firstName = obj.firstName;
            }
            var fname1 = RegexExpression.NameValidation(obj.firstName);

            Console.Write("Middle Name\t:{0}'\tUpdate MiddleName:\t", st1.middleName);
            obj.middleName = Console.ReadLine().ToString();
            var mname1 = RegexExpression.NameValidation(obj.middleName);

            Console.Write("Last Name\t:'{0}'\tUpdate LastName:\t", st1.lastName);
            obj.lastName = Console.ReadLine().ToString();
            var lname1 = RegexExpression.NameValidation(obj.lastName);


            Console.Write("Date of Birth (DD-MM-YYYY)\t:\t :'{0}'\t Update BirthDate\t:", st1.Birthday);
            // string datestring = Console.ReadLine();
            DateTime birth;

            // obj.Birthday =
            try
            {
                if (DateTime.TryParse(Console.ReadLine(), out birth))
                {
                    obj.Birthday = birth;
                }
                //else
                //{
                //    Console.WriteLine("Date is not valid");
                //}
            }
            catch (Exception e)
            {
                Console.WriteLine("DateTime is not valid");
            }
            var Birthday1 = RegexExpression.IsValidDate(obj.Birthday);

            try
            {
                Console.Write("Email\t: '{0}'\tUpdate Email ID:\t", st1.Email);
                obj.Email = Console.ReadLine();
                var Email1 = RegexExpression.IsEmail(obj.Email);
            }
            catch (Exception)
            {
                Console.WriteLine("Enter the valid date");
            }
            Console.Write("Work Number :'{0}'\tUpdate Work Number:\t", st1.WorkNumber);
            obj.WorkNumber = Console.ReadLine();
            var WorkNumber1 = RegexExpression.HomePhoneNumber(obj.WorkNumber);

            Console.Write("Home Number :'{0}'\tUpdate Home Number:\t", st1.HomeNumber);
            obj.HomeNumber = Console.ReadLine();
            var HomeNumber1 = RegexExpression.HomePhoneNumber(obj.HomeNumber);

            Console.Write("Mobile Number :'{0}'\tUpdate Mobile Number:\t", st1.MobileNumber);
            obj.MobileNumber = Console.ReadLine();
            var MobileNumber1 = RegexExpression.IsPhoneNumber(obj.MobileNumber);

            try
            {
                //    productProcess process = new productProcess();
                Contact c1 = new Contact();
                // c1.UpdateContact(obj);

                bool status = c1.UpdateContact(obj);
                if (status == true)
                {
                    Console.WriteLine("\nContact Successfully Updated");
                }
                else
                {
                    Console.WriteLine("Updation failed");
                }
                //  ContactInfointer.GetDetails(obj);
                // Console.WriteLine("\nProduct Successfully added");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        public void InsertContacts()
        {
            Console.WriteLine();
            Console.WriteLine("Add a new Contact");


            var         temp1 = true;
            ContactInfo obj   = new ContactInfo();

            try
            {
                do
                {
                    Console.Write("First Name\t:\t");
                    obj.firstName = Console.ReadLine();
                    var fname1 = RegexExpression.NameValidation(obj.firstName);
                    temp1 = SatisfyCondition(fname1, "name");
                }while (temp1 == false);
                Console.Write("Middle Name\t:\t");
                obj.middleName = Console.ReadLine();
                var mname1 = RegexExpression.NameValidation(obj.middleName);
                temp1 = SatisfyCondition(mname1, "name");


                Console.Write("Last Name\t:\t");
                obj.lastName = Console.ReadLine();
                var lname1 = RegexExpression.NameValidation(obj.lastName);
                temp1 = SatisfyCondition(lname1, "name");

                do
                {
                    Console.Write("Date of Birth (DD-MM-YYYY)\t:\t");
                    // string datestring = Console.ReadLine();
                    DateTime birth;
                    // obj.Birthday =
                    if (DateTime.TryParse(Console.ReadLine(), out birth))
                    {
                        obj.Birthday = birth;
                    }
                    else
                    {
                        Console.WriteLine("Date is not valid");
                    }

                    var Birthday1 = RegexExpression.IsValidDate(obj.Birthday);
                    temp1 = SatisfyCondition(Birthday1, "Date");
                    //  obj.Birthday = Convert.ToDateTime(datestring);
                }while (temp1 == false);

                do
                {
                    try
                    {
                        Console.Write("Email\t:\t");
                        obj.Email = Console.ReadLine();
                        var Email1 = RegexExpression.IsEmail(obj.Email);
                        temp1 = SatisfyCondition(Email1, "email");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Enter the valid date");
                    }
                }while (temp1 == false);
                do
                {
                    Console.Write("Work Number\t:\t");
                    obj.WorkNumber = Console.ReadLine();
                    var WorkNumber1 = RegexExpression.HomePhoneNumber(obj.WorkNumber);
                    temp1 = SatisfyCondition(WorkNumber1, "phone");
                }while (temp1 == false);
                do
                {
                    Console.Write("Home Number\t:\t");
                    obj.HomeNumber = Console.ReadLine();
                    var HomeNumber1 = RegexExpression.HomePhoneNumber(obj.HomeNumber);
                    temp1 = SatisfyCondition(HomeNumber1, "phone");
                }while (temp1 == false);
                do
                {
                    Console.Write("Mobile Number\t:\t");
                    obj.MobileNumber = Console.ReadLine();
                    var MobileNumber1 = RegexExpression.IsPhoneNumber(obj.MobileNumber);
                    temp1 = SatisfyCondition(MobileNumber1, "mobile");
                }while (temp1 == false);
                //    do
                //    {
                //        Console.Write("Active status\t:\t");
                //        obj.IsActive = Convert.ToBoolean(Console.ReadLine());
                //        var IsActive1 = RegexExpression.IsActivecheck(obj.IsActive);
                //        temp1 = SatisfyCondition(IsActive1, "isactive");
                //    }
                //    while (temp1 == false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //ValidationContext context = new ValidationContext(obj, null, null);
            //List<ValidationResult> results = new List<ValidationResult>();
            //bool valid = Validator.TryValidateObject(obj, context, results, true);

            //if (!valid)
            //{
            //    foreach (ValidationResult vr in results)
            //    {
            //        Console.ForegroundColor = ConsoleColor.Blue;
            //     //   Console.Write("Member Name :{0}", vr.MemberNames.First());
            //
            //  Console.Write("Member Name :{0}", vr.MemberNames);
            //        Console.ForegroundColor = ConsoleColor.Red;
            //        Console.Write("   ::  {0}{1}", vr.ErrorMessage, Environment.NewLine);
            //    }
            //}
            //Console.ForegroundColor = ConsoleColor.White;
            //Console.WriteLine("\nPress any key to exit");
            //Console.ReadKey();

            try
            {
                //    productProcess process = new productProcess();

                bool status = c1.InsertNewContact(obj);
                if (status == true)
                {
                    Console.WriteLine("\nContact Successfully added");
                }
                else
                {
                    Console.WriteLine("Insertion failed");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }