//Delete public static ResponseResult Delete(TestViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_test ts = db.t_test.Where(o => o.id == entity.id).FirstOrDefault(); if (ts != null) { var Serial = new JavaScriptSerializer(); object dataBefore = new //Mengambil Data Before for Log { ts.name, ts.is_bootcamp_test, ts.notes, ts.is_delete }; ts.deleted_by = entity.UserId; ts.deleted_on = DateTime.Now; ts.is_delete = true; db.SaveChanges(); // Audit Log Modify object dataAfter = new { ts.name, ts.is_bootcamp_test, ts.notes, ts.is_delete }; t_audit_log log = new t_audit_log(); log.type = "MODIFY"; log.json_before = Serial.Serialize(dataBefore); log.json_after = Serial.Serialize(dataAfter); log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Test Not Found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponResultViewModel Deact(TestViewModel model) { ResponResultViewModel result = new ResponResultViewModel(); using (var db = new MinProContext()) { t_test test = db.t_test.Where(x => x.id == model.id).FirstOrDefault(); test.active = false; test.modified_by = 1; test.modified_on = DateTime.Now; test.name = model.name; try { db.SaveChanges(); result.Entity = model; } catch (Exception e) { result.Success = false; result.Message = e.Message; } } return(result); }
public static ResponResultViewModel Update(TestViewModel entity) { //untuk create & edit ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_test test = new t_test(); test.name = entity.name; test.notes = entity.notes; test.active = entity.active; test.created_by = 1; test.created_on = DateTime.Now; db.t_test.Add(test); db.SaveChanges(); result.Entity = test; } else { t_test test = db.t_test.Where(x => x.id == entity.id).FirstOrDefault(); if (test != null) { test.name = entity.name; test.notes = entity.notes; test.active = entity.active; test.modified_by = 1; test.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }