public bool merge(VacancyKillerQuestionDTO entity)
    {
        try
        {
            var addObj = (from p in ctx.VacancyKillerQuestions
                       where p.question == @entity.question && p.vacancyNumber == @entity.vacancyNumber
                       select p).Single();

            model.VacancyKillerQuestion obj = (VacancyKillerQuestion)addObj;

            /*Update*/
            obj.question = entity.question;
            obj.vacancyNumber = entity.vacancyNumber;
            obj.answer = entity.answer;

            ctx.SubmitChanges();
            return true;
        }
        catch (Exception e)
        {
            model.Log log = new Log();
            log.message = "VacancyKillerQuestion Merge: " + " [" + entity.question + " , " + entity.vacancyNumber + "] " + e.Message;
            ctx.SubmitChanges();

            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }
    public VacancyKillerQuestionDTO find(string question, string vacancyNumber)
    {
        var obj = (from p in ctx.VacancyKillerQuestions
                   where p.question == @question && p.vacancyNumber == @vacancyNumber
                   select p).Single();

        VacancyKillerQuestionDTO add = new VacancyKillerQuestionDTO();
        add.vacancyNumber = obj.vacancyNumber;
        add.question = obj.question;

        return add;
    }
    public VacancyKillerQuestionDTO find(string vacancyNumber, string question)
    {
        VacancyKillerQuestionDTO info = new VacancyKillerQuestionDTO();
        SqlConnection oConn = new SqlConnection();
        SqlCommand sqlCmd = null;

        try
        {
            oConn.ConnectionString = ConfigurationManager.AppSettings["conn"];
            oConn.Open();

            sqlCmd = oConn.CreateCommand();
            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.CommandText = "select * from VacancyKillerQuestion where vacancyNumber = '" + vacancyNumber + "' AND question = '" + question + "'";

            SqlDataReader rdr = sqlCmd.ExecuteReader();

            if (rdr.HasRows)
            {
                while (rdr.Read())
                {
                    info.vacancyNumber = rdr["vacancyNumber"].ToString();
                    info.question = rdr["question"].ToString();
                    info.answer = rdr["answer"].ToString();

                }
            }

        }
        catch
        { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return info;
    }
    public List<VacancyKillerQuestionDTO> findAll()
    {
        var objs = (from p in ctx.VacancyKillerQuestions
                    select p);
        VacancyKillerQuestionDTO add = null;
        List<VacancyKillerQuestionDTO> addList = new List<VacancyKillerQuestionDTO>();
        foreach (VacancyKillerQuestion obj in objs)
        {
            add = new VacancyKillerQuestionDTO();
            add.question = obj.question;
            add.vacancyNumber = obj.vacancyNumber;
            add.answer = obj.answer;

            addList.Add(add);
        }
        return addList;
    }
        public void VacancyKillerQuestionDAOConstructorTest()
        {
            /*Context*/
            VacancyKillerQuestionDAO vacKill_context = new VacancyKillerQuestionDAO();
            VacancyDAO vac_context = new VacancyDAO();

            /*Insert*/
            VacancyDTO vac = new VacancyDTO();
            vac.department = "IS";
            vac.description = "Web services";
            vac.manager = "Tom";
            vac.recruiter = "Thumi";
            vac.site = "www.petrosa.co.za";
            vac.startDate = new DateTime(2012, 10, 10);
            vac.endDate = new DateTime(2012, 12, 1);
            vac.description = "desktop support";
            vac.title = "support technician";
            vac.vacancyNumber = "1";
            vac.viewCount = 10;
            vac.viewStatus = "published";
            vac.status = "active";

            vac_context.presist(vac);

            VacancyKillerQuestionDTO vacKill = new VacancyKillerQuestionDTO();
            vacKill.vacancyNumber = "1";
            vacKill.question = "Do you have a BTech";
            vacKill.answer = "Yes";

            Assert.AreEqual(vacKill_context.presist(vacKill), true);

            /*Update*/
            vacKill.answer = "No";
            vacKill_context.merge(vacKill);
            Assert.AreEqual(vacKill.answer, "No");

            /*Delete*/
            Assert.AreEqual(vacKill_context.removeByUserId("1", "Do you have a BTech"), true);
            vac_context.removeByUserId("1");
        }
 public bool remove(VacancyKillerQuestionDTO entity)
 {
     return this.removeByUserId(entity.question, entity.vacancyNumber);
 }
    public bool presist(VacancyKillerQuestionDTO entity)
    {
        try
        {
            model.VacancyKillerQuestion obj = new VacancyKillerQuestion();
            obj.question = entity.question;
            obj.vacancyNumber = entity.vacancyNumber;
            obj.answer = entity.answer;

            ctx.VacancyKillerQuestions.InsertOnSubmit(obj);
            ctx.SubmitChanges();
            return true;
        }
        catch (Exception)
        {
            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }
    public bool presist(VacancyKillerQuestionDTO entity)
    {
        bool success = false;
        SqlConnection oConn = new SqlConnection();
        SqlCommand sqlCmd = null;

        try
        {
            oConn.ConnectionString = ConfigurationManager.AppSettings["conn"];
            oConn.Open();

            sqlCmd = oConn.CreateCommand();
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "insertVacancyKillerQuestion";
            sqlCmd.Parameters.Add(new SqlParameter("vacancyNumber", entity.vacancyNumber));
            sqlCmd.Parameters.Add(new SqlParameter("question", entity.question));
            sqlCmd.Parameters.Add(new SqlParameter("answer", entity.answer));

            SqlDataReader rdr = sqlCmd.ExecuteReader();
            if (rdr.HasRows)
            {
                while (rdr.Read())
                { } //Read all
            }
            rdr.Close();

            if (rdr.RecordsAffected > 0)
                success = true;
        }
        catch { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return success;
    }
 public void setKillerQuestionDto(VacancyKillerQuestionDTO userDto)
 {
     view.setAnswer(userDto.answer);
     view.setQuestion(userDto.question);
 }
 public VacancyKillerQuestionDTO getKillerQuestionDto()
 {
     VacancyKillerQuestionDTO questionDto = new VacancyKillerQuestionDTO();
     questionDto.answer = view.getAnswer();
     questionDto.question = view.getQuestion();
     questionDto.vacancyNumber = view.getVacancyNumber();
     return questionDto;
 }