// Get By Id public static QuestionViewModel ById(long id) { QuestionViewModel result = new QuestionViewModel(); using (var db = new XBC_Context()) { result = (from q in db.t_question where q.id == id && q.is_deleted == false select new QuestionViewModel { id = q.id, questionType = q.question_type, question = q.question, imageUrl = q.image_url, optionA = q.option_a, optionB = q.option_b, optionC = q.option_c, optionD = q.option_d, optionE = q.option_e, imageA = q.image_a, imageB = q.image_b, imageC = q.image_c, imageD = q.image_d, imageE = q.image_e }).FirstOrDefault(); } return(result == null ? result = new QuestionViewModel() : 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); }
//Get By Id public static BatchViewModel ById(long id) { BatchViewModel result = new BatchViewModel(); using (var db = new XBC_Context()) { result = (from b in db.t_batch join tc in db.t_technology on b.technology_id equals tc.id //into btc //from tc in btc.DefaultIfEmpty() join tr in db.t_trainer on b.trainer_id equals tr.id //into btr //from tr in btr.DefaultIfEmpty() join bt in db.t_bootcamp_type on b.bootcamp_type_id equals bt.id into bbt from bt in bbt.DefaultIfEmpty() join rm in db.t_room on b.room_id equals rm.id into brm from rm in brm.DefaultIfEmpty() where b.id == id && b.is_delete == false select new BatchViewModel { id = b.id, technologyName = tc.name, name = b.name, trainerName = tr.name, technologyId = tc.id, periodFrom = b.period_from, bootcampTypeId = bt.id, roomId = rm.id, trainerId = tr.id, periodTo = b.period_to, notes = b.notes }).FirstOrDefault(); } return(result == null ? result = new BatchViewModel() : 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); }
//getbyid public static IdleNewsViewModel ById(long id) { IdleNewsViewModel result = new IdleNewsViewModel(); using (var db = new XBC_Context()) { result = (from idn in db.t_idle_news join cat in db.t_category on idn.category_id equals cat.id where idn.id == id && idn.is_delete == false select new IdleNewsViewModel { id = idn.id, categoryId = idn.category_id, categoryName = cat.name, title = idn.title, content = idn.content, isPublish = idn.is_publish, isDelete = idn.is_delete }).FirstOrDefault(); if (result == null) { result = new IdleNewsViewModel(); } } return(result); }
public static List <Document_Test_DetailViewModel> ViewTest(long id) { List <Document_Test_DetailViewModel> result = new List <Document_Test_DetailViewModel>(); using (var db = new XBC_Context()) { result = (from dtd in db.t_document_test_detail join dt in db.t_document_test on dtd.document_test_id equals dt.id join q in db.t_question on dtd.question_id equals q.id where dtd.document_test_id == id select new Document_Test_DetailViewModel { id = dtd.id, document_test_id = dt.id, question_id = q.id, question = q.question, questionType = q.question_type, imageUrl = q.image_url, imageA = q.image_a, imageB = q.image_b, imageC = q.image_c, imageD = q.image_d, imageE = q.image_e, optionA = q.option_a, optionB = q.option_b, optionC = q.option_c, optionD = q.option_d, optionE = q.option_e }).ToList(); } return(result == null ? new List <Document_Test_DetailViewModel>() : result); }
public static RoomViewModel ById(long id) { RoomViewModel result = new RoomViewModel(); using (var db = new XBC_Context()) { result = (from r in db.t_room join o in db.t_office on r.office_id equals o.id where r.id == id select new RoomViewModel { id = r.id, code = r.code, name = r.name, capacity = r.capacity, any_projector = r.any_projector, notes = r.notes, isDelete = r.is_delete }).FirstOrDefault(); if (result == null) { result = new RoomViewModel(); } } return(result); }
public static List <RoomViewModel> ByOfficeId(long OfId) { List <RoomViewModel> result = new List <RoomViewModel>(); using (var db = new XBC_Context()) { var listRoom = db.t_room.Where(o => o.office_id == OfId && o.is_delete == false).ToList(); if (listRoom != null) { foreach (var r in listRoom) { result.Add(new RoomViewModel { id = r.id, officeId = r.office_id, code = r.code, name = r.name, capacity = r.capacity, any_projector = r.any_projector, notes = r.notes, isDelete = r.is_delete }); } } else { result = new List <RoomViewModel>(); } } return(result); }
public static List <TechnologyTrainerViewModel> ListTrainer(long id) { List <TechnologyTrainerViewModel> result = new List <TechnologyTrainerViewModel>(); using (var db = new XBC_Context()) { result = (from ttr in db.t_technology_trainer join tra in db.t_trainer on ttr.trainer_id equals tra.id where tra.is_delete == false && ttr.technology_id == id select new TechnologyTrainerViewModel { id = ttr.id, trainer_id = ttr.trainer_id, trainer_name = tra.name, technology_id = ttr.technology_id, created_by = ttr.created_by, created_on = DateTime.Now }).ToList(); if (result == null) { result = new List <TechnologyTrainerViewModel>(); } } return(result); }
public static MenuViewModel ById(long id) { MenuViewModel result1 = new MenuViewModel(); string nama = ""; try { using (var db1 = new XBC_Context()) { result1 = (from m in db1.t_menu where m.is_delete == false && m.id == id select new MenuViewModel { id = m.id, code = m.code, title = m.title, descriptoin = m.descriptoin, image_url = m.image_url, menu_order = m.menu_order, menu_parent = m.menu_parent, menu_url = m.menu_url }).FirstOrDefault(); } nama = result1.title; } catch (Exception ex) { Console.Write(ex.Message); } return(result1 == null ? new MenuViewModel() : result1); }
public static OfficeViewModel ById(long id) { OfficeViewModel result = new OfficeViewModel(); using (var db = new XBC_Context()) { result = (from o in db.t_office where o.id == id select new OfficeViewModel { id = o.id, name = o.name, phone = o.phone, email = o.email, address = o.address, notes = o.notes, contact = o.phone + " / " + o.email, isDelete = o.is_delete }).FirstOrDefault(); if (result == null) { result = new OfficeViewModel(); } } return(result); }
public static List <MenuViewModel> Search(string search) { List <MenuViewModel> result = new List <MenuViewModel>(); try { using (var db = new XBC_Context()) { result = (from m in db.t_menu where m.is_delete == false && m.title.Contains(search) select new MenuViewModel { id = m.id, code = m.code, title = m.title, descriptoin = m.descriptoin, image_url = m.image_url, menu_order = m.menu_order, menu_parent = m.menu_parent, menu_url = m.menu_url }).ToList(); } } catch (Exception ex) { Console.Write(ex.Message); } return(result == null ? new List <MenuViewModel>() : result); }
public static AssignmentViewModel ById(long id) { AssignmentViewModel result = new AssignmentViewModel(); try { using (var db = new XBC_Context()) { result = (from m in db.t_assignment where m.is_delete == false && m.id == id && m.is_hold != true select new AssignmentViewModel { id = m.id, biodata_id = m.biodata_id, title = m.title, start_date = m.start_date, end_date = m.end_date, description = m.description, realization_date = m.realization_date, notes = m.notes }).FirstOrDefault(); } } catch (Exception ex) { Console.Write(ex.Message); } return(result == null ? new AssignmentViewModel() : result); }
public static List <AssignmentViewModel> Search(DateTime cari) { List <AssignmentViewModel> result = new List <AssignmentViewModel>(); try { using (var db = new XBC_Context()) { result = (from m in db.t_assignment where m.is_delete == false && m.start_date == cari && m.is_hold != true select new AssignmentViewModel { id = m.id, biodata_id = m.biodata_id, title = m.title, start_date = m.start_date, end_date = m.end_date, description = m.description, realization_date = m.realization_date, notes = m.notes, is_done = m.is_done }).ToList(); } } catch (Exception ex) { Console.Write(ex.Message); } return(result == null ? new List <AssignmentViewModel>() : result); }
public static long ByIdtest(long id) { long result; Document_TestViewModel results = new Document_TestViewModel(); using (var db = new XBC_Context()) { results = (from dt in db.t_document_test join t in db.t_test on dt.test_id equals t.id join tt in db.t_test_type on dt.test_type_id equals tt.id where dt.id == id select new Document_TestViewModel { id = dt.id, token = dt.token, version = dt.version, test_id = t.id, test_type_id = tt.id }).FirstOrDefault(); if (results == null) { result = 0; } } return(result = results.test_type_id); }
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 Document_TestViewModel ByIdCopyDocument(long id) { string ntoken = RandomString(); long id2 = ByIdtest(id); decimal nversion = GetNewVersion(id2); Document_TestViewModel result = new Document_TestViewModel(); using (var db = new XBC_Context()) { result = (from dt in db.t_document_test join t in db.t_test on dt.test_id equals t.id join tt in db.t_test_type on dt.test_type_id equals tt.id where dt.id == id select new Document_TestViewModel { id = dt.id, token = ntoken, version = nversion, test_id = t.id, test_type_id = tt.id }).FirstOrDefault(); if (result == null) { result = new Document_TestViewModel(); } } return(result); }
//RADIO BUTTON public static string GetGender(long Id) { string gender = ""; BiodataViewModel result = new BiodataViewModel(); try { using (var db = new XBC_Context()) { result = (from b in db.t_biodata where b.id == Id select new BiodataViewModel { gender = b.gender }).FirstOrDefault(); if (result != null) { gender = result.gender == null?"" : result.gender; } } } catch (Exception ex) { Console.Write(ex.Message); } return(gender); }
//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); }
//Get All Id public static List <MonitoringViewModel> All() { List <MonitoringViewModel> result = new List <MonitoringViewModel>(); using (var db = new XBC_Context()) { result = (from m in db.t_monitoring join b in db.t_biodata on m.biodata_id equals b.id where m.is_delete == false select new MonitoringViewModel { id = m.id, biodata_id = b.id, name = b.name, idle_date = m.idle_date, placement_date = m.placement_date, is_delete = m.is_delete }).ToList(); if (result == null) { result = new List <MonitoringViewModel>(); } } return(result); }
public static List <Document_Test_DetailViewModel> ListDTD(long id) { List <Document_Test_DetailViewModel> result = new List <Document_Test_DetailViewModel>(); using (var db = new XBC_Context()) { result = (from dtd in db.t_document_test_detail join dt in db.t_document_test on dtd.document_test_id equals dt.id join q in db.t_question on dtd.question_id equals q.id join t in db.t_test on dt.test_id equals t.id where dt.id == id select new Document_Test_DetailViewModel { id = dtd.id, document_test_id = dt.id, question_id = q.id, test_id = t.id, question = q.question, }).ToList(); } return(result == null ? new List <Document_Test_DetailViewModel>() : result); }
//Get By Search public static List <MonitoringViewModel> GetBySearch(string search) { List <MonitoringViewModel> result = new List <MonitoringViewModel>(); using (var db = new XBC_Context()) { result = (from mon in db.t_monitoring join bio in db.t_biodata on mon.biodata_id equals bio.id where mon.t_biodata.name.Contains(search) && mon.is_delete == false select new MonitoringViewModel { id = mon.id, biodata_id = bio.id, name = bio.name, idle_date = mon.idle_date, placement_date = mon.placement_date }).ToList(); if (result == null) { result = new List <MonitoringViewModel>(); } } return(result); }
// Get By Technology (Punya Rido) public static List <TrainerViewModel> ByTechnology(long TcId) { List <TrainerViewModel> result = new List <TrainerViewModel>(); using (var db = new XBC_Context()) { var ListTerainer = db.t_technology_trainer. Where(o => o.technology_id == TcId).ToList(); if (ListTerainer != null) { foreach (var t in ListTerainer) { result = ( from tct in db.t_technology_trainer join tr in db.t_trainer on tct.trainer_id equals tr.id where tr.is_delete == false && tct.technology_id == TcId select new TrainerViewModel { id = tr.id, name = tr.name }).ToList(); } } else { result = new List <TrainerViewModel>(); } } return(result); }
//Get By Id public static MonitoringViewModel ById(long id) { MonitoringViewModel result = new MonitoringViewModel(); using (var db = new XBC_Context()) { result = (from m in db.t_monitoring join b in db.t_biodata on m.biodata_id equals b.id where m.id == id && m.is_delete == false select new MonitoringViewModel { id = m.id, biodata_id = b.id, name = b.name, last_project = m.last_project, idle_reason = m.idle_reason, idle_date = m.idle_date, placement_date = m.placement_date, placement_at = m.placement_at, notes = m.notes, is_delete = m.is_delete }).FirstOrDefault(); if (result == null) { result = new MonitoringViewModel(); } } return(result); }
public static List <IdleNewsViewModel> GetBySearch(string search) { List <IdleNewsViewModel> result = new List <IdleNewsViewModel>(); using (var db = new XBC_Context()) { result = (from idn in db.t_idle_news join cat in db.t_category on idn.category_id equals cat.id where idn.title.Contains(search) && idn.is_delete == false select new IdleNewsViewModel { id = idn.id, categoryId = idn.category_id, categoryName = cat.name, title = idn.title, content = idn.content, isPublish = idn.is_publish, isDelete = idn.is_delete }).ToList(); if (result == null) { result = new List <IdleNewsViewModel>(); } } return(result); }
public static List <Document_TestViewModel> GetBySearch(string cari) { List <Document_TestViewModel> result = new List <Document_TestViewModel>(); using (var db = new XBC_Context()) { result = (from dt in db.t_document_test join t in db.t_test on dt.test_id equals t.id join tt in db.t_test_type on dt.test_type_id equals tt.id where dt.is_delete == false && (tt.name.Contains(cari) || dt.version.ToString().Contains(cari)) select new Document_TestViewModel { id = dt.id, version = dt.version, test_type_id = tt.id, TestType = tt.name, Test = t.name }).ToList(); } return(result == null ? new List <Document_TestViewModel>() : result); }
//Get Participant public static List <BiodataViewModel> ListParticipant() { List <BiodataViewModel> result = new List <BiodataViewModel>(); using (var db = new XBC_Context()) { result = (from b in db.t_biodata join c in db.t_clazz on b.id equals c.biodata_id into bc from c in bc.DefaultIfEmpty() where b.is_deleted == false && c.id.Equals(null) select new BiodataViewModel { id = b.id, name = b.name, majors = b.majors, gpa = b.gpa, is_deleted = b.is_deleted }).ToList(); if (result == null) { result = new List <BiodataViewModel>(); } } return(result); }
public static int GetNewVersion(long id) { int newref1; long newRef = id; using (var db = new XBC_Context()) { var result = (from dt in db.t_document_test //join tt in db.t_test_type //on dt.test_type_id equals tt.id //where tt.name.Contains(newRef) where dt.test_type_id == id select new { Version = dt.version }) .OrderByDescending(o => o.Version) .FirstOrDefault(); if (result != null) { newref1 = int.Parse(result.Version.ToString()) + 1; } else { newref1 = 1; } } return(newref1); }
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 List <TestTypeViewModel> GetBySearch(string search) { List <TestTypeViewModel> result = new List <TestTypeViewModel>(); using (var db = new XBC_Context()) { result = (from ttp in db.t_test_type join us in db.t_user on ttp.created_by equals us.id where ttp.name.Contains(search) && ttp.is_delete == false select new TestTypeViewModel { id = ttp.id, name = ttp.name, notes = ttp.notes, typeofanswer = ttp.type_of_answer, createdBy = ttp.created_by, CreatedByName = us.username }).ToList(); if (result == null) { result = new List <TestTypeViewModel>(); } } return(result); }