} //End Method public TaskVM getData(int?id, IQueryable <TaskVM> poFieldsToselect = null) { TaskVM oQRY = null; this.oData = this.oDS.getDataFirst_byRES_ID(id); if (this.oData != null) { this.oData.DETAIL = this.oDSDetail.getDatalist_byRES_ID(id); if ((hlpConfig.SessionInfo.getAppRoleId() == valROLE.ROLEID_LEADER) && (hlpConfig.SessionInfo.getAppResId() != id)) { this.oData.DETAIL = this.oData.DETAIL.Where(fld => fld.ASSIGNEE_ID == hlpConfig.SessionInfo.getAppResId()).ToList(); } //end if if (this.oData.DETAIL == null) { this.oData = null; } else if (this.oData.DETAIL.Count == 0) { this.oData = null; } } //end if oQRY = this.oData; return(oQRY); } //End Method
} //End Constructor 2 //Constructor 3 public Task_Validation(TaskVM poViewModel, TaskDS poDS, TaskdDS poDSDetail) { this.oViewModel = poViewModel; this.oViewModel.DETAIL = poViewModel.DETAIL; this.oDS = poDS; this.oDSDetail = poDSDetail; aValidationMSG = new List <ValidationMSG_VM>(); } //End Constructor 2
} //End public Task_workerCRUD() public void Create(TaskVM poViewModel) { try { //Init this.oVM = poViewModel; this.oData_employee = this.oDSEmployee.getData(this.oVM.RES_ID); //Date if (oVM.TASK_DT == null) { oVM.TASK_DT = DateTime.Now.Date; } //Month this.oData_month = this.oDSMonth.getData_byMonthNum(oVM.MONTH_ID); if (this.oData_month == null) { this.oData_month = this.oDSMonth.getData_byMonthNum(oVM.TASK_DT.Value.Month); } if (this.oData_month == null) { this.oData_month = this.oDSMonth.getData_byMonthNum(DateTime.Now.Month); } //Year this.oData_year = this.oDSYear.getData(this.oVM.YEAR_ID); if (this.oData_year == null) { this.oData_year = this.oDSYear.getData_byYearNum(oVM.TASK_DT.Value.Year); } if (this.oData_year == null) { this.oData_year = this.oDSYear.getData_byYearNum(DateTime.Now.Year); } //Header this.mapModel(); this.oCRUD.Create(this.oVM); this.oCRUD.Commit(); this.ID = this.oCRUD.ID; //Detail if (!this.oCRUD.isERR) { foreach (var item in oVM.DETAIL) { this.oVM_detail = item; this.mapModel_detail(); this.oCRUD_detail.Create(oVM_detail); } //End foreach this.oCRUD_detail.Commit(); this.DETAIL_ID = this.oCRUD_detail.ID; } //End if } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Create: " + e.Message; } //End catch } //End public void Create
//Instantiate private void Instantiate() { //CRUD this.oCRUD = new TaskCRUD(this.db); this.oCRUD_detail = new TaskdCRUD(this.db); //DS this.oDSDetail = new TaskdDS(this.db); this.oDSSysinfo = new SysinfoDS(this.db); this.oDSEmployee = new EmployeeDS(this.db); this.oDSMonth = new MonthDS(this.db); this.oDSYear = new YearDS(this.db); //DATA this.oData = new TaskVM(); } //End private void Instantiate()
} //End public void Create public void Update(TaskVM poViewModel) { try { //Init this.oVM = poViewModel; this.oData.DETAIL = this.oDSDetail.getDatalist_byForeignId(oVM.ID); this.fillModel(); //Header //this.mapModel(); this.oCRUD.Update(this.oVM); this.oCRUD.Commit(); this.ID = this.oCRUD.ID; //Detail if (!this.oCRUD.isERR) { foreach (var item in oVM.DETAIL) { this.oVM_detail = item; this.mapModel_detail_edit(); if (this.oVM_detail.ID == null) { this.oCRUD_detail.Create(this.oVM_detail); } if (this.oVM_detail.ID != null) { if (this.oVM_detail.DTA_STS == null) { this.oCRUD_detail.Create(this.oVM_detail); } if (this.oVM_detail.DTA_STS == valFLAG.FLAG_DTA_STS_CREATE) { this.oCRUD_detail.Update(this.oVM_detail); } if (this.oVM_detail.DTA_STS == valFLAG.FLAG_DTA_STS_UPDATE) { this.oCRUD_detail.Update(this.oVM_detail); } if (this.oVM_detail.DTA_STS == valFLAG.FLAG_DTA_STS_DELETE) { this.oCRUD_detail.Delete(this.oVM_detail.ID); } } //end if } //End foreach this.oCRUD_detail.Commit(); } //End if } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Update" + e.Message; } //End catch } //End public void Update
} //End public void Create public void Update(TaskVM poViewModel) { try { this.oModel = this.db.Tasks.AsNoTracking().SingleOrDefault(fld => fld.ID == poViewModel.ID); //Map Form Data this.oModel.InjectFrom(poViewModel); //Set Field Header this.oModel.setFIELD_HEADER(hlpFlags_CRUDOption.UPDATE); //Set DTA_STS this.oModel.DTA_STS = valFLAG.FLAG_DTA_STS_UPDATE; //Process CRUD this.db.Entry(this.oModel).State = EntityState.Modified; //this.db.SaveChanges(); //this.ID = this.oModel.ID; } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Update" + e.Message; } //End catch } //End public void Update
} //End public TaskCRUD() public void Create(TaskVM poViewModel) { try { this.oModel = new Task(); //Map Form Data this.oModel.InjectFrom(poViewModel); //Set Field Header this.oModel.setFIELD_HEADER(hlpFlags_CRUDOption.CREATE); //Set DTA_STS this.oModel.DTA_STS = valFLAG.FLAG_DTA_STS_CREATE; //Process CRUD this.db.Tasks.Add(this.oModel); //this.db.SaveChanges(); //this.ID = this.oModel.ID; } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Create: " + e.Message; } //End catch } //End public void Create
} //End Constructor 1 //Constructor 2 public Task_Validation(TaskVM poViewModel, TaskDS poDS) { this.oViewModel = poViewModel; this.oDS = poDS; aValidationMSG = new List <ValidationMSG_VM>(); } //End Constructor 2