|
select case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
static internal ProtoTestRES doHello(ProtoTestASK r_ask) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var listMember = from itemMember in dataContext.tb_Member where itemMember.fd_Member_nID == 1 select itemMember; foreach(var itemMember in listMember) { res.m_Member_nID = itemMember.fd_Member_nID; res.m_Member_strEmail = itemMember.fd_Member_strEmail; } return res; } catch (Exception ex) { throw new Exception(ex.Message); } } |
insert case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
static internal ProtoTestRES doHello_Insert(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = new tb_Member { fd_Member_strEmail = r_ask.m_Member_strEmail, fd_Member_strPW = r_ask.m_Member_strPW }; dataContext.tb_Member.InsertOnSubmit(itemMember); dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
update case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
static internal ProtoTestRES doHello_Update(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = dataContext.tb_Member.SingleOrDefault(r_p => r_p.fd_Member_nID == 1); if (itemMember != null) itemMember.fd_Member_nID = 3; dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
delete single case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
static internal ProtoTestRES doHello_Delete_Single(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = dataContext.tb_Member.SingleOrDefault(r_p => r_p.fd_Member_nID == 1); if (itemMember != null) dataContext.tb_Member.DeleteOnSubmit(itemMember); dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
delete multi case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
static internal ProtoTestRES doHello_Delete_Multi(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = dataContext.tb_Member.Where(r_p => r_p.fd_Member_nID > 1); dataContext.tb_Member.DeleteAllOnSubmit(itemMember); dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
static internal ProtoBufRES doInsert(ProtoBufASK r_ask) { try { var res = new ProtoBufRES(); Mapper.Instance().BeginTransaction(); res.nRet = Mapper.Instance().QueryForObject < int > ("QueryInsert", r_ask); // Insert시에 SELECT SCOPE_IDENTITY()로 키값을 가져오는 방향으로 Mapper.Instance().CommitTransaction(); if (0 >= nRet) { res.m_eResult = ENUM_RESULT.ENUM_NOINSERT; res.m_strMessage = "처리되지 않았습니다."; return res; } else { res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { Mapper.Instance().RollBackTransaction(); throw new Exception(ex.Message); } } |
Test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
static private readonly ILog s_thelog = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); #if DEBUG static public ServiceReference_Solution.ServiceTaxiClient proxy = new ServiceReference_Solution.ServiceTaxiClient(); #else static public ServiceReference_Staging.ServiceTaxiClient proxy = new ServiceReference_Staging.ServiceTaxiClient(); #endif private ProtoBufRES _function(ProtoBufASK r_ask) { s_thelog.Info("> " + GetType().FullName + "." + MethodBase.GetCurrentMethod().Name); var btask = ProtoBuffHelper.Serialize(r_ask); var btres = proxy.function(btask); var res = ProtoBuffHelper.Deserialize < ProtoBufRES > (btres); s_thelog.Debug(string.Format(" {0, -25} : {1}", "m_eResult", res.m_eResult)); if (ENUM_RESULT.ENUM_EXCEPTION == res.m_eResult) { s_thelog.Error(res.m_strMessage); } return res; } [TestMethod] public void function () { var ask = new ProtoBufASK { m_nMemberID = 1, m_nMemberFriendID = 2 }; var res = _function(ask); Assert.AreNotEqual(ENUM_RESULT.ENUM_EXCEPTION, res.m_eResult); } |
Services
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
static public byte[] function (byte[] r_bAsk) { try { var ask = ProtoBuffHelper.Deserialize < ProtoBufASK > (r_bAsk); var res = daoCommunity.doReceiveDeny(ask); return ProtoBuffHelper.Serialize(res); } catch (Exception ex) { var exres = new ProtoBufRES { m_eResult = ENUM_RESULT.ENUM_EXCEPTION, m_strMessage = string.Format("tException function : {0}nt{1}n", Convert.ToBase64String(r_bAsk), ex.Message) }; CCommon.s_thelog(exres.m_strMessage); return ProtoBuffHelper.Serialize(exres); } } |
DAO – insert
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
static internal ProtoBufRES doInsert(ProtoBufASK r_ask) { try { var res = new ProtoBufRES(); Mapper.Instance().BeginTransaction(); res.nRet = Mapper.Instance().QueryForObject < int > ("QueryInsert", r_ask); // Insert시에 SELECT SCOPE_IDENTITY()로 키값을 가져오는 방향으로 Mapper.Instance().CommitTransaction(); if (0 >= nRet) { res.m_eResult = ENUM_RESULT.ENUM_NOINSERT; res.m_strMessage = "처리되지 않았습니다."; return res; } else { res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { Mapper.Instance().RollBackTransaction(); throw new Exception(ex.Message); } } |
DAO – update delete
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
static internal ProtoBufRES doUpdate(ProtoBufASK r_ask) { try { var res = new ProtoBufRES(); Mapper.Instance().BeginTransaction(); res.nRet = Mapper.Instance().Delete("QueryDelete", r_ask); Mapper.Instance().CommitTransaction(); if (0 >= nRet) { res.m_eResult = ENUM_RESULT.ENUM_NOUPDATE; res.m_strMessage = "데이터가 처리되지 않았습니다."; return res; } else { res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { Mapper.Instance().RollBackTransaction(); throw new Exception(ex.Message); } } |
DAO – select
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
static internal ProtoBufRES doSelect(ProtoBufASK r_ask) { try { var res = Mapper.Instance().QueryForObject < ProtoBufRES > ("QuerySelect", r_ask); if (0 >= res.nRet) { res.m_eResult = ENUM_RESULT.ENUM_NORESULT; res.m_strMessage = "res에 데이터가 없습니다."; return res; } var listMine = Mapper.Instance().QueryForList < ProtoBuf > ("QuerySelect", r_ask); if (0 >= listMine.Count) { res.m_eResult = ENUM_RESULT.ENUM_NORESULT; res.m_strMessage = "list 내에 데이터가 없습니다."; return res; } else { foreach(var itemMine in listMine) { res.m_listMine.Add(itemMine); } res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { throw new Exception(ex.Message); } } |
|
링크
|