public static ResponseResult ResetPassword(UserViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_user user = db.t_user.Where(o => o.id == entity.id).FirstOrDefault(); if (user != null) { var Serial = new JavaScriptSerializer(); object data = new { user.password }; var json = Serial.Serialize(data); user.password = entity.password; user.modified_by = entity.UserId; user.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; db.SaveChanges(); object data2 = new { user.password }; t_audit_log log = new t_audit_log(); log.type = "MODIFY"; log.json_before = json; json = Serial.Serialize(data2); log.json_after = json; 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 = "Category not found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Create(MenuAccessViewModel entity) { ResponseResult result = new ResponseResult(); using (var db = new XBC_Context()) { t_menu_access ma = new t_menu_access(); ma.role_id = entity.role_id; ma.menu_id = entity.menu_id; ma.created_by = entity.UserId; ma.created_on = DateTime.Now; db.t_menu_access.Add(ma); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(ma); 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 = ma.id; result.Entity = entity; } return(result); }
//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 ResponseResult Delete(UserViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_user user = db.t_user.Where(o => o.id == entity.id).FirstOrDefault(); if (user != null) { var Serial = new JavaScriptSerializer(); object data = new { user.username, user.email, user.role_id, user.mobile_flag, user.mobile_token }; var json = Serial.Serialize(data); user.is_delete = true; user.deleted_by = entity.UserId; user.deleted_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; db.SaveChanges(); t_audit_log log = new t_audit_log(); log.type = "MODIFY"; log.json_delete = json; 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 = "Category not found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(MenuViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_menu menu = db.t_menu.Where(o => o.id == entity.id).FirstOrDefault(); if (menu != null) { var Serial = new JavaScriptSerializer(); object data = new { menu.id, menu.image_url, menu.title, menu.code }; var json = Serial.Serialize(data); menu.is_delete = true; menu.deleted_by = entity.UserId; menu.deleted_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; db.SaveChanges(); t_audit_log log = new t_audit_log(); log.type = "MODIFY"; log.json_delete = json; 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 = "Category not found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
// Update (Create) public static ResponseResult Update(QuestionViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { if (entity.id == 0) // Create { t_question qs = new t_question(); qs.question_type = entity.questionType; qs.question = entity.question; qs.image_url = entity.imageUrl; qs.created_by = entity.UserId; qs.created_on = DateTime.Now; qs.is_deleted = false; db.t_question.Add(qs); db.SaveChanges(); // Audit Log Insert var json = new JavaScriptSerializer().Serialize(qs); 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(); object data = new { qs.id, qs.question, qs.question_type, qs.image_url }; entity.id = qs.id; result.Entity = data; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(RoomViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_room room = db.t_room.Where(o => o.id == entity.id).FirstOrDefault(); if (room != null) { room.is_delete = true; room.deleted_by = entity.UserId; room.created_on = DateTime.Now; db.SaveChanges(); object data = new { room.id, room.name, room.code }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Modified"; log.json_insert = json; 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 = "Room Not Fount"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
//Setup Test Cancel public static ResponseResult Cancel(BatchTestViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_batch_test bt = db.t_batch_test.Where(o => o.batch_id == entity.batch_id && o.test_id == entity.test_id).FirstOrDefault(); if (bt != null) { db.t_batch_test.Remove(bt); db.SaveChanges(); result.Entity = entity; // Audit Log Delete var Serial = new JavaScriptSerializer(); object data = new //Mengambil Data Json { bt.batch_id, bt.test_id }; //var json = new JavaScriptSerializer().Serialize(bt); t_audit_log log = new t_audit_log(); log.type = "DELETE"; log.json_delete = Serial.Serialize(data);; 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 ResponseResult Delete(IdleNewsViewModel entity) { ResponseResult result = new ResponseResult(); using (var db = new XBC_Context()) { t_idle_news idn = db.t_idle_news.Where(o => o.id == entity.id).FirstOrDefault(); if (idn != null) { var Serial = new JavaScriptSerializer(); object data = new { idn.category_id, idn.title, idn.content, idn.is_publish }; var json = Serial.Serialize(data); idn.is_delete = true; idn.deleted_by = entity.UserId; idn.deleted_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; db.SaveChanges(); t_audit_log log = new t_audit_log(); log.type = "Delete"; log.json_delete = json; 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 = "Idle News not found!"; } } return(result); }
// Add Participant public static ResponseResult Add(ClazzViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { if (entity.id == 0) // Create { t_clazz cl = new t_clazz(); cl.batch_id = entity.batchId; cl.biodata_id = entity.biodataId; cl.created_by = entity.UserId; cl.created_on = DateTime.Now; db.t_clazz.Add(cl); db.SaveChanges(); // Audit Log Insert var json = new JavaScriptSerializer().Serialize(cl); 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 = cl.id; result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Gagal Menambahkan Participant"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
// Setup Test Choose public static ResponseResult Choose(BatchTestViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { if (entity.id == 0) // Choose { t_batch_test bt = new t_batch_test(); bt.batch_id = entity.batch_id; bt.test_id = entity.test_id; bt.created_by = entity.UserId; bt.created_on = DateTime.Now; db.t_batch_test.Add(bt); db.SaveChanges(); // Audit Log Insert var json = new JavaScriptSerializer().Serialize(bt); 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 = bt.id; result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Gagal Mensetup Test"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(TestimonyViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_testimony tes = db.t_testimony .Where(t => t.id == entity.id) .FirstOrDefault(); if (tes != null) { object data = new { tes.id, tes.title, tes.content, tes.is_delete }; 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; tes.is_delete = true; tes.deleted_by = entity.UserId; tes.deleted_on = DateTime.Now; object data2 = new { tes.id, tes.title, tes.content, tes.is_delete }; 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 = "Testimony Not Found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(BootcampTypeViewModel entity) { ResponseResult result = new ResponseResult(); using (var db = new XBC_Context()) { t_bootcamp_type botp = db.t_bootcamp_type.Where(o => o.id == entity.id).FirstOrDefault(); if (botp != null) { var json = new JavaScriptSerializer().Serialize(botp); 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; botp.is_delete = true; botp.deleted_by = entity.UserId; botp.deleted_on = DateTime.Now; var json2 = new JavaScriptSerializer().Serialize(botp); log.json_after = json2; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Bootcamp Type not found!"; } } return(result); }
public static ResponseResult Delete(BootcampTestTypeViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_bootcamp_test_type btt = db.t_bootcamp_test_type.Where(o => o.id == entity.id).FirstOrDefault(); if (btt != null) { btt.is_delete = true; btt.deleted_by = entity.UserId; btt.created_on = DateTime.Now; db.SaveChanges(); object data = new { btt.id, btt.name, btt.notes }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Modified"; log.json_insert = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); } else { result.Success = false; result.ErrorMessage = "Bootcamp Test Type Not Found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(CategoryViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_category cat = db.t_category.Where(o => o.id == entity.id).FirstOrDefault(); if (cat != null) { var json = new JavaScriptSerializer().Serialize(cat); 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; cat.is_delete = true; cat.deleted_by = entity.UserId; cat.deleted_on = DateTime.Now; db.SaveChanges(); var json2 = new JavaScriptSerializer().Serialize(cat); log.json_after = json2; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Category Not Found!"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult DeleteQuestion(Document_Test_DetailViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_document_test_detail cat = db.t_document_test_detail.Where(o => o.id == entity.id).FirstOrDefault(); if (cat != null) { db.t_document_test_detail.Remove(cat); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(cat); t_audit_log log = new t_audit_log(); log.type = "Delete"; log.json_delete = json; 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 = "Category Not Found!"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(ClazzViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_clazz cl = db.t_clazz.Where(o => o.id == entity.id).FirstOrDefault(); if (cl != null) { db.t_clazz.Remove(cl); db.SaveChanges(); //insert AuditLog var json = new JavaScriptSerializer().Serialize(cl); t_audit_log log = new t_audit_log(); log.type = "Delete"; log.json_delete = json; 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 = "Class Not Found!"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult DeleteTrainer(TechnologyTrainerViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_technology_trainer ttr = db.t_technology_trainer .Where(t => t.id == entity.id) .FirstOrDefault(); if (ttr != null) { object data = new { ttr.id, ttr.trainer_id, ttr.technology_id }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Delete"; log.json_delete = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.t_technology_trainer.Remove(ttr); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Trainer Not Found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(MenuAccessViewModel entity) { ResponseResult result = new ResponseResult(); using (var db = new XBC_Context()) { t_menu_access ma = db.t_menu_access.Where(o => o.id == entity.id).FirstOrDefault(); db.t_menu_access.Remove(ma); if (ma != null) { object data = new { ma.id, ma.menu_id, ma.role_id }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "DELETE"; log.json_before = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; var json2 = new JavaScriptSerializer().Serialize(ma); log.json_after = json2; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = " not found! "; } } return(result); }
public static ResponseResult Update(RoleViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { //CREATE if (entity.id == 0) { t_role rol = new t_role(); rol.code = entity.code; //sesuai yg kita input di web rol.name = entity.name; rol.description = entity.description; rol.is_deleted = entity.is_delete; rol.created_by = entity.UserId; rol.created_on = DateTime.Now; db.t_role.Add(rol); db.SaveChanges(); object data = new { rol.id, rol.code, rol.name, rol.description }; 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 = rol.id; result.Entity = entity; } else //EDIT { t_role rol = db.t_role .Where(o => o.id == entity.id) .FirstOrDefault(); if (rol != null) { object data = new { rol.id, rol.code, rol.name, rol.description }; 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; rol.code = entity.code; rol.name = entity.name; rol.description = entity.description; rol.modified_by = entity.UserId; rol.modified_on = DateTime.Now; object data2 = new { rol.id, rol.code, rol.name, rol.description }; 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 = "Role not found!"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Delete(Document_TestViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_document_test doct = db.t_document_test.Where(o => o.id == entity.id).FirstOrDefault(); if (doct != null) { var Serial = new JavaScriptSerializer(); object data = new { doct.id, doct.test_id, doct.test_type_id, doct.token, doct.version, doct.is_delete, doct.deleted_by, doct.deleted_on }; var json = Serial.Serialize(data); doct.is_delete = true; doct.deleted_by = entity.UserId; doct.deleted_on = DateTime.Now; object data2 = new { doct.id, doct.test_id, doct.test_type_id, doct.token, doct.version, doct.is_delete, doct.deleted_by, doct.deleted_on }; t_audit_log log = new t_audit_log(); log.type = "Modify"; log.json_before = json; json = Serial.Serialize(data2); log.json_after = json; 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 = "Category Not Found!"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Update(IdleNewsViewModel entity) { ResponseResult result = new ResponseResult(); using (var db = new XBC_Context()) { if (entity.id == 0) { t_idle_news idn = new t_idle_news(); idn.category_id = entity.categoryId; idn.title = entity.title; idn.content = entity.content; idn.is_publish = entity.isPublish; idn.created_by = entity.UserId; idn.created_on = DateTime.Now; idn.is_delete = false; db.t_idle_news.Add(idn); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(idn); 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 = idn.id; result.Entity = entity; } else //edit { t_idle_news idn = db.t_idle_news.Where(idns => idns.id == entity.id).FirstOrDefault(); if (idn != null) { var Serial = new JavaScriptSerializer(); object data = new { idn.category_id, idn.title, idn.content, idn.is_publish }; var json = Serial.Serialize(data); idn.category_id = entity.categoryId; idn.title = entity.title; idn.content = entity.content; idn.is_publish = entity.isPublish; idn.modified_by = entity.UserId; idn.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; db.SaveChanges(); object data2 = new { idn.category_id, idn.title, idn.content, idn.is_publish }; t_audit_log log = new t_audit_log(); log.type = "Modify"; log.json_before = json; json = Serial.Serialize(data2); log.json_after = json; 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 = "Idle News not found!"; } } } return(result); }
public static ResponseResult Update(Document_TestViewModel entity /*, long id*/) { ResponseResult result = new ResponseResult(); try { //entity.TestType = GetTestType(id); //entity.version = GetNewVersion(entity.test_type_id); if (entity.token == null) { entity.token = RandomString(); } using (var db = new XBC_Context()) { //create if (entity.id == 0) { t_document_test doct = new t_document_test(); doct.version = entity.version; doct.token = entity.token; doct.test_type_id = entity.test_type_id; doct.test_id = entity.test_id; doct.created_by = entity.UserId; doct.created_on = DateTime.Now; db.t_document_test.Add(doct); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(doct); 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 = doct.id; result.Entity = entity; } else //edit { t_document_test doct = db.t_document_test.Where(o => o.id == entity.id).FirstOrDefault(); if (doct != null) { var Serial = new JavaScriptSerializer(); object data = new { doct.created_by, doct.created_on, doct.is_delete, doct.id, doct.modified_by, doct.modified_on, doct.test_id, doct.test_type_id, doct.token, doct.version }; var json = Serial.Serialize(data); if (doct.test_type_id != entity.test_type_id) { doct.version = GetNewVersion(entity.test_type_id); } doct.test_id = entity.test_id; doct.test_type_id = entity.test_type_id; doct.token = entity.token; doct.modified_by = entity.UserId; doct.modified_on = DateTime.Now; object data2 = new { doct.created_by, doct.created_on, doct.is_delete, doct.id, doct.modified_by, doct.modified_on, doct.test_id, doct.test_type_id, doct.token, doct.version }; t_audit_log log = new t_audit_log(); log.type = "Modify"; log.json_before = json; json = Serial.Serialize(data2); log.json_after = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; db.SaveChanges(); //var json2 = new JavaScriptSerializer().Serialize(doct); //log.json_after = json2; //db.t_audit_log.Add(log); result.Entity = entity; //string b = data2.ToString(); // string a = data.ToString(); // b = b + a; // object data3 = new // { // doct.created_by, // b // }; // json = Serial.Serialize(b); } else { result.Success = false; result.ErrorMessage = "Category Not Found"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Update(TrainerViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { //Create if (entity.id == 0) { t_trainer tra = new t_trainer(); tra.name = entity.name; tra.notes = entity.notes; tra.created_by = entity.UserId; tra.created_on = DateTime.Now; db.t_trainer.Add(tra); db.SaveChanges(); object data = new { tra.id, tra.name, tra.notes }; 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 = tra.id; result.Entity = entity; } //edit else { t_trainer tra = db.t_trainer .Where(t => t.id == entity.id) .FirstOrDefault(); if (tra != null) { object data = new { tra.id, tra.name, tra.notes }; 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; tra.name = entity.name; tra.notes = entity.notes; tra.modified_by = entity.UserId; tra.modified_on = DateTime.Now; object data2 = new { tra.id, tra.name, tra.notes }; 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 = "Trainer Not Found!"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Update(BootcampTypeViewModel entity) { ResponseResult result = new ResponseResult(); using (var db = new XBC_Context()) { if (entity.id == 0) { t_bootcamp_type botp = new t_bootcamp_type(); botp.name = entity.name; botp.notes = entity.notes; botp.created_by = 01; botp.created_on = DateTime.Now; botp.is_delete = false; db.t_bootcamp_type.Add(botp); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(botp); 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 = botp.id; result.Entity = entity; } else //edit { t_bootcamp_type botp = db.t_bootcamp_type.Where(btp => btp.id == entity.id).FirstOrDefault(); if (botp != null) { var json = new JavaScriptSerializer().Serialize(botp); 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; botp.name = entity.name; botp.notes = entity.notes; botp.modified_by = entity.UserId; botp.modified_on = DateTime.Now; var json2 = new JavaScriptSerializer().Serialize(botp); log.json_after = json2; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = " Bootcamp Type not found"; } } } return(result); }
public static ResponseResult Update(RoomViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { if (entity.id == 0) { t_room room = new t_room(); room.office_id = entity.officeId; room.code = entity.code; room.name = entity.name; room.capacity = entity.capacity; room.any_projector = entity.any_projector; room.notes = entity.notes; room.is_delete = false; room.created_by = entity.UserId; room.created_on = DateTime.Now; db.t_room.Add(room); db.SaveChanges(); object data = new { room.code, room.name, room.capacity, room.any_projector, room.notes, }; 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); entity.id = room.id; result.Entity = entity; } else { t_room room = db.t_room.Where(o => o.id == entity.id).FirstOrDefault(); if (room != null) { var Serial = new JavaScriptSerializer(); object dataBefore = new { room.code, room.name, room.capacity, room.any_projector, room.notes }; room.code = entity.code; room.name = entity.name; room.capacity = entity.capacity; room.any_projector = entity.any_projector; room.notes = entity.notes; room.is_delete = false; room.modified_by = entity.UserId; room.modified_on = DateTime.Now; db.SaveChanges(); object dataAfter = new { room.code, room.name, room.capacity, room.any_projector, room.notes }; t_audit_log log = new t_audit_log(); log.type = "Modified"; 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 = "Room not Found"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
// Update (Edit & Create) public static ResponseResult Update(BatchViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { if (entity.id == 0) // Create { t_batch bt = new t_batch(); bt.name = entity.name; bt.technology_id = entity.technologyId; bt.period_to = entity.periodTo; bt.bootcamp_type_id = entity.bootcampTypeId; bt.room_id = entity.roomId; bt.trainer_id = entity.trainerId; bt.period_from = entity.periodFrom; bt.notes = entity.notes; bt.created_by = entity.UserId; bt.created_on = DateTime.Now; bt.is_delete = false; db.t_batch.Add(bt); db.SaveChanges(); // Audit Log Insert var json = new JavaScriptSerializer().Serialize(bt); 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 = bt.id; result.Entity = entity; } else // Edit { t_batch bt = db.t_batch.Where(o => o.id == entity.id).FirstOrDefault(); if (bt != null) { var Serial = new JavaScriptSerializer(); object dataBefore = new //Mengambil Data Before for Log { bt.name, bt.technology_id, bt.period_to, bt.bootcamp_type_id, bt.room_id, bt.trainer_id, bt.period_from, bt.notes }; bt.name = entity.name; bt.technology_id = entity.technologyId; bt.period_to = entity.periodTo; bt.bootcamp_type_id = entity.bootcampTypeId; bt.room_id = entity.roomId; bt.trainer_id = entity.trainerId; bt.period_from = entity.periodFrom; bt.notes = entity.notes; bt.modified_by = entity.UserId; bt.modified_on = DateTime.Now; db.SaveChanges(); // Audit Log Modify object dataAfter = new { bt.name, bt.technology_id, bt.period_to, bt.bootcamp_type_id, bt.room_id, bt.trainer_id, bt.period_from, bt.notes }; 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 = "Betch Not Found"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Update(Document_Test_DetailViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { //create if (entity.id == 0) { t_document_test_detail dtd = new t_document_test_detail(); dtd.question_id = entity.question_id; dtd.document_test_id = entity.document_test_id; dtd.created_by = entity.UserId; dtd.created_on = DateTime.Now; db.t_document_test_detail.Add(dtd); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(dtd); 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 = dtd.id; result.Entity = entity; } /*else*/ //edit //{ // t_category cat = db.t_category.Where(o => o.id == entity.id).FirstOrDefault(); // if (cat != null) // { // var json = new JavaScriptSerializer().Serialize(cat); // t_audit_log log = new t_audit_log(); // log.type = "Modify"; // log.json_before = json; // log.created_by = 1; // log.created_on = DateTime.Now; // cat.name = entity.name; // cat.description = entity.description; // cat.modified_by = 1; // cat.modified_on = DateTime.Now; // var json2 = new JavaScriptSerializer().Serialize(cat); // log.json_after = json2; // db.t_audit_log.Add(log); // db.SaveChanges(); // result.Entity = entity; // } // else // { // result.Success = false; // result.ErrorMessage = "Category Not Found"; // } //} } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult Update(FeedbackViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { //create if (entity.id == 0) { t_feedback fed = new t_feedback(); t_document_test_detail dtd = new t_document_test_detail(); fed.test_id = entity.test_id; fed.document_test_id = entity.document_test_id; var Serial = new JavaScriptSerializer(); object data = new { fed.test_id, fed.document_test_id, entity.Feedback }; var json = Serial.Serialize(data); //string a = data.ToString(); //string b; //foreach (var item in FeedbackRepo.ListDTD(entity.document_test_id)) //{ // //dtd.question_id = entity.question_id; // //answer = entity.answer; // object data2 = new // { // //dtd.question_id, // //answer // }; // b = data2.ToString(); // a = a + b; // json = Serial.Serialize(b); //} fed.json_feedback = json; fed.created_by = entity.UserId; fed.created_on = DateTime.Now; db.t_feedback.Add(fed); db.SaveChanges(); var json1 = new JavaScriptSerializer().Serialize(fed); t_audit_log log = new t_audit_log(); log.type = "Insert"; log.json_insert = json1; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); //t_audit_log log = new t_audit_log(); //log.type = "Insert"; //log.json_insert = json; //log.created_by = 1; //log.created_on = DateTime.Now; //db.t_audit_log.Add(log); //db.SaveChanges(); entity.id = fed.id; result.Entity = entity; } else //edit { t_feedback fed = new t_feedback(); t_document_test_detail dtd = new t_document_test_detail(); fed.test_id = entity.test_id; fed.document_test_id = entity.id; var Serial = new JavaScriptSerializer(); object data = new { fed.test_id, fed.document_test_id }; var json = Serial.Serialize(""); string a = data.ToString(); string b; foreach (var item in FeedbackRepo.ListDTD(entity.id)) { //dtd.question_id = entity.question_id; //answer = entity.answer; object data2 = new { //dtd.question_id, //answer }; b = data2.ToString(); a = a + b; json = Serial.Serialize(b); } fed.json_feedback = json; fed.created_by = entity.UserId; fed.created_on = DateTime.Now; db.t_feedback.Add(fed); db.SaveChanges(); 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 = fed.id; result.Entity = entity; //} } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponseResult CopyDocument(Document_TestViewModel entity) { { ResponseResult result = new ResponseResult(); try { //entity.TestType = GetTestType(id); //entity.version = GetNewVersion(entity.test_type_id); //entity.token = RandomString(); using (var db = new XBC_Context()) { //create if (entity.id == 0) { t_document_test doct = new t_document_test(); doct.version = entity.version; doct.token = entity.token; doct.test_type_id = entity.test_type_id; doct.test_id = entity.test_id; doct.created_by = entity.UserId; doct.created_on = DateTime.Now; db.t_document_test.Add(doct); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(doct); 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 = doct.id; result.Entity = entity; } else //edit { t_document_test doct = db.t_document_test.Where(o => o.id == entity.id).FirstOrDefault(); if (doct != null) { t_document_test doct1 = new t_document_test(); doct1.test_id = entity.test_id; doct1.test_type_id = entity.test_type_id; doct1.version = entity.version; doct1.token = entity.token; doct1.created_by = entity.UserId; doct1.created_on = DateTime.Now; db.t_document_test.Add(doct1); db.SaveChanges(); var Serial = new JavaScriptSerializer(); object data2 = new { doct1.id, doct1.created_by, doct1.created_on, doct1.deleted_by, doct1.deleted_on, doct1.is_delete, doct1.modified_by, doct1.modified_on, doct1.test_id, doct1.test_type_id, doct1.token, doct.version }; t_audit_log log = new t_audit_log(); var json = Serial.Serialize(data2); 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(); //var json = new JavaScriptSerializer().Serialize(doct1); //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(); List <t_document_test_detail> results = (from dtd in db.t_document_test_detail where dtd.document_test_id == entity.id select dtd).ToList(); foreach (t_document_test_detail dtd in results) { t_document_test_detail od = new t_document_test_detail(); od.question_id = dtd.question_id; od.document_test_id = doct1.id; od.created_by = entity.UserId; od.created_on = DateTime.Now; db.t_document_test_detail.Add(od); db.SaveChanges(); Serial = new JavaScriptSerializer(); object data = new { od.id, od.document_test_id, od.question_id }; var json2 = Serial.Serialize(data); log.type = "Insert"; log.json_insert = json2; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); } entity.id = doct1.id; result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Document Test Not Found"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); } }