コード例 #1
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (txtName.Text != "" && txtNumber.Text != "")
     {
         _contactManager.AddContact(txtName.Text, txtNumber.Text);
     }
 }
コード例 #2
0
    public void OnFinishedEditButtonPressed()
    {
        if (contact.name + contact.lastname == "")
        {
            EnableDisableButtons(false); // just to make sure
            SetWarning("Contact Has No Name", () => {
                EnableDisableButtons(true);
            });
            return;
        }
        if (ContactManager.FindExactContact(contact) != null)
        {
            EnableDisableButtons(false); // just to make sure
            SetWarning("Contact Already Exists", () => {
                EnableDisableButtons(true);
            });
            return;
        }

        if (oldContact != null)
        {
            ContactManager.RemoveContact(oldContact);
        }
        if (contact != null && contact.name != "")
        {
            contact.dateAdded = System.DateTime.Now;
            ContactManager.AddContact(contact);
        }
        EnableDisableButtons(true);
        PhoneBook.Instance.CurrentState = ScreenState.MainMenu;
    }
コード例 #3
0
        public CLI()
        {
            Manager = new ContactManager(DefaultRecordsFile);

            var user = Manager.CreateUser(
                "admin",
                User.UserRole.Admin
                );

            Manager.AddUser(user);

            var contact = Manager.CreateContact(
                "小明",
                ContactUser.ContactGender.Male,
                "Earth (for now)",
                DateTime.Today,
                "GDUT",
                "13800138000"
                );

            Manager.AddContact(contact);

            var comment = Manager.CreateComment(
                contact,
                "This is a test 😀"
                );

            Manager.Dump();
        }
コード例 #4
0
        public void AddContact_CorrectResult()
        {
            // SetUp
            Initialize();

            var contact = new ContactVM()
            {
                Name     = "Name",
                Surname  = "Surname",
                Birthday = DateTime.Now.Date,
                Phone    = "81111111111",
                Vk       = "daniska1616",
                Email    = "*****@*****.**",
            };

            contactManager.AddContact(contact);
        }
コード例 #5
0
        private void OnAddResponse(IMClientPeer peer, OperationResponse response)
        {
            const SubCode subCode = SubCode.Contact_Add_Response;

            if (!TryInitResponse(subCode, peer, response, out var parameters,
                                 ParameterKeys.CONTACT_ADD_CLIENT_RESPONSE, out ContactAddClientResponseModel model))
            {
                return;
            }
            if (peer.LoginUser == null)
            {
                mLogger.ErrorFormat("响应失败!客户端:{0}未登陆!", peer);
                return;
            }
            var contactAddRequest = ContactAddRequestManager.GetContactAddRequest(model.RequestUsername, peer.LoginUser.Username);

            if (contactAddRequest == null)
            {
                peer.SendResponse(ReturnCode.UsernameDoesNotExist, parameters);
                return;
            }

            var responseCode = model.Accept
                ? ContactAddRequest.ContactAddResponseCode.Accept
                : ContactAddRequest.ContactAddResponseCode.Refuse;

            //DB更新
            contactAddRequest.ResponseCode = (int)responseCode;
            ContactAddRequestManager.UpdateContactAddRequest(contactAddRequest);
            var requestUser = UserManager.GetUser(model.RequestUsername);

            if (model.Accept)
            {
                //DB添加
                ContactManager.AddContact(new Contact
                {
                    Username        = model.RequestUsername,
                    ContactUsername = peer.LoginUser.Username
                });
                ContactManager.AddContact(new Contact
                {
                    Username        = peer.LoginUser.Username,
                    ContactUsername = requestUser.Username
                });
            }
            //响应
            ContactAddServerResponseModel responseModel1 = new ContactAddServerResponseModel(false, responseCode, new UserModel(requestUser));

            peer.SendResponse(ReturnCode.Success, parameters.AddParameter(ParameterKeys.CONTACT_ADD_SERVER_RESPONSE, responseModel1));
            //如果请求方在线,发送响应
            if (IMApplication.Instance.TryGetPeerByUsername(model.RequestUsername, out var requestPeer))
            {
                ContactAddServerResponseModel responseModel2 = new ContactAddServerResponseModel(true, responseCode, new UserModel(peer.LoginUser));
                parameters[ParameterKeys.CONTACT_ADD_SERVER_RESPONSE] = responseModel2;
                requestPeer.SendRequest(parameters);
            }
        }
コード例 #6
0
        public bool ProcessReservationPayment(PayPalCheckoutInfo info, byte[] parameters)
        {
            var accepted = false;

            var model = new PayPalListenerModel();

            model.PayPalCheckoutInfo = info;

            if (parameters != null)
            {
                model.ProcessParameters(parameters);
            }

            if (model.IsVerified && model.IsPaymentCompleted)
            {
                int reservationId;
                if (!Int32.TryParse(info.custom, out reservationId))
                {
                    SendOrderNotFoundNotification(info);
                    return(accepted);
                }

                var reservation = GetReservation(reservationId);

                if (reservation == null)
                {
                    SendOrderNotFoundNotification(info);
                    return(accepted);
                }
                reservation.TransactionId = info.txn_id;
                reservation.AmountPaid    = info.Total;
                var isPaymentValid = reservation.AmountPaid == reservation.OrderTotal;


                if (!isPaymentValid)
                {
                    reservation.Status = _appdb.RejectedStatus;
                    SendInvalidPaymentNotifications(reservation);
                }
                else
                {
                    reservation.Status = _appdb.AcceptedStatus;
                    accepted           = true;
                    reservation.PaymentCompletedTimestamp = info.TrxnDate;
                    ContactManager.AddContact(reservation.CustomerInfo);
                    //TODO: Brivo API
                }

                _appdb.SaveChanges();
            }

            return(accepted);
        }
コード例 #7
0
        private static void startContactManager(ContactManager contactManager)
        {
            bool isExit = false;

            Console.WriteLine("Contact Manager Started...!!!");

            while (!isExit)
            {
                Console.WriteLine("Select any option Below:"
                                  + "\n 1. Add new Contact."
                                  + "\n 2. Display Contact."
                                  + "\n 3. Quit."
                                  + "\nEnter Choice: ");

                int       choice = 0;
                const int ADD = 1, DISPLAY = 2, QUIT = 3;

                choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {
                case ADD:
                    Console.WriteLine("Enter Name: ");
                    string contactName = Console.ReadLine();

                    Console.WriteLine("Enter Number: ");
                    string contactNumber = Console.ReadLine();

                    contactManager.AddContact(contactName, contactNumber);

                    break;

                case DISPLAY:
                    Console.WriteLine("Displaying Contacts....\n------------------------------------------------");
                    foreach (Contact contact in contactManager.Contacts)
                    {
                        Console.WriteLine(contact);
                    }
                    Console.WriteLine("---------------------------------------------------");
                    break;

                case QUIT:
                    Console.WriteLine("This Program is now Closed.");
                    isExit = true;
                    break;

                default:
                    Console.WriteLine("Select any option.");
                    break;
                }
            }
        }
コード例 #8
0
        //Create a new Contact
        public string CreateContact(ContactModel _ContactModel)
        {
            ContactDTO _ContactDTO = new ContactDTO();

            _ContactDTO.FirstName   = _ContactModel.FirstName;
            _ContactDTO.LastName    = _ContactModel.LastName;
            _ContactDTO.Id          = _ContactModel.Id;
            _ContactDTO.Email       = _ContactModel.Email;
            _ContactDTO.PhoneNumber = _ContactModel.PhoneNumber;
            _ContactDTO.Status      = true;

            return(_ContactManager.AddContact(_ContactDTO).ToString());
        }
