public bool merge(BasicEduSubjectDTO entity)
    {
        try
        {
            var addObj = (from p in ctx.BasicEduSubjects
                       where p.userName == @entity.userName && p.subjectName == @entity.subjectName
                       select p).Single();

            model.BasicEduSubject obj = (BasicEduSubject)addObj;

            /*Update*/
            obj.userName = entity.userName;
            obj.subjectName = entity.subjectName;
            obj.subjectDescription = entity.subjectDescription;

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

            ctx.Dispose();
            ctx = new ModelDataContext();
            ctx.SubmitChanges();

            return false;
        }
    }
    public BasicEduSubjectDTO find(string userName, string subjectName)
    {
        var obj = (from p in ctx.BasicEduSubjects
                   where p.userName == @userName && p.subjectName == @subjectName
                   select p).Single();

        BasicEduSubjectDTO add = new BasicEduSubjectDTO();
        add.userName = obj.userName;
        add.subjectName = obj.subjectName;
        add.subjectDescription = obj.subjectDescription;
        return add;
    }
        public void BasicEduSubjectDAOConstructorTest()
        {
            /*Context*/
            BasicEduSubjectDAO basicEdu_context = new BasicEduSubjectDAO();
            BasicEduDAO edu_context = new BasicEduDAO();
            AccountDAO acc_context = new AccountDAO();

            /*Insert*/
            AccountDTO acc = new AccountDTO();
            acc.userName = "******";
            acc.password = "******";
            acc.accountType = "administrator";
            acc.status = "active";

            acc_context.presist(acc);

            BasicEduDTO basic_Edu = new BasicEduDTO();
            basic_Edu.userName = "******";
            basic_Edu.country = "South Africa";
            basic_Edu.levelCompleted = 12;
            basic_Edu.province = "WP";
            basic_Edu.school = "Brackenfell High School";
            basic_Edu.town = "Cape Town";

            edu_context.presist(basic_Edu);

            BasicEduSubjectDTO basicEduSub = new BasicEduSubjectDTO();
            basicEduSub.subjectName = "Technical Programming";
            basicEduSub.subjectDescription = "Mr Kabaso is Awesome";
            basicEduSub.userName = "******";

            basicEdu_context.presist(basicEduSub);

            /*Update*/
            basicEduSub.subjectDescription = "Mr Kabaso is Awesome!";
            basicEdu_context.merge(basicEduSub);

            string expectedUpdate = "Mr Kabaso is Awesome!";
            BasicEduSubjectDTO updateEduSub = basicEdu_context.find("john", "Technical Programming");
            Assert.AreEqual(expectedUpdate, updateEduSub.subjectDescription);

            /*Delete*/
            basicEdu_context.removeByUserId("john", "Technical Programming");
            bool expectedDelBasicEduSub = false;
            bool actualDelBasicEduSub = basicEdu_context.isFound("john", "Technical Programming");
            Assert.AreEqual(expectedDelBasicEduSub, actualDelBasicEduSub);
            edu_context.removeByUserId("john");
            acc_context.removeByUserId("john");
        }
    public BasicEduSubjectDTO find(string userName, string subjectName)
    {
        BasicEduSubjectDTO edu = new BasicEduSubjectDTO();
        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 BasicEduSubject where userName = '******' AND subjectName = '" + subjectName + "'";

            SqlDataReader rdr = sqlCmd.ExecuteReader();

            if (rdr.HasRows)
            {
                while (rdr.Read())
                {

                    edu.userName = rdr["userName"].ToString();
                    edu.subjectName = rdr["subjectName"].ToString();
                    edu.subjectDescription = rdr["subjectDescription"].ToString();
                }
            }

        }
        catch
        { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return edu;
    }
    public List<BasicEduSubjectDTO> findAll()
    {
        var objs = (from p in ctx.BasicEduSubjects
                    select p);
        BasicEduSubjectDTO add = null;
        List<BasicEduSubjectDTO> addList = new List<BasicEduSubjectDTO>();
        foreach (BasicEduSubject obj in objs)
        {
            add = new BasicEduSubjectDTO();
            add.userName = obj.userName;
            add.subjectName = obj.subjectName;
            add.subjectDescription = obj.subjectDescription;

            addList.Add(add);
        }
        return addList;
    }
 public bool remove(BasicEduSubjectDTO entity)
 {
     return this.removeByUserId(entity.userName,entity.subjectName);
 }
    public bool presist(BasicEduSubjectDTO 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 = "insertBasicEduSubject";
            sqlCmd.Parameters.Add(new SqlParameter("userName", entity.userName));
            sqlCmd.Parameters.Add(new SqlParameter("subjectName", entity.subjectName));
            sqlCmd.Parameters.Add(new SqlParameter("subjectDescription", entity.subjectDescription));

            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 bool presist(BasicEduSubjectDTO entity)
    {
        try
        {
            model.BasicEduSubject obj = new BasicEduSubject();
            obj.userName = entity.userName;
            obj.subjectName = entity.subjectName;
            obj.subjectDescription = entity.subjectDescription;

            ctx.BasicEduSubjects.InsertOnSubmit(obj);
            ctx.SubmitChanges();
            return true;
        }
        catch (Exception)
        {
            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }