} //End public int? getData_currentYearID() public YeardetailVM getData(DateTime?pdDatetime) { YeardetailVM vReturn = null; DateTime? dDate = null; if (pdDatetime != null) { dDate = pdDatetime.Value.Date; using (var db = new DBMAINContext()) { var oQRY = from tb in db.Years //where tb.DTA_STS != 3 select new YeardetailVM { ID = tb.ID, //DTA_STS = tb.DTA_STS, //YEAR_CODE = tb.YEAR_CODE, //YEAR_SHORTDESC = tb.YEAR_SHORTDESC, YEAR_DESC = tb.YEAR_DESC, YEAR_FROM = tb.YEAR_FROM, YEAR_TO = tb.YEAR_TO }; vReturn = oQRY.Where(fld => dDate >= fld.YEAR_FROM && dDate <= fld.YEAR_TO).SingleOrDefault(); } //End using (var = new DbContext()) } //End if (pdDatetime != null) return(vReturn); } //End public int? getData_YearID(DateTime? pdDatetime = null)
} //End public void InjectFromStudentVM(StudentdetailVM poViewModel) public void InjectFromYearVM(YeardetailVM poViewModel) { this.YEAR_ID = poViewModel.ID; this.YEAR_CODE = poViewModel.YEAR_CODE; this.YEAR_SHORTDESC = poViewModel.YEAR_SHORTDESC; this.YEAR_DESC = poViewModel.YEAR_DESC; this.YEAR_FROM = poViewModel.YEAR_FROM; this.YEAR_TO = poViewModel.YEAR_TO; } //End public void InjectFromYearVM(YeardetailVM poViewModel)
} //End public void Delete public void Create() { SysinfodetailVM oViewModel = new SysinfoDS().getData(); try { using (var db = new DBMAINContext()) { int nYEAR = oViewModel.SYSDATE.Value.Year; int nMONTH = oViewModel.SYSDATE.Value.Month; int nYEAR_FROM = 0; int nYEAR_TO = 0; //1 Juli - 31 Desember (Semester 1) if ((nMONTH >= 7) && (nMONTH <= 12)) { nYEAR_FROM = nYEAR; nYEAR_TO = nYEAR + 1; } //End if ((nMONTH >= 7) && (nMONTH <= 12)) //1 Januari - 30 Juni (Semester 2) if ((nMONTH >= 1) && (nMONTH <= 6)) { nYEAR_FROM = nYEAR - 1; nYEAR_TO = nYEAR; } //End if ((nMONTH >= 1) && (nMONTH <= 6)) string sYEAR_CODE = nYEAR_FROM.ToString() + " - " + nYEAR_TO.ToString(); DateTime?oDatefrom = hlpConvertionAndFormating.ConvertStringToDateShort("01/07/" + nYEAR_FROM.ToString()); DateTime?oDateto = hlpConvertionAndFormating.ConvertStringToDateShort("30/06/" + nYEAR_TO.ToString()); /*----------------------------------------------------------------------*/ YearDS oDS = new YearDS(); YeardetailVM oData = oDS.getData_byPeriod(oDatefrom, oDateto); if (oData == null) { Year oModel = new Year(); //Set Field Header oModel.setFIELD_HEADER(hlpFlags_CRUDOption.CREATE); //Set DTA_STS oModel.DTA_STS = valFLAG.FLAG_DTA_STS_CREATE; oModel.YEAR_CODE = sYEAR_CODE; oModel.YEAR_SHORTDESC = sYEAR_CODE; oModel.YEAR_DESC = sYEAR_CODE; oModel.YEAR_FROM = oDatefrom; oModel.YEAR_TO = oDateto; //Process CRUD db.Years.Add(oModel); db.SaveChanges(); this.ID = oModel.ID; } //End if (oData != null) } //End using } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Create: " + e.Message; } //End catch } //End public void Create
} //End public void Create public void Update(YeardetailVM poViewModel) { try { using (var db = new DBMAINContext()) { Year oModel = db.Years.AsNoTracking().SingleOrDefault(fld => fld.ID == poViewModel.ID); //Map Form Data oModel.InjectFrom(poViewModel); //Set Field Header oModel.setFIELD_HEADER(hlpFlags_CRUDOption.UPDATE); //Process CRUD db.Entry(oModel).State = EntityState.Modified; db.SaveChanges(); this.ID = oModel.ID; } //End using } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Update" + e.Message; } //End catch } //End public void Update
} //End public YearCRUD() public void Create(YeardetailVM poViewModel) { try { using (var db = new DBMAINContext()) { Year oModel = new Year(); //Map Form Data oModel.InjectFrom(poViewModel); //Set Field Header oModel.setFIELD_HEADER(hlpFlags_CRUDOption.CREATE); //Process CRUD db.Years.Add(oModel); db.SaveChanges(); this.ID = oModel.ID; } //End using } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Create: " + e.Message; } //End catch } //End public void Create
//Constructor public Year_Validation(YeardetailVM poViewModel) { oViewModel = poViewModel; } //End public Year_Validation()