コード例 #9
0
        private async Task ProcessQuestion(Question question)
        {
            if (question.IssueId == null)
            {
                return;
            }
            var emails = question.Content.GetEmails();

            if (emails == null)
            {
                return;
            }

            var issueContacts = ContactManager.GetContactsOfIssue(question.IssueId.Value);
            var issue         = IssueManager.GetById(question.IssueId.Value);
            var nowEmails     = new List <string>();

            if (issueContacts != null && issueContacts.Any())
            {
                nowEmails = issueContacts.Select(t => t.Email).ToList();
            }
            foreach (var email in emails)
            {
                if (!nowEmails.Contains(email))
                {
                    Contact contact = ContactManager.GetByEmail(email);
                    if (contact == null)
                    {
                        contact = new Contact(email)
                        {
                            CreatedBy = User.Identity.Name
                        };
                        ContactManager.AddContact(contact);
                    }
                    ContactManager.MappContactIssue(contact, issue);
                }
                else
                {
                    var contact = ContactManager.GetByEmail(email);
                    contact.Issues.Add(issue);
                    issue.Contacts.Add(contact);
                    await IssueManager.UpdateAsync(issue);

                    ContactManager.MappContactIssue(contact, issue);
                }
            }
        }
コード例 #10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string name   = txtName.Text;
            string number = txtNumber.Text;

            if (name != "" && number != "")
            {
                _contactManager.AddContact(name, number);
                labelStatus.Text = "Contact Added Successfully";
            }
            else
            {
                labelStatus.Text = "fill the Fields to add contact";
            }
            txtName.Text   = "";
            txtNumber.Text = "";
        }
コード例 #11
0
        /// <summary>
        /// Lit et interprète la commande de l'utilisateur.
        /// </summary>
        /// <returns>Un booléen qui indique si l'utilisateur continue l'exécution.</returns>
        private bool ParseAnswer()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(_contactManager.GetPrompt());
            Console.ResetColor();
            string userResponse = Console.ReadLine();
            string command      = userResponse.Split(" ")[0];

            string[] arguments = userResponse.Split(" ").Skip(1).ToArray();

            switch (command)
            {
            case "afficher":
                Console.WriteLine(_contactManager);
                break;

            case "enregistrer":
                SaveToFile(_serializationType);
                break;

            case "charger":
                LoadFromFile(_serializationType);
                break;

            case "ajouterdossier":
            case "addfolder":
                if (arguments.Length == 0)
                {
                    Console.WriteLine("Syntaxe incorrecte. Utilisez: ajouterdossier nom");
                }
                else
                {
                    _contactManager.AddFolder(arguments[0]);
                }
                break;

            case "ajoutercontact":
            case "addcontact":
                if (arguments.Length < 5)
                {
                    Console.WriteLine("Syntaxe incorrecte. Utilisez: ajoutercontact nom prenom email entreprise lien");
                }
                else
                {
                    try
                    {
                        if (_contactManager.AddContact(arguments[0], arguments[1], arguments[2], arguments[3], (Link)Enum.Parse(typeof(Link), arguments[4])))
                        {
                            Console.WriteLine("Contact ajouté");
                        }
                        else
                        {
                            Console.Error.WriteLine("Format de l'email invalide");
                        }
                    }
                    catch (ArgumentException e)
                    {
                        Console.Error.WriteLine($"Ajout du contact impossible: {e.Message}");
                    }
                }
                break;

            case "cd":
                if (arguments.Length == 0)
                {
                    Console.WriteLine("Syntaxe incorrecte. Utilisez: cd chemin. Par exemple: cd ../../dossier1/mondossier");
                }
                else
                {
                    _contactManager.ChangeDirectory(arguments[0]);
                }
                break;

            case "typeserialisation":
                if (arguments.Length == 0)
                {
                    Console.WriteLine("Syntaxe incorrecte. Utilisez: typeserialisation type. Par exemple: typeserialisation xml");
                }
                else
                {
                    _serializationType = arguments[0];
                    Console.WriteLine($"Le type de serialisation utilisé a été modifié en: {_serializationType}");
                }
                break;

            case "sortir":
            case "quit":
                return(false);

            case "":
            case "help":
                ShowHelp();
                break;

            default:
                Console.WriteLine($"La commande \"{command}\" n'a pas été reconnue. Faites help pour avoir la liste.");
                break;
            }
            return(true);
        }
コード例 #12
0
 public IHttpActionResult Post(Contact contact)
 {
     contact.createdOn = DateTime.Now;
     _mgr.AddContact(contact);
     return(Ok());
 }
コード例 #13
0
 public void TestAddContactMethod()
 {
     contactmanager.AddContact("Foo", "8520963");
 }
コード例 #14
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            var newContact = new Contact(name.Text, ipDirection.Text);

            _contactManager.AddContact(newContact);
        }
コード例 #15
0
        public void importFile(string path, bool withNumbersOnly)
        {
            /* Read the initial time. */
            DateTime startTime = DateTime.Now;

            TextReader tr     = new StreamReader(path);
            string     output = "";
            int        count  = 0;

            //Get number of lines so we can update the progress bar
            output = tr.ReadLine();
            while (output != null)
            {
                count++;
                output = tr.ReadLine();
            }
            //after "count" should be the total number of lines in the contacts file

            //display Progress Bar form
            loader.miLoaderProgress.Maximum = count;
            loader.miLoaderProgress.Step    = 1;
            loader.Show();

            // create reader & open file //tofix try catch
            tr = new StreamReader(path);

            // read a line of text
            output = tr.ReadLine();
            // set the header
            Regex regexAdditionals = new Regex(":::", RegexOptions.None);
            Regex regex            = new Regex(",", RegexOptions.None);

            string[] headers = regex.Split(output);
            // Next Line
            output = tr.ReadLine();

            ContactManager     contactManager = new ContactManager(_connectionString, _provider);
            PhoneNumberManager phoneManager   = new PhoneNumberManager(_connectionString, _provider);

            while (output != null)
            {
                string name = "", email = "", numbers = "", desc = "";
                List <contactNumber> contactNumbers = new List <contactNumber>();

                //get the current line output
                string[] csv = regex.Split(output);

                for (int i = 0; i < headers.Length; i++)
                {
                    if (csv[i] != String.Empty)
                    {
                        if (headers[i] == "Name")
                        {
                            name = csv[i] + " ";
                        }
                        //Emails
                        else if (headers[i].StartsWith("E-mail") && headers[i].EndsWith("Value"))
                        {
                            if (csv[i].Contains(":::"))
                            {
                                string[] splitEmails = regexAdditionals.Split(csv[i]);
                                foreach (string eAddress in splitEmails)
                                {
                                    email += eAddress + ", ";
                                }
                            }
                            else
                            {
                                email += csv[i];
                            }
                        }
                        //Phone numbers
                        else if ((headers[i].StartsWith("Phone")) && (headers[i].EndsWith("Type")))
                        {
                            if (csv[i + 1].Contains(":::"))
                            {
                                string[] splitNumbers = regexAdditionals.Split(csv[i + 1]);
                                foreach (string number in splitNumbers)
                                {
                                    if (csv[i] != String.Empty)
                                    {
                                        contactNumbers.Add(new contactNumber(csv[i], number));
                                    }
                                    numbers += " " + csv[i] + ": " + number;
                                }
                            }
                            else
                            {
                                if (csv[i] != String.Empty)
                                {
                                    contactNumbers.Add(new contactNumber(csv[i], csv[i + 1]));
                                }
                                numbers += " " + csv[i] + ": " + csv[i + 1];
                            }
                        }
                        //description info
                        else if ((headers[i] == "Organization 1 - Name") || (headers[i] == "Organization 1 - Title") || (headers[i] == "Notes"))
                        {
                            if (desc == String.Empty)
                            {
                                desc += csv[i];
                            }
                            else
                            {
                                desc += " - " + csv[i];
                            }
                        }
                    }
                }

                //Clean the data
                name  = name.Trim().Replace("\"", "").Replace("'", "");
                desc  = desc.Trim().Replace("\"", "").Replace("'", "");
                email = email.Trim().Replace("\"", "").Replace("'", "");

                //Create a new Contact
                List <ValidationError> errors = new List <ValidationError>();

                // Add the contact into the database
                if ((!withNumbersOnly) || (contactNumbers.Count > 0))
                {
                    errors = contactManager.AddContact(name, desc, email);
                }


                //tofix throw errors

                loader.miLoaderProgress.PerformStep();

                foreach (contactNumber cont in contactNumbers)
                {
                    cont.id   = contactManager._lastid;
                    cont.type = "External";

                    //#### Option 1 - 23.73 seconds
                    //ThreadPool.QueueUserWorkItem(new WaitCallback(phoneManager.AddPhoneNumberNoReturn), cont);

                    //#### Option 2 - 20.76 seconds
                    try
                    {
                        errors = phoneManager.AddPhoneNumber(cont.id, cont.number, cont.description, cont.type);
                    }
                    catch (Exception ex)
                    {
                        errors.Add(new ValidationError(ex.ToString()));
                    }

                    if (errors.Count > 0)
                    {
                        MessageBox.Show("Error occured when importing the phone numbers");
                        foreach (ValidationError err in errors)
                        {
                            loader.showMsg(err.GetMesssage());
                        }
                    }
                    //#### Option 3 - 22.93 seconds
                    //ThreadedContactAdder fetcher = new ThreadedContactAdder(cont,_connectionString,_provider);
                    //new Thread(new ThreadStart(fetcher.AddNumber)).Start();
                }

                // Next Line
                output = tr.ReadLine();
            }

            /* Read the end time. */
            DateTime stopTime = DateTime.Now;

            /* Compute the duration between the initial and the end time. */
            TimeSpan duration = stopTime - startTime;

            loader.showMsg(duration.ToString());

            loader.Close();
            // close the stream
            tr.Close();
        }
コード例 #16
0
        public List <ValidationError> ReadCsv(string path, bool withNumbersOnly)
        {
            /* Read the initial time. */
            DateTime startTime            = DateTime.Now;
            List <ValidationError> errors = new List <ValidationError>();

            int _i = 0;

            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(new StreamReader(path), true))
            {
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();

                Regex regexAdditionals = new Regex(":::", RegexOptions.None);

                loader.miLoaderProgress.Maximum = fieldCount;
                loader.miLoaderProgress.Step    = 1;
                loader.Show();
                ContactManager     contactManager = new ContactManager(_connectionString, _provider);
                PhoneNumberManager phoneManager   = new PhoneNumberManager(_connectionString, _provider);

                while (csv.ReadNextRecord())
                {
                    string name = "", email = "", numbers = "", desc = "";
                    List <contactNumber> contactNumbers = new List <contactNumber>();


                    for (int i = 0; i < fieldCount; i++)
                    {
                        //Console.Write(string.Format("{0} = {1};", headers[i], csv[i]));
                        _i = i;
                        if (csv[i] != String.Empty)
                        {
                            if (headers[i] == "Name")
                            {
                                name = csv[i] + " ";
                            }
                            //Emails
                            else if (headers[i].StartsWith("E-mail") && headers[i].EndsWith("Value"))
                            {
                                if (csv[i].Contains(":::"))
                                {
                                    string[] splitEmails = regexAdditionals.Split(csv[i]);
                                    foreach (string eAddress in splitEmails)
                                    {
                                        email += eAddress + ", ";
                                    }
                                }
                                else
                                {
                                    email += csv[i];
                                }
                            }
                            //Phone numbers
                            else if ((headers[i].StartsWith("Phone")) && (headers[i].EndsWith("Type")))
                            {
                                if (csv[i + 1].Contains(":::"))
                                {
                                    string[] splitNumbers = regexAdditionals.Split(csv[i + 1]);
                                    foreach (string number in splitNumbers)
                                    {
                                        if (csv[i] != String.Empty)
                                        {
                                            contactNumbers.Add(new contactNumber(csv[i], number));
                                        }
                                        numbers += " " + csv[i] + ": " + number;
                                    }
                                }
                                else
                                {
                                    if (csv[i] != String.Empty)
                                    {
                                        contactNumbers.Add(new contactNumber(csv[i], csv[i + 1]));
                                    }
                                    numbers += " " + csv[i] + ": " + csv[i + 1];
                                }
                            }
                            //description info
                            else if ((headers[i] == "Organization 1 - Name") || (headers[i] == "Organization 1 - Title") || (headers[i] == "Notes"))
                            {
                                if (desc == String.Empty)
                                {
                                    desc += csv[i];
                                }
                                else
                                {
                                    desc += " - " + csv[i];
                                }
                            }
                        }
                    }

                    //Clean the data
                    name  = name.Trim().Replace("\"", "").Replace("'", "");
                    desc  = desc.Trim().Replace("\"", "").Replace("'", "");
                    email = email.Trim().Replace("\"", "").Replace("'", "");


                    // Add the contact into the database
                    if ((!withNumbersOnly) || (contactNumbers.Count > 0))
                    {
                        //Create a new error list
                        List <ValidationError> contactErrors = new List <ValidationError>();
                        try
                        {
                            contactErrors = contactManager.AddContact(name, desc, email);
                        }
                        catch (Exception ex)
                        {
                            contactErrors.Add(new ValidationError(ex.ToString()));
                        }

                        if (errors.Count > 0)
                        {
                            foreach (ValidationError err in contactErrors)
                            {
                                errors.Add(err);
                            }
                        }
                        else
                        {
                            foreach (contactNumber cont in contactNumbers)
                            {
                                cont.id   = contactManager._lastid;
                                cont.type = "External";
                                if (cont.id != String.Empty)
                                {
                                    List <ValidationError> newErrors = phoneManager.AddPhoneNumber(cont.id, cont.number, cont.description, cont.type);
                                    if (newErrors.Count > 0)
                                    {
                                        foreach (ValidationError err in newErrors)
                                        {
                                            errors.Add(err);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //tofix throw errors
                    loader.miLoaderProgress.PerformStep();
                }
            }

            /* Read the end time. */
            DateTime stopTime = DateTime.Now;

            /* Compute the duration between the initial and the end time. */
            TimeSpan duration = stopTime - startTime;

            loader.showMsg(duration.ToString() + "  and i=" + _i);

            loader.Close();
            return(errors);
        }
コード例 #17
0
        public void ShouldBeAbleToAddNewContact()
        {
            _contactManager.AddContact("Josh", "Carroll", "(865)555-5555");

            _mockDataAccess.Verify(svc => svc.AddContact("Josh", "Carroll", "8655555555"));
        }
コード例 #18
0
ファイル: Main.aspx.cs プロジェクト: VK90/BootstrapTest
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (tbSSNtmp.Text == "")
            {
                if (tbFName.Text != "" && tbLName.Text != "" && tbSSN.Text != "")
                {
                    ContactManager.AddContact(tbFName.Text, tbLName.Text, tbSSN.Text, CON_STR);
                    Response.Redirect("~/Main.aspx");
                }
                else
                {
                    Response.Write($"<script('#MyErrormessagescript>').style='display=block'</script>");
                }
            }
            else
            {
                string ssn = tbSSNtmp.Text;
                string id  = ContactManager.GetContactId(ssn, CON_STR);
                ContactList.Contact tmpContact = ContactManager.GetContactInfoById(id, CON_STR);

                if (id != "" && tmpContact != null)
                {
                    string fname  = "";
                    string lname  = "";
                    string newSSN = ssn;

                    if (tbFName.Text != "")
                    {
                        fname = tbFName.Text;
                    }
                    else
                    {
                        fname = tmpContact.FirstName;
                    }

                    if (tbLName.Text != "")
                    {
                        lname = tbLName.Text;
                    }
                    else
                    {
                        lname = tmpContact.LastName;
                    }

                    if (tbSSN.Text != "")
                    {
                        newSSN = tbSSN.Text;
                    }
                    else
                    {
                        newSSN = ssn;
                    }
                    int test = 0;

                    Contact tmpCon = new Contact(fname, lname, newSSN);

                    try
                    {
                        DateTime de = new DateTime();
                        if (DateTime.TryParse(tmpCon.PersonNr.Substring(0, 4) + "-" + tmpCon.PersonNr.Substring(4, 2) + "-" + tmpCon.PersonNr.Substring(6, 2), out de))
                        {
                            test = 1;
                        }
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex);
                    }

                    if (test == 1)
                    {
                        ContactManager.EditContact(id, fname, lname, newSSN, CON_STR);
                    }
                }
            }
            Response.Redirect("~/Main.aspx");
        }