} //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
public void Update_progres(TaskdVM poViewModel) { try { this.oVM_detail = poViewModel; this.oData_detail = this.oDSDetail.getData(oVM_detail.ID); this.mapModel_detail_progress(); this.oCRUD_detail.Update(this.oVM_detail); this.oCRUD_detail.Commit(); this.ID = this.oVM_detail.TASK_ID; this.DETAIL_ID = this.oCRUD_detail.ID; } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Update" + e.Message; } //End catch } //End public void Update
} //End map private void mapModel_detail_edit() { //TODO: Modif "this.mapModel_detail" bagian ini untuk ambil data detail dulu jika update this.oData_detail = this.oVM_detail; this.oVM_detail = this.oData.DETAIL.Where(fld => fld.ID == this.oData_detail.ID).SingleOrDefault(); //Replace data from user input this.oVM_detail.ASSIGNEE_ID = this.oData_detail.ASSIGNEE_ID; this.oVM_detail.RES_ID = this.oData_detail.RES_ID; this.oVM_detail.PROJECT_ID = this.oData_detail.PROJECT_ID; this.oVM_detail.TASKD_PLANDESC = this.oData_detail.TASKD_PLANDESC; this.oVM_detail.TASKD_PLANSTARTDT = this.oData_detail.TASKD_PLANSTARTDT; this.oVM_detail.TASKD_PLANDURATION = this.oData_detail.TASKD_PLANDURATION; this.oVM_detail.TASKD_PLANENDDT = this.oData_detail.TASKD_PLANENDDT; } //End map
} //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 Method public TaskdVM getData(int?id, IQueryable <TaskdVM> poFieldsToselect = null) { IQueryable <TaskdVM> oQRY = null; if (poFieldsToselect != null) { oQRY = poFieldsToselect; } else { oQRY = this.fieldAll(); } this.oData = oQRY.Where(fld => fld.ID == id).SingleOrDefault(); //this.dataMutation(); return(this.oData); } //End Method
} //End public void Create public void Update(TaskdVM poViewModel) { try { this.oModel = this.db.Taskds.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 TaskdCRUD() public void Create(TaskdVM poViewModel) { try { this.oModel = new Taskd(); //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.Taskds.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 private void Validate_ID() private void Validate_isValidated(TaskdVM poViewModel) { Boolean bIsvalid = true; this.oViewModel_detail = null; this.oViewModel_detail = poViewModel; //[IS_VALIDATED] - Is Validated task if ((this.oViewModel_detail.TASKD_PROGRESSPCT != null && this.oViewModel_detail.TASKD_PROGRESSPCT == 100) && (this.oViewModel_detail.TASKD_VALIDATESTS != null && this.oViewModel_detail.TASKD_VALIDATESTS > 0)) { bIsvalid = false; ValidationMSG_VM oMSG = new ValidationMSG_VM(); oMSG.VAL_ERRID = "IS_VALIDATED1"; oMSG.VAL_ERRMSG = "Tugas " + this.oViewModel_detail.TASKD_PLANDESC + " sudah divalidasi. Tidak bisa di edit/delete."; aValidationMSG.Add(oMSG); } //End if ////[ID] - Unique //if (oDS.isExists_ID(oViewModel.ID)) //{ // bIsvalid = false; // ValidationMSG_VM oMSG = new ValidationMSG_VM(); // oMSG.VAL_ERRID = "ID2"; // oMSG.VAL_ERRMSG = "ID " + oViewModel.ID + " sudah digunakan"; // aValidationMSG.Add(oMSG); //} //End if //[ID] - If has error(s) if (!bIsvalid) { bIsvalid = false; ValidationMSG_VM oMSG = new ValidationMSG_VM(); oMSG.VAL_ERRID = "IS_VALIDATED0"; oMSG.VAL_ERRMSG = "ERROR"; aValidationMSG.Add(oMSG); } //End if } //End private void Validate_ID()
} //End public void Validate_Edit() public void Validate_Delete(TaskdVM poViewModel = null) { this.Validate_isValidated(poViewModel); //Validate_ID(); } //End public void Validate_Delete()
} //End public void Validate_Create() public void Validate_Create(TaskdVM poViewModel = null) { //Validate_ID(); } //End public void Validate_Create()
} //End Constructor 1 //Constructor 2 public Taskd_Validation(TaskdVM poViewModel, TaskdDS poDS) { this.oViewModel = poViewModel; this.oDS = poDS; aValidationMSG = new List <ValidationMSG_VM>(); } //End Constructor 2