public static PendidikanViewModel ById(long id) { PendidikanViewModel result = new PendidikanViewModel(); using (var db = new XSIS20Context()) { result = db.x_riwayat_pendidikan .Where(p => p.is_delete == false && p.id == id) .Select(p => new PendidikanViewModel { id = p.id, biodata_id = p.biodata_id, school_name = p.school_name, city = p.city, country = p.country, education_level_id = p.education_level_id, EducationName = p.x_education_level.name, entry_year = p.entry_year, graduation_year = p.graduation_year, major = p.major, gpa = p.gpa, notes = p.notes }).FirstOrDefault(); if (result == null) { result = new PendidikanViewModel(); } return(result); } }
public ActionResult Delete(long id) { ViewBag.EducationList = new SelectList(EducationLevelRepo.All(), "id", "name"); PendidikanViewModel model = PendidikanRepo.ById(id); return(PartialView("_Delete", model)); }
public ActionResult Edit(PendidikanViewModel model) { ResponseResult result = PendidikanRepo.Update(model); return(Json(new { success = result.Success, message = result.Message, entity = result.Entity }, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(long id) { ViewBag.Years = new SelectList(Enumerable.Range(1995, (DateTime.Today.Year - 1995) + 1).Select(x => new SelectListItem() { Text = x.ToString(), Value = x.ToString() }), "Value", "Text"); ViewBag.EducationList = new SelectList(EducationLevelRepo.All(), "id", "name"); PendidikanViewModel model = PendidikanRepo.ById(id); return(PartialView("_Edit", model)); }
public static ResponseResult Delete(long id) { ResponseResult result = new ResponseResult(); try { using (var db = new XSIS20Context()) { x_riwayat_pendidikan pend = db.x_riwayat_pendidikan.Where(p => p.is_delete == false && p.id == id).FirstOrDefault(); if (pend != null) { pend.is_delete = true; PendidikanViewModel entity = new PendidikanViewModel(); entity.id = pend.id; entity.is_delete = pend.is_delete; entity.biodata_id = pend.biodata_id; entity.school_name = pend.school_name; entity.city = pend.city; entity.country = pend.country; entity.education_level_id = pend.education_level_id; entity.EducationName = pend.x_education_level.name; entity.entry_year = pend.entry_year; entity.graduation_year = pend.graduation_year; entity.major = pend.major; entity.gpa = pend.gpa; entity.notes = pend.notes; db.SaveChanges(); pend.deleted_by = "Akbar"; pend.deleted_on = DateTime.Now; result.Entity = entity; } else { result.Success = false; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
// UPDATE public static ResponseResult Update(PendidikanViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XSIS20Context()) { // CREATE if (entity.id == 0) { x_riwayat_pendidikan pend = new x_riwayat_pendidikan(); pend.school_name = entity.school_name; pend.city = entity.city; pend.country = entity.country; pend.education_level_id = entity.education_level_id; pend.entry_year = entity.entry_year; pend.graduation_year = entity.graduation_year; pend.major = entity.major; pend.gpa = entity.gpa; pend.notes = entity.notes; pend.created_by = "Akbar"; pend.created_on = DateTime.Now; db.x_riwayat_pendidikan.Add(pend); db.SaveChanges(); result.Entity = pend; } // EDIT else { x_riwayat_pendidikan pend = db.x_riwayat_pendidikan.Where(p => p.is_delete == false && p.id == entity.id).FirstOrDefault(); if (pend != null) { pend.school_name = entity.school_name; pend.city = entity.city; pend.country = entity.country; pend.education_level_id = entity.education_level_id; pend.entry_year = entity.entry_year; pend.graduation_year = entity.graduation_year; pend.major = entity.major; pend.gpa = entity.gpa; pend.notes = entity.notes; pend.modified_by = "Akbar"; pend.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "Pendidikan Not Found"; } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }