public static ResponResultViewModel Update2(BiodataViewModel entity) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_biodata bio = db.t_biodata.Where(o => o.id == entity.id).FirstOrDefault(); if (bio != null) { bio.active = false; db.SaveChanges(); result.Entity = entity; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel Update(BiodataViewModel entity) { //Untuk create dan edit ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { //Create if (entity.id == 0) { t_biodata bi = new t_biodata(); bi.name = entity.name; bi.last_education = entity.last_education; bi.educational_level = entity.educational_level; bi.graduation_year = entity.graduation_year; bi.majors = entity.majors; bi.gpa = entity.gpa; bi.active = entity.active; bi.created_by = 1; bi.created_on = DateTime.Now; db.t_biodata.Add(bi); db.SaveChanges(); result.Entity = bi; } //Edit else { t_biodata bi = db.t_biodata.Where(o => o.id == entity.id).FirstOrDefault(); if (bi != null) { bi.name = entity.name; bi.last_education = entity.last_education; bi.educational_level = entity.educational_level; bi.graduation_year = entity.graduation_year; bi.majors = entity.majors; bi.gpa = entity.gpa; bi.active = entity.active; bi.modified_by = 2; bi.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "Biodata not Found!"; } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponseResult Update(BiodataViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { //CREATE if (entity.id == 0) { t_biodata bio = new t_biodata(); bio.name = entity.name; //sesuai yg kita input di web bio.last_education = entity.last_education; bio.educational_level = entity.educational_level; bio.graduation_year = entity.graduation_year; bio.majors = entity.majors; bio.gpa = entity.gpa; bio.is_deleted = entity.is_deleted; bio.created_by = entity.UserId; bio.created_on = DateTime.Now; db.t_biodata.Add(bio); db.SaveChanges(); object data = new { bio.id, bio.name, bio.gender, bio.last_education, bio.graduation_year, bio.educational_level, bio.majors, bio.gpa, bio.bootcamp_test_type, bio.iq, bio.du, bio.arithmetic, bio.nested_logic, bio.join_table, bio.tro, bio.notes, bio.interviewer }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Insert"; log.json_insert = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); entity.id = bio.id; result.Entity = entity; } else //EDIT { t_biodata bio = db.t_biodata .Where(o => o.id == entity.id && o.is_deleted == false) .FirstOrDefault(); if (bio != null) { object data = new { bio.id, bio.name, bio.gender, bio.last_education, bio.graduation_year, bio.educational_level, bio.majors, bio.gpa, bio.bootcamp_test_type, bio.iq, bio.du, bio.arithmetic, bio.nested_logic, bio.join_table, bio.tro, bio.notes, bio.interviewer }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Modify"; log.json_before = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; bio.name = entity.name; bio.gender = entity.gender; bio.last_education = entity.last_education; bio.graduation_year = entity.graduation_year; bio.educational_level = entity.educational_level; bio.majors = entity.majors; bio.gpa = entity.gpa; bio.bootcamp_test_type = entity.bootcamp_test_type; bio.iq = entity.iq; bio.du = entity.du; bio.arithmetic = entity.arithmetic; bio.nested_logic = entity.nested_logic; bio.join_table = entity.join_table; bio.tro = entity.tro; bio.notes = entity.notes; bio.interviewer = entity.interviewer; bio.modified_by = entity.UserId; bio.modified_on = DateTime.Now; object data2 = new { bio.id, bio.name, bio.gender, bio.last_education, bio.graduation_year, bio.educational_level, bio.majors, bio.gpa, bio.bootcamp_test_type, bio.iq, bio.du, bio.arithmetic, bio.nested_logic, bio.join_table, bio.tro, bio.notes, bio.interviewer }; var json2 = new JavaScriptSerializer().Serialize(data2); log.json_after = json2; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Biodata not found!"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
//DELETE public static ResponseResult Delete(BiodataViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_biodata bio = db.t_biodata .Where(o => o.id == entity.id) .FirstOrDefault(); if (bio != null) { object data = new { bio.id, bio.name, bio.gender, bio.last_education, bio.graduation_year, bio.educational_level, bio.majors, bio.gpa, bio.bootcamp_test_type, bio.iq, bio.du, bio.arithmetic, bio.nested_logic, bio.join_table, bio.tro, bio.notes, bio.interviewer, bio.is_deleted }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Modify"; log.json_before = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; bio.is_deleted = true; bio.deleted_by = entity.UserId; bio.deleted_on = DateTime.Now; object data2 = new { bio.id, bio.name, bio.gender, bio.last_education, bio.graduation_year, bio.educational_level, bio.majors, bio.gpa, bio.bootcamp_test_type, bio.iq, bio.du, bio.arithmetic, bio.nested_logic, bio.join_table, bio.tro, bio.notes, bio.interviewer, bio.is_deleted }; var json2 = new JavaScriptSerializer().Serialize(data2); log.json_after = json2; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Biodata not found!"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }