public bool merge(KeyWordDTO entity) { try { var addObj = (from p in ctx.KeyWords where p.word == @entity.word && p.vacancyNumber == @entity.vacancyNumber select p).Single(); model.KeyWord obj = (KeyWord)addObj; /*Update*/ obj.word = entity.word; obj.vacancyNumber = entity.vacancyNumber; ctx.SubmitChanges(); return true; } catch (Exception e) { model.Log log = new Log(); log.message = "KeyWord Merge: " + " [" + entity.word + " , " + entity.vacancyNumber + "] " + e.Message; ctx.Dispose(); ctx = new ModelDataContext(); ctx.SubmitChanges(); return false; } }
public KeyWordDTO find(string word, string vacancyNumber) { var obj = (from p in ctx.KeyWords where p.word == @word && p.vacancyNumber == @vacancyNumber select p).Single(); KeyWordDTO add = new KeyWordDTO(); add.vacancyNumber = obj.vacancyNumber; add.word = obj.word; return add; }
public List<KeyWordDTO> findAll() { var objs = (from p in ctx.KeyWords select p); KeyWordDTO add = null; List<KeyWordDTO> addList = new List<KeyWordDTO>(); foreach (KeyWord obj in objs) { add = new KeyWordDTO(); add.word = obj.word; add.vacancyNumber = obj.vacancyNumber; addList.Add(add); } return addList; }
public KeyWordDTO find(string vacancyNumber, string keyWord) { KeyWordDTO info = new KeyWordDTO(); 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 KeyWord where vacancyNumber = '" + vacancyNumber + "' AND word = '" + keyWord + "'"; SqlDataReader rdr = sqlCmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { info.vacancyNumber = rdr["vacancyNumber"].ToString(); info.word = rdr["word"].ToString(); } } } catch { } finally { if (sqlCmd != null) { sqlCmd = null; } if (oConn != null) { if (oConn.State.Equals(ConnectionState.Open)) { oConn.Close(); } oConn = null; } } return info; }
public void KeyWordDAO_Test() { /*Context*/ KeyWordDAO key_context = new KeyWordDAO(); 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); KeyWordDTO key = new KeyWordDTO(); key.vacancyNumber = "1"; key.word = "Fish"; key_context.presist(key); bool expectedVac = true; bool actualVac; actualVac = key_context.isFound("Fish", "1"); Assert.AreEqual(expectedVac, actualVac); /*Update*/ //Not Applicable - Composite primary key can not be changed,except by removing the entity. /*Delete*/ Assert.AreEqual(key_context.isFound("Fish", "1"), true); key_context.removeByUserId("Fish", "1"); Assert.AreEqual(key_context.isFound("Fish", "1"), false); vac_context.removeByUserId("1"); }
public List<KeyWordDTO> findAll() { KeyWordDTO info = null; List<KeyWordDTO> infos = new List<KeyWordDTO>(); 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 KeyWord"; SqlDataReader rdr = sqlCmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { info = new KeyWordDTO(); info.vacancyNumber = rdr["vacancyNumber"].ToString(); info.word = rdr["word"].ToString(); infos.Add(info); } } } catch { } finally { if (sqlCmd != null) { sqlCmd = null; } if (oConn != null) { if (oConn.State.Equals(ConnectionState.Open)) { oConn.Close(); } oConn = null; } } return infos; }
public bool remove(KeyWordDTO entity) { return this.removeByUserId(entity.vacancyNumber, entity.word); }
public bool presist(KeyWordDTO 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 = "insertKeyWord"; sqlCmd.Parameters.Add(new SqlParameter("vacancyNumber", entity.vacancyNumber)); sqlCmd.Parameters.Add(new SqlParameter("word", entity.word)); 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 ChangeKeyWord(KeyWordDTO keyWordDTO) { _personRepository.ChangeKeyWord(_mapper.Map <KeyWordDTO, KeyWord>(keyWordDTO)); }
public void AddKeyWord(KeyWordDTO keyWordDTO) { _personRepository.AddKeyWord(_mapper.Map <KeyWordDTO, KeyWord>(keyWordDTO)); }
public bool presist(KeyWordDTO entity) { try { model.KeyWord obj = new KeyWord(); obj.word = entity.word; obj.vacancyNumber = entity.vacancyNumber; ctx.KeyWords.InsertOnSubmit(obj); ctx.SubmitChanges(); return true; } catch (Exception) { ctx.Dispose(); ctx = new ModelDataContext(); return false; } }
public void setKeyWordDto(KeyWordDTO keyWordDto) { view.setKeyWord(keyWordDto.word); }
public KeyWordDTO getKeyWordDto() { KeyWordDTO keyWordDto = new KeyWordDTO(); keyWordDto.vacancyNumber = view.getVacancyNumber(); keyWordDto.word = view.getKeyWord(); return keyWordDto; }