public void ContactManager_works()
        {
            List <Contact2> contacts = new List <Contact2>
            {
                new Contact2 {
                    Name = "Homer", Iq = 50
                },
                new Contact2 {
                    Name = "Lisa", Iq = 120
                },
                new Contact2 {
                    Name = "Bart", Iq = 90
                },
            };

            var contactManager = new ContactManager();

            contactManager.Add(contacts);

            var filterStrategy = new FilterStrategy();

            contactManager.Filter(filterStrategy);

            var            formattedStrings = contactManager.Format(new SimpleFormatStrategy());
            IPrintStrategy printStrategy    = new PrintStrategy();

            var result = contactManager.Print(formattedStrings, printStrategy);

            result.Should().Be("Lisa,Bart");
        }
コード例 #2
0
        public ActionResult Index(ContactViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var contact = _contactManager.Add(model.Contact);
                    var body    = new StringBuilder();
                    body.AppendLine("Ad: " + contact.Firstname);
                    body.AppendLine("Soyad: " + contact.Lastname);
                    body.AppendLine("E-Mail Adresi: " + contact.Email);
                    body.AppendLine("Konu: " + contact.TopicTitle);
                    body.AppendLine("Mesaj: " + contact.Message);
                    MailHelper.SendMail(body.ToString(), "", contact.TopicTitle, false);
                    return(RedirectToAction(actionName: "Index", controllerName: "Home"));
                }

                catch (Exception exception)
                {
                    return(RedirectToAction(actionName: "Index", controllerName: "Error", routeValues: new { message = "Sistemsel bir hata oluştu" }));
                }
            }

            return(RedirectToAction(actionName: "Index", controllerName: "Error", routeValues: new { message = "Bilgileri eksik girdiniz!" }));
        }
