ProviderHostedCustomUIActionsWeb.Models.ContactsListManager.AddNewContacts C# (CSharp) Method

AddNewContacts() public method

public AddNewContacts ( int CustomerCount ) : void
CustomerCount int
return void
        public void AddNewContacts(int CustomerCount)
        {
            for (int i = 1; i <= CustomerCount; i++) {
            ListItem newItem = contactsList.AddItem(new ListItemCreationInformation());
            Customer customer = CustomerFactory.GetRandomCustomer();
            newItem["FirstName"] = customer.FirstName;
            newItem["Title"] = customer.LastName;
            newItem["Company"] = customer.Company;
            newItem["Email"] = customer.EmailAddress;
            newItem["WorkPhone"] = customer.WorkPhone;
            newItem["HomePhone"] = customer.HomePhone;
            newItem.Update();
            clientContext.ExecuteQuery();
              }
        }

Usage Example

 public ActionResult AddTenItems(string SPListId)
 {
     ContactsListManager contactsListManager = new ContactsListManager(new Guid(SPListId));
       contactsListManager.AddNewContacts(10);
       return View();
 }