public List <interviewmodel> GetData(string query)
        {
            interviewList = new List <interviewmodel>();
            string strConnString = ConfigurationManager.ConnectionStrings["mvcapp_connection"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(strConnString))
            {
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = query;
                    cmd.Connection.Open();
                    using (var r = cmd.ExecuteReader())
                    {
                        interviewmodel inv;

                        while (r.Read())
                        {
                            inv               = new interviewmodel();
                            inv.Gender        = r.GetString(0);
                            inv.Title         = r.GetString(1);
                            inv.Occupation    = r.GetString(2);
                            inv.Company       = r.GetString(3);
                            inv.GivenName     = r.GetString(4);
                            inv.MiddleInitial = r.GetString(5);
                            inv.Surname       = r.GetString(6);
                            inv.BloodType     = r.GetString(7);
                            inv.EmailAddress  = r.GetString(8);
                            interviewList.Add(inv);
                        }
                    }
                }
            }

            return(interviewList);
        }
        public JsonResult AddInterview(interviewmodel inv)
        {
            string status  = "";
            bool   success = false;

            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["mvcapp_connection"].ConnectionString;
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "INSERT INTO TBL_INTERVIEW(Gender,Title,Occupation,Company,GivenName," +
                                              "MiddleInitial,Surname,BloodType,EmailAddress) " +
                                              "VALUES( @Gender,@Title,@Occupation,@Company,@GivenName, " +
                                              "@MiddleInitial,@Surname,@BloodType,@EmailAddress)";

                        command.Parameters.AddWithValue("@Gender", inv.Gender);
                        command.Parameters.AddWithValue("@Title", inv.Title);
                        command.Parameters.AddWithValue("@Occupation", inv.Occupation);
                        command.Parameters.AddWithValue("@Company", inv.Company);
                        command.Parameters.AddWithValue("@GivenName", inv.GivenName);
                        command.Parameters.AddWithValue("@MiddleInitial", inv.MiddleInitial);
                        command.Parameters.AddWithValue("@Surname", inv.Surname);
                        command.Parameters.AddWithValue("@BloodType", inv.BloodType);
                        command.Parameters.AddWithValue("@EmailAddress", inv.EmailAddress);

                        command.ExecuteNonQuery();

                        if (interviewList == null)
                        {
                            interviewList = new List <interviewmodel>();
                        }
                        interviewList.Add(inv);

                        status  = "Save success";
                        success = true;
                    }
                }
            }
            catch (SqlException ex)
            {
                status  = "Save failed. " + ex.Message;
                success = false;
            }
            catch (Exception ex)
            {
                status  = "Save failed. " + ex.Message;
                success = false;
            }

            return(new JsonResult {
                Data = new { status = status, success = success }
            });
        }