コード例 #3
0
        /// <summary>
        /// Обработчик события при нажатии на кнопку сохранения контакта.
        /// </summary>
        private void saveButton_Click(object sender, EventArgs e)
        {
            bool hasError = false; //Флаг наличия ошибок на форме.

            resetInputs();
            //Проверяем поля на пустоту, если поле пустое, то помечаем его красным цветом
            foreach (var control in _inputs.Where(control => string.IsNullOrWhiteSpace(control.Text)))
            {
                hasError          = true;
                control.BackColor = Color.Red;
            }
            // Поля MaskedTextBox должны быть заполнены польностью
            foreach (var control in _inputs.OfType <MaskedTextBox>().Where(t => t.Text.Length != t.Mask.Length))
            {
                hasError          = true;
                control.BackColor = Color.Red;
            }

            if (hasError)
            {
                MessageBox.Show("Не все поля заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (_adding)
            {
                var c = new Contact()
                {
                    Surname     = surnameTextBox.Text,
                    Name        = nameTextBox.Text,
                    Group       = groupTextBox.Text,
                    Phone       = phoneMaskedTextBox.Text,
                    MobilePhone = mobliePhoneMaskedTextBox.Text,
                    Photo       = new Bitmap(pictureBox1.BackgroundImage)
                };
                _manager.Add(c);
            }
            else if (_editing)
            {
                _selectedContactForEditing.Surname     = surnameTextBox.Text;
                _selectedContactForEditing.Name        = nameTextBox.Text;
                _selectedContactForEditing.Group       = groupTextBox.Text;
                _selectedContactForEditing.Phone       = phoneMaskedTextBox.Text;
                _selectedContactForEditing.MobilePhone = mobliePhoneMaskedTextBox.Text;
                _selectedContactForEditing.Photo       = new Bitmap(pictureBox1.BackgroundImage);
                _manager.Update(_selectedContactForEditing);
            }
            _startEditOrAdd = false;
            hideOrShowControlsForAdd(false);
            _editing = false;
            if (groupCheckBox.Checked)
            {
                fillTree(_manager.GroupContact);
            }
            else
            {
                fillList(_manager.Contacts);
            }
            searchTextBox.Text = "";
        }
コード例 #4
0
 public IActionResult Create([Bind("Id,FirstName,LastName,Email,PhoneNumber")] StudentViewModel studentViewModel)
 {
     if (ModelState.IsValid)
     {
         Student student = MapToStudent(studentViewModel);
         _contactManager.Add(student);
         return(RedirectToAction(nameof(Index), new { message = "create" }));
     }
     return(View());
 }
コード例 #5
0
        private void SaveContactButton_Click(object sender, EventArgs e)
        {
            try
            {
                XMLHelper helper = new XMLHelper();

                Mail_Client.Models.Contact NewContact = new Models.Contact();
                NewContact.ID    = helper.LastElementUniqueID(_location + "Contacts.xml", "Contact") + 1;
                NewContact.Name  = NameTextbox.Text;
                NewContact.Email = EmailIDTextbox.Text;

                contactManager.Add(NewContact);

                MessageBox.Show("New Contact: " + NewContact.Name + " Added Successfully");

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Some Unexpected error has occured while adding new contact. Please try again after sometime.");
            }
        }
コード例 #6
0
        public void AddContact_Test()
        {
            _manager.Add(TEACHER);

            IList <Contact> contacts = _manager.GetAll().ToList();

            Assert.Equal(1, contacts.Count);
            Contact contact = contacts.First();

            Assert.Equal("Kenneth", contact.FirstName);
        }
コード例 #7
0
    protected override void ActionAdminDo()
    {
        string content = Request.Unvalidated["content"];


        ContactManager CM      = new ContactManager();
        ContactTBx     contact = new ContactTBx();

        contact.Content = content;

        contact.Status = 1;
        CM.Add(contact);
        Response.Write(1);
    }
コード例 #8
0
        private void button4_Click(object sender, EventArgs e)
        {
            AddCont add_Category = new AddCont(CategoriesManager);

            if (add_Category.ShowDialog() == DialogResult.OK)
            {
                ContactManager.
                Add(add_Category.Name,
                    add_Category.Adress,
                    add_Category.Email,
                    add_Category.Phone,
                    add_Category.Telegram,
                    add_Category.Viber,
                    add_Category.Category);
                LoadContacts();
            }
        }
コード例 #9
0
        private static void MenuWorker(MenuOption menuOption)
        {
            ContactManager contactManager = new ContactManager();

            switch (menuOption)
            {
            case MenuOption.add:
                contactManager.Add();
                Continue();
                break;

            case MenuOption.delete:
                contactManager.PrintAll();
                contactManager.RemoveContact();
                Continue();
                break;

            case MenuOption.update:
                contactManager.UpdateUserInformation();
                Continue();
                break;

            case MenuOption.view:
                contactManager.PrintAll();
                Continue();
                break;

            case MenuOption.search:
                contactManager.Search();
                Continue();
                break;

            case MenuOption.quit:
                break;

            case MenuOption.unknown:
            default:
                Console.WriteLine();
                Console.WriteLine("Please, read menu options and try again.");
                Console.ReadKey(true);
                Console.Clear();
                Main();
                break;
            }
        }
コード例 #10
0
        public IActionResult Post([FromBody] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Contact newContact = contactManager.Add(contact);

                return(Created($"contacts/{newContact.ContactId}", newContact));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to insert contact: {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
コード例 #11
0
        public void AddTest()
        {
            var mockSet     = new Mock <DbSet <Contact> >();
            var mockContext = new Mock <ContactModel>();

            mockContext.Setup(c => c.Contacts).Returns(mockSet.Object);

            var contactManager = new ContactManager(mockContext.Object);
            var contact        = new Contact()
            {
                FirstName    = "Shivam",
                PrimaryEmail = "*****@*****.**",
                PrimaryPhone = 9899007541
            };

            contactManager.Add(contact);

            mockSet.Verify(m => m.Add(It.IsAny <Contact>()), Times.Once);
            mockContext.Verify(m => m.SaveChanges(), Times.Once);
        }
コード例 #12
0
        /// <summary>
        /// Add operation of the AddPatientCmd.
        /// Operation that will be performormed on the control click.
        /// </summary>
        /// <param name="obj"></param>
        public void Add(object obj)
        {
            //Always create a new instance of patient before adding.
            //Otherwise we will endup sending the same instance that is binded, to the BL which will cause complications
            var contact = new Contact  {
                Id = Id, Name = Name, MobileNumber = MobileNumber, EmailId = EmailId, City = City, State = State
            };

            //Add patient will be successfull only if the patient with same ID does not exist.
            if (contactManager.Add(contact))
            {
                Contacts.Add(contact);
                ResetPatient();
                MessageBox.Show("Contact Add Successful !");
            }
            else
            {
                MessageBox.Show("Contact with this ID already exists !");
            }
        }
コード例 #13
0
 private void button_add_mail_id_Click(object sender, EventArgs e)
 {
     try
     {
         ContactManager manager = new ContactManager();
         manager.Add(new Contact()
         {
             ID = counter, Name = string.Empty, Email = textBox_email_id.Text
         });
         var c = manager.GetSingle(counter);
         MessageBox.Show(c.ToString());
         counter++;
     }
     catch (Exception ex)
     {
         counter++;
         MessageBox.Show("Something went wrong");
     }
     //FileReadWrite.path = FileReadWrite.GetCurrentDirectoryPath + "\\Data\\Groups\\__All Mail IDs.txt";
     //FileReadWrite.WriteInFileTextBoxContent(textBox_email_id.Text);
     MessageBox.Show("Mail Id Added Successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
     textBox_email_id.Clear();
 }