Esempio n. 1
0
        public void Test2(int para)
        {
            Contact c1 = new Contact();

            Console.WriteLine("retrieving Contacts with ID");
            try
            {
                //string criteria = "";
                //c1.ShowContactInfo();
                ContactInfo obj = new ContactInfo();
                obj = c1.ShowContactInfoById(para);
                // bool flag = false;
                //foreach (var item in list)
                //{
                //    //Console.WriteLine("{0},{1},{2},{3},{4}",
                //    //    item.ContactId, item.firstName, item.middleName, item.lastName, item.Birthday,
                //    //    item.Email, item.WorkNumber, item.HomeNumber, item.MobileNumber, item.IsActive);
                //    Console.WriteLine($"{item.ContactId}, {item.firstName}, {item.middleName}, {item.lastName}, { item.Birthday.Date}, " +
                //      $"{item.Email}, {item.WorkNumber}, {item.HomeNumber}, {item.MobileNumber}, {item.IsActive}");

                if (obj.ContactId == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    throw new UserIDException("Contact Id not found");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    //Console.WriteLine("{0},{1},{2},{3},{4}",
                    //    item.ContactId, item.firstName, item.middleName, item.lastName, item.Birthday,
                    //    item.Email, item.WorkNumber, item.HomeNumber, item.MobileNumber, item.IsActive);
                    Console.WriteLine($"{obj.ContactId}, {obj.firstName}, {obj.middleName}, {obj.lastName}, { obj.Birthday.Date}, " +
                                      $"{obj.Email}, {obj.WorkNumber}, {obj.HomeNumber}, {obj.MobileNumber}, {obj.IsActive}");
                }
                //        flag = true;
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 2
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);
            }
        }