public bool merge(SupportDocDTO entity) { try { var addObj = (from p in ctx.supportDocs where p.userName == @entity.userName && p.title == @entity.title select p).Single(); supportDoc obj = (supportDoc)addObj; /*Update*/ obj.userName = entity.userName; obj.title = entity.title; obj.description = entity.description; obj.content = new System.Data.Linq.Binary(entity.content);//Array of bytes to Linq.Binary ctx.SubmitChanges(); return true; } catch (Exception e) { Log log = new Log(); log.message = "supportDoc Merge: " + " ["+entity.userName+" , "+entity.title+"] " + e.Message; ctx.SubmitChanges(); ctx.Dispose(); ctx = new modelDataContext(); return false; } }
public void SupportDocDAOConstructorTest() { /*context*/ SupportDocDAO sup_context = new SupportDocDAO(); // TODO: Initialize to an appropriate value AccountDAO acc_context = new AccountDAO(); /*insert*/ AccountDTO acc = new AccountDTO(); acc.userName = "******"; acc.password = "******"; acc.accountType = "administrator"; acc.status = "active"; acc_context.presist(acc); SupportDocDTO supp = new SupportDocDTO(); supp.userName = "******"; byte[] bits = { 1, 0, 1, 0, 0, 1 }; supp.content = bits; supp.description = "Supporting doc"; supp.title = "help"; sup_context.presist(supp); Assert.AreEqual(supp.title, sup_context.find("john", "help").title); /*Update*/ supp.description = "NEW doc"; sup_context.merge(supp); Assert.AreEqual("NEW doc", sup_context.find("john", "help").description); /*Delete*/ sup_context.removeByUserId("john", "help"); Assert.AreEqual(sup_context.isFound("john", "help"), false); acc_context.removeByUserId("john"); }
public SupportDocDTO find(string userName, string title) { var obj = (from p in ctx.supportDocs where p.userName == @userName && p.title == @title select p).Single(); SupportDocDTO add = new SupportDocDTO(); add.userName = obj.userName; add.title = obj.title; add.description = obj.description; add.content = obj.content.ToArray(); return add; }
public SupportDocDTO find(string userName, string title) { SupportDocDTO info = new SupportDocDTO(); 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 supportDoc where userName = '******' AND title = '" + title + "'"; SqlDataReader rdr = sqlCmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { info.userName = rdr["userName"].ToString(); info.title = rdr["title"].ToString(); info.description = rdr["description"].ToString(); info.content = (byte[])rdr["content"]; } } } catch { } finally { if (sqlCmd != null) { sqlCmd = null; } if (oConn != null) { if (oConn.State.Equals(ConnectionState.Open)) { oConn.Close(); } oConn = null; } } return info; }
public List<SupportDocDTO> findAll() { var objs = (from p in ctx.supportDocs select p); SupportDocDTO add = null; List<SupportDocDTO> addList = new List<SupportDocDTO>(); foreach (supportDoc obj in objs) { add = new SupportDocDTO(); add.userName = obj.userName; add.title = obj.title; add.description = obj.description; add.content = obj.content.ToArray();//Converts Binary data to an Array of bytes addList.Add(add); } return addList; }
public bool remove(SupportDocDTO entity) { return this.removeByUserId(entity.userName,entity.title); }
public bool presist(SupportDocDTO entity) { try { supportDoc obj = new supportDoc(); obj.userName = entity.userName; obj.title = entity.title; obj.description = entity.description; obj.content = new System.Data.Linq.Binary(entity.content);//Array of bytes to Linq.Binary ctx.supportDocs.InsertOnSubmit(obj); ctx.SubmitChanges(); return true; } catch (Exception) { ctx.Dispose(); ctx = new modelDataContext(); return false; } }
public bool presist(SupportDocDTO 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 = "insertSupportDoc"; sqlCmd.Parameters.Add(new SqlParameter("title", entity.title)); sqlCmd.Parameters.Add(new SqlParameter("userName", entity.userName)); sqlCmd.Parameters.Add(new SqlParameter("description", entity.description)); sqlCmd.Parameters.Add(new SqlParameter("content", entity.content)); 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; }