} //End public void Update public void Delete(string id) { string vsMsgErr = ""; try { using (var db = new DBMAINContext()) { CPAR oModel = db.CPARs.Find(id); db.CPARs.Remove(oModel); //Set CPAR_stdref Delete by CPAR RUID oDSCPARStdref = new CPARStdrefDS(); var oQRY = oDSCPARStdref.getDatalist_byCPAR_RUID(id); foreach (var item in oQRY) { CPARStdref oItem = db.CPARStdrefs.Find(item.RUID); db.CPARStdrefs.Remove(oItem); } //End foreach (var item in oQRY) //Process CRUD db.SaveChanges(); } //End using } //End try catch (Exception e) { vsMsgErr = e.Message; } //End catch } //End public void Delete
} //End public CPARDS public void Init(CPARStdrefDS poDSStdref, SubtypeDS poDSLOVSubtype, ClassauditDS poDSLOVClass) { oDSStdref = poDSStdref; oDSLOVSubtype = poDSLOVSubtype; oDSLOVClass = poDSLOVClass; this.sROLE_RUID = hlpConfig.SessionInfo.getAppRoleRUID(); this.sRES_RUID = hlpConfig.SessionInfo.getAppUsrRES_RUID(); this.sDEPT_RUID = hlpConfig.SessionInfo.getAppUsrDEPT_RUID(); } //End public CPARDS(CPARSubtypeDS poDSLOVSubtype, CPARClassDS poDSLOVClass)
} //End public void Create public void Update(CPAR_DetailVM poViewModel) { string vsMsgErr = ""; try { using (var db = new DBMAINContext()) { CPAR oModel = db.CPARs.AsNoTracking().SingleOrDefault(fld => fld.RUID == poViewModel.RUID); poViewModel.CPAR_STS = oModel.CPAR_STS; poViewModel.CPAR_TYPE = oModel.CPAR_TYPE; poViewModel.AUDITORDEPT_RUID = oModel.AUDITORDEPT_RUID; poViewModel.AUDITEEDEPT_RUID = oModel.AUDITEEDEPT_RUID; //Reflect data VM if (oModel.CPAR_TYPE == valFLAG.FLAG_CPAR_TYPE_CC) { poViewModel.AUDITEE_RUID = oModel.AUDITEE_RUID; poViewModel.AUDITEEDEPT_RUID = oModel.AUDITEEDEPT_RUID; poViewModel.CPAR_DT = oModel.CPAR_DT; poViewModel.CPAR_TRGT_DT = oModel.CPAR_TRGT_DT; //poViewModel.CPAR_DESC = oModel.CPAR_DESC; poViewModel.CPAR_RESOLUTION2 = oModel.CPAR_RESOLUTION2; poViewModel.COMPLAIN_RUID = oModel.COMPLAIN_RUID; } //End if (this.CPAR_TYPE == valFLAG.FLAG_CPAR_TYPE_CC) //Map Form Data Mapper.CreateMap <CPAR_DetailVM, CPAR>(); oModel = Mapper.Map <CPAR_DetailVM, CPAR>(poViewModel); //Set Field Header oModel.setFIELD_HEADER(hlpFlags_CRUDOption.UPDATE); //Set DTA_STS oModel.DTA_STS = valFLAG.FLAG_CRUDOPT_UPDATE; //Set FIELD oModel.setFIELD(); //Set CPAR_FINISG_DT base on CPAR_DT //oModel.setFIELD_finishdate(poViewModel); oModel.setFIELD_finishdate(); //Set CPAR_RSPNLMT_DT base on CPAR_DT //oModel.setFIELD_responsedate(poViewModel); oModel.setFIELD_responsedate(); //Set CPAR_VERLMT_DT base on CPAR_DT //oModel.setFIELD_verifydate(poViewModel); oModel.setFIELD_verifydate(); //Process CRUD db.Entry(oModel).State = EntityState.Modified; //Set CPAR_stdref Delete by CPAR RUID oCRUD_Stdref = new CPARStdrefCRUD(); oDSCPARStdref = new CPARStdrefDS(); var oQRY = oDSCPARStdref.getDatalist_byCPAR_RUID(oModel.RUID); foreach (var item in oQRY) { CPARStdref oItem = db.CPARStdrefs.Find(item.RUID); db.CPARStdrefs.Remove(oItem); } //End foreach (var item in oQRY) //Set CPAR_stdref Add by STDREF_LIST if (poViewModel.STDREF_LIST != null) { foreach (var item in poViewModel.STDREF_LIST) { //LASTWORK CPARStdref_DetailVM oItem = new CPARStdref_DetailVM(); //Map Form Data Mapper.CreateMap <CPARStdref_ListVM, CPARStdref_DetailVM>(); oItem = Mapper.Map <CPARStdref_ListVM, CPARStdref_DetailVM>(item); oItem.CPAR_RUID = oModel.RUID; oCRUD_Stdref.Create_prepare(oItem); db.CPARStdrefs.Add(oCRUD_Stdref.oModel); } //End foreach (var item in poViewModel.STDREF_LIST) } //End if (poViewModel.STDREF_LIST != null) //Process CRUD db.SaveChanges(); this.RUID = oModel.RUID; } //End using } //End try catch (Exception e) { vsMsgErr = e.Message; } //End catch } //End public void Update