public ActionResult Index()
 {
     ViewBag.ErrMsg = string.Empty;
     ViewBag.Msg = "Thank you for Visiting us! Please fill in the information below, We will definitely get back to you.";
     Person p = new Person();
     return View(p);
 }
        public ActionResult Index(Person p)
        {
            ViewBag.ErrMsg = string.Empty;
            ViewBag.Msg = string.Empty;

            if (!ModelState.IsValid)
            {
                ViewBag.Msg = "Thank you for Visiting us! Please fill in the information below, We will definitely get back to you.";
                return View(p);
            }

            try
            {
                GetInvolvedDAO.Save(p);
            }
            catch(Exception e)
            {
                ViewBag.ErrMsg = "There is a connection problem, please resubmit.";
                return View(p);
            }

             //this will hold email of person
            string emailBody = getVolunteerInfo(p);
            try
            {
                sendGmail(emailBody);
            }
            catch (SmtpException e)
            {
                ViewBag.Msg = "Your information is saved, sorry the Email didnt go thru we will look into it! ";
            }
            ViewBag.Msg = ViewBag.Msg+"Thank you for showing interest in Bitiya, it means a lot to us. We will definitely get back to you!";
            return View(p);
        }
Exemple #3
0
        public static void Save(Person p)
        {
            string name = "ApplicationServices";
            string arvix_connect = getConnectionStringByName(name);

            SqlConnection myConnection = new SqlConnection(arvix_connect);

            string sp_Name = "up_insertGetInvolved";

            SqlCommand myCommand = new SqlCommand(sp_Name, myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter fName = new SqlParameter("@FirstName", p.Firstname ?? string.Empty);
            myCommand.Parameters.Add(fName);

            SqlParameter lName = new SqlParameter("@LastName", p.Lastname ?? string.Empty);
            myCommand.Parameters.Add(lName);

            SqlParameter address = new SqlParameter("@Address", p.Address ?? string.Empty);
            myCommand.Parameters.Add(address);

            SqlParameter city = new SqlParameter("@City", p.City ?? string.Empty);
            myCommand.Parameters.Add(city);

            SqlParameter state = new SqlParameter("@State", p.State ?? string.Empty);
            myCommand.Parameters.Add(state);

            SqlParameter zip = new SqlParameter("@zip", p.Zip ?? string.Empty);
            myCommand.Parameters.Add(zip);

            SqlParameter email = new SqlParameter("@Email", p.Email ?? string.Empty);
            myCommand.Parameters.Add(email);

            SqlParameter phone = new SqlParameter("@Phone", p.Phone ?? string.Empty);
            myCommand.Parameters.Add(phone);

            SqlParameter avail = new SqlParameter("@Availability", p.Availability ?? string.Empty);
            myCommand.Parameters.Add(avail);

            SqlParameter events = new SqlParameter("@Events", p.Volunteer ?? string.Empty);
            myCommand.Parameters.Add(events);

            SqlParameter funds = new SqlParameter("@Funds", p.Fundraising ?? string.Empty);
            myCommand.Parameters.Add(funds);

            SqlParameter skills = new SqlParameter("@Skills", p.Interests ?? string.Empty);
            myCommand.Parameters.Add(skills);

            SqlParameter ideas = new SqlParameter("@Ideas", p.Suggestions ?? string.Empty);
            myCommand.Parameters.Add(ideas);

            myConnection.Open();

            int noofrows = myCommand.ExecuteNonQuery();
            myConnection.Close();
        }
        protected string getVolunteerInfo(Person p)
        {
            // create a string variable to generate message
            StringBuilder messageTable = new StringBuilder();

            string[] cellValues = new string[3];

            Type myType = p.GetType();
            IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());

            messageTable.Append("<h3>Get Involved Information</h3><br />");
            foreach (PropertyInfo prop in props)
            {
                object propValue = prop.GetValue(p, null);

                //prop.GetValue(p,null)
                string rowStr = string.Format("{0} : <span style=\" font-weight: bold;\">{1}</span><br />", prop.Name, prop.GetValue(p, null));
                // Do something with propValue
                messageTable.Append(rowStr);
            }

            return messageTable.ToString();
        }