Ejemplo n.º 1
0
        //Add new contact person to the database table
        public bool AddContactPerson(CreateContactPersonViewModel p)
        {
            connection();
            SqlCommand com = new SqlCommand("INSERT into ContactPersons values(@FirstName, @LastName, @Email, @Telephone, @SelectedCompanyId)", _con);

            com.CommandType = CommandType.Text;
            com.Parameters.AddWithValue("@FirstName", p.FirstName);
            com.Parameters.AddWithValue("@LastName", p.LastName);
            com.Parameters.AddWithValue("@Email", p.Email);
            com.Parameters.AddWithValue("@Telephone", p.Telephone);
            com.Parameters.AddWithValue("@SelectedCompanyId", p.SelectedCompanyId);

            _con.Open();
            int i = com.ExecuteNonQuery();

            _con.Close();
            if (i >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        //Load Company list to the create contact person form dropdown!
        public CreateContactPersonViewModel CreateEmpty(CreateContactPersonViewModel ViewModel)
        {
            DataManager dm = new DataManager();

            var companies = dm.GetAllCompanies();

            ViewModel.Companies = companies.Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.CompanyName,
            }).ToList();

            return(ViewModel);
        }
Ejemplo n.º 3
0
        public ActionResult Create(CreateContactPersonViewModel vm)
        {
            DataManager dm = new DataManager();

            try
            {
                if (ModelState.IsValid)
                {
                    dm.AddContactPerson(vm);
                }



                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }