} //End public void setCPAR_TYPE(string psCPAR_TYPE) public void Create(CPAR_DetailVM poViewModel) { string vsMsgErr = ""; try { using (var db = new DBMAINContext()) { CPAR oModel = new CPAR(); //Map Form Data Mapper.CreateMap <CPAR_DetailVM, CPAR>(); oModel = Mapper.Map <CPAR_DetailVM, CPAR>(poViewModel); //Set Field Header oModel.setFIELD_HEADER(hlpFlags_CRUDOption.CREATE); //Set DTA_STS oModel.DTA_STS = valFLAG.FLAG_CRUDOPT_CREATE; //Set CPAR_STS oModel.CPAR_STS = valFLAG.FLAG_CPAR_STS_OPEN; //Set CPAR_TYPE oModel.CPAR_TYPE = this.CPAR_TYPE; //Get Config_cparid //oModel.oVMConfig_cparid = oDSConfig_cparid.getData(); //Set FIELD oModel.setFIELD(); //Set DEPT_RUID Auditor and Auditee if (oModel.AUDITOR_RUID != null) { oModel.AUDITORDEPT_RUID = oDSEmployee.getData_deptruid(oModel.AUDITOR_RUID); } //End if (AUDITOR_RUID != null) if (oModel.AUDITEE_RUID != null) { oModel.AUDITEEDEPT_RUID = oDSEmployee.getData_deptruid(oModel.AUDITEE_RUID); } //End if (AUDITEE_RUID != null) //Set Config CPAR_ID if (oModel.isNEW_CONFIG) { oCRUDConfig_cparid.Create_prepare(oModel.oVMConfig_cparid); db.Config_cparids.Add(oCRUDConfig_cparid.oModel); } //End if (oModel.isNEW_CONFIG) if (!oModel.isNEW_CONFIG) { oCRUDConfig_cparid.Update_prepare(oModel.oVMConfig_cparid); db.Entry(oCRUDConfig_cparid.oModel).State = EntityState.Modified; } //End if (!oModel.isNEW_CONFIG) //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.CPARs.Add(oModel); //Set CPAR_stdref oCRUD_Stdref = new CPARStdrefCRUD(); if (poViewModel.STDREF_LIST != null) { foreach (var item in poViewModel.STDREF_LIST) { 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 Create
} //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