public static ResponResultViewModel Update(MenuViewModel entity, long userid) { //untuk create & edit ResponResultViewModel result = new ResponResultViewModel(); entity.code = GetNewMenu(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_menu menu = new t_menu(); menu.code = entity.code; menu.title = entity.title; menu.description = entity.description; menu.image_url = entity.image_url; menu.menu_order = entity.menu_order; menu.menu_parent = entity.menu_parent; menu.menu_url = entity.menu_url; menu.created_by = userid; menu.created_on = DateTime.Now; menu.active = entity.active; db.t_menu.Add(menu); db.SaveChanges(); result.Entity = menu; } else { t_menu menu = db.t_menu.Where(x => x.id == entity.id).FirstOrDefault(); if (menu != null) { menu.title = entity.title; menu.description = entity.description; menu.image_url = entity.image_url; menu.menu_order = entity.menu_order; menu.menu_parent = entity.menu_parent; menu.menu_url = entity.menu_url; menu.created_by = userid; menu.created_on = DateTime.Now; menu.active = entity.active; db.SaveChanges(); result.Entity = entity; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public static ResponResultViewModel Update2(TrainerViewModel entity) { //untuk create dan edit ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_trainer trainer = new t_trainer(); trainer.name = entity.name; trainer.notes = entity.notes; trainer.active = entity.active; trainer.created_by = 1; trainer.created_on = DateTime.Now; db.t_trainer.Add(trainer); db.SaveChanges(); result.Entity = trainer; } else { t_trainer trainer = db.t_trainer.Where(o => o.id == entity.id).FirstOrDefault(); if (trainer != null) { trainer.name = entity.name; trainer.notes = entity.notes; trainer.active = false; trainer.created_by = 1; trainer.created_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "trainer not found!"; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public static ResponResultViewModel Update2(TestimonyViewModel entity) { //untuk create dan edit ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_testimony testimony = new t_testimony(); testimony.title = entity.title; testimony.content = entity.content; testimony.is_delete = entity.is_delete; testimony.created_by = 1; testimony.created_on = DateTime.Now; db.t_testimony.Add(testimony); db.SaveChanges(); result.Entity = testimony; } else { t_testimony testimony = db.t_testimony.Where(o => o.id == entity.id).FirstOrDefault(); if (testimony != null) { testimony.title = entity.title; testimony.content = entity.content; testimony.is_delete = true; testimony.created_by = 1; testimony.created_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "testimony not found!"; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public static ResponResultViewModel Update(IdleViewModel entity) { //create - edit ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_idle_news idl = new t_idle_news(); idl.title = entity.title; idl.category_id = entity.category_id; idl.content = entity.content; idl.is_publish = false; idl.created_by = 1; idl.created_on = DateTime.Now; idl.is_delete = false; db.t_idle_news.Add(idl); db.SaveChanges(); result.Entity = entity; } else { t_idle_news idl = db.t_idle_news.Where(o => o.id == entity.id).FirstOrDefault(); if (idl != null) { idl.title = entity.title; idl.category_id = entity.category_id; idl.content = entity.content; idl.modified_by = 1; idl.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "Idle Not Found"; } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel Update(UserViewModel entity, long userid) { //untuk create & edit ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_user user = new t_user(); user.username = entity.username; user.password = entity.password; user.role_id = entity.role_id; user.mobile_flag = entity.mobile_flag; user.mobile_token = entity.mobile_token; user.created_by = userid; user.created_on = DateTime.Now; user.active = entity.active; db.t_user.Add(user); db.SaveChanges(); result.Entity = user; } else { t_user user = db.t_user.Where(x => x.id == entity.id).FirstOrDefault(); if (user != null) { user.username = entity.username; user.password = entity.password; user.role_id = entity.role_id; user.mobile_flag = entity.mobile_flag; user.mobile_token = entity.mobile_token; user.modified_by = userid; user.modified_on = DateTime.Now; user.active = entity.active; db.SaveChanges(); result.Entity = entity; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public static ResponResultViewModel Update(BootcampTypeViewModel entity) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_bootcamp_type bt = new t_bootcamp_type(); bt.name = entity.name; bt.notes = entity.notes; bt.created_by = 1; bt.created_on = DateTime.Now; bt.active = true; db.t_bootcamp_type.Add(bt); db.SaveChanges(); result.Entity = entity; } else { if (entity != null) { t_bootcamp_type bt = db.t_bootcamp_type.Where(o => o.id == entity.id).FirstOrDefault(); bt.name = entity.name; bt.notes = entity.notes; bt.modified_by = 1; bt.modified_on = DateTime.Now; bt.active = true; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "Bootcamp Type Not Found"; } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel Update(RoleViewModel entity, long userid) { //untuk create & edit ResponResultViewModel result = new ResponResultViewModel(); entity.code = GetNewRole(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_role role = new t_role(); role.code = entity.code; role.name = entity.name; role.description = entity.description; role.created_by = userid; role.created_on = DateTime.Now; role.active = entity.active; db.t_role.Add(role); db.SaveChanges(); result.Entity = role; } else { t_role role = db.t_role.Where(x => x.id == entity.id).FirstOrDefault(); if (role != null) { role.name = entity.name; role.description = entity.description; role.modified_by = userid; role.modified_on = DateTime.Now; role.active = entity.active; db.SaveChanges(); result.Entity = entity; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public static ResponResultViewModel CreatePlacement(MonitoringViewModel entity) { //Untuk placement ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_monitoring mn = db.t_monitoring.Where(o => o.id == entity.id).FirstOrDefault(); if (mn != null) { mn.placement_date = entity.placement_date; mn.placement_at = entity.placement_at; mn.notes = entity.notes; mn.modified_by = 2; mn.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel DeletePart(long id) { ResponResultViewModel result = new ResponResultViewModel(); try { using (MinProContext db = new MinProContext()) { t_clazz clazz = db.t_clazz.Where(x => x.id == id).FirstOrDefault(); if (clazz == null) { result.Success = false; result.Message = "Participant not found"; } else { result.Entity = clazz; db.t_clazz.Remove(clazz); db.SaveChanges(); } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public static bool Update2(UserViewModel model) { bool result = false; using (MinProContext db = new MinProContext()) { t_user user = db.t_user.Find(model.id); user.username = model.username; user.password = model.password; user.role_id = model.role_id; user.mobile_flag = model.mobile_flag; user.mobile_token = model.mobile_token; user.created_by = model.id; user.created_on = DateTime.Now; user.modified_by = model.id; user.modified_on = DateTime.Now; user.active = model.active; try { db.SaveChanges(); result = true; } catch (Exception e) { result = false; } } return(result); }
public static ResponResultViewModel Update(ClassViewModel entity) { //untuk create & edit ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_clazz clazz = new t_clazz(); clazz.batch_id = entity.id; clazz.biodata_id = entity.id; clazz.created_by = 1; clazz.created_on = DateTime.Now; db.t_clazz.Add(clazz); db.SaveChanges(); result.Entity = clazz; } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public static ResponResultViewModel Deactive(MenuViewModel entity, long userid) { //untuk deactive ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_menu menu = db.t_menu.Where(x => x.id == entity.id).FirstOrDefault(); if (menu != null) { menu.active = false; menu.modified_by = userid; menu.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "user not found!"; } } } catch (Exception e) { result.Success = false; result.Message = e.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 Delete(long id) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_bootcamp_type bt = db.t_bootcamp_type.Where(o => o.id == id).FirstOrDefault(); if (bt == null) { result.Success = false; result.Message = "Bootcamp Type Not Found"; } else { result.Entity = bt; db.t_bootcamp_type.Remove(bt); db.SaveChanges(); } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel Update(MenuAccessViewModel entity) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_menu_access ma = new t_menu_access(); ma.menu_id = entity.menu_id; ma.role_id = entity.role_id; ma.created_by = 1; ma.created_on = DateTime.Now; db.t_menu_access.Add(ma); db.SaveChanges(); result.Entity = entity; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel Deact(BatchViewModel model) { ResponResultViewModel result = new ResponResultViewModel(); using (var db = new MinProContext()) { t_batch batch = db.t_batch.Where(x => x.id == model.id).FirstOrDefault(); batch.is_delete = false; batch.deleted_by = 1; batch.deleted_on = DateTime.Now; batch.name = model.name; try { db.SaveChanges(); result.Entity = model; } catch (Exception e) { result.Success = false; result.Message = e.Message; } } return(result); }
public static ResponResultViewModel Is_Delete(MonitoringViewModel entity) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_monitoring mn = db.t_monitoring.Where(o => o.id == entity.id).FirstOrDefault(); if (mn != null) { mn.is_delete = true; mn.deleted_by = 1; mn.deleted_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel Delete(long id) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_menu_access ma = db.t_menu_access.Where(o => o.id == id).FirstOrDefault(); if (ma == null) { result.Success = false; result.Message = "Menu Access Not Found"; } else { result.Entity = ma; db.t_menu_access.Remove(ma); db.SaveChanges(); } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResponResultViewModel CreateHold(AssignmentViewModel entity) { //Untuk placement ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_assignment asg = db.t_assignment.Where(o => o.id == entity.id).FirstOrDefault(); if (asg != null) { asg.biodata_id = entity.biodata_id; asg.is_hold = true; asg.modified_by = 2; asg.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } } } catch (Exception ex) { result.Success = false; result.Message = ex.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); }
public static ResponResultViewModel Create(VersionViewModel entity, long userid) { //Create n Version + 1 ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_version version = new t_version(); version.version = entity.version; version.created_by = userid; version.created_on = DateTime.Now; version.is_delete = false; foreach (var quiz in entity.questions) { t_version_detail vd = new t_version_detail(); vd.version_id = version.id; vd.question_id = quiz.id; vd.created_by = userid; vd.created_on = DateTime.Now; db.t_version_detail.Add(vd); } db.t_version.Add(version); db.SaveChanges(); result.Entity = entity; } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static void Delete(string json_insert, long userid) { //Delete fisik DATABASE try { using (var db = new MinProContext()) { t_audit_log log = new t_audit_log(); log.type = "DELETE"; log.json_insert = json_insert; log.created_by = userid; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); } } catch (Exception ex) { } }
public static void Insert(string json_insert, long userid) { //Untuk create dan Insert ke database try { using (var db = new MinProContext()) { t_audit_log log = new t_audit_log(); log.type = "CREATE"; log.json_insert = json_insert; log.created_by = userid; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); } } catch (Exception ex) { } }
public static void Modify(string json_after, string json_before, long userid) { //Untuk Update, Deactivate,isDelete try { using (var db = new MinProContext()) { t_audit_log log = new t_audit_log(); log.type = "MODIFY"; log.json_after = json_after; log.json_before = json_before; log.created_by = userid; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); } } catch (Exception ex) { } }
public static List <VersionViewModel> All(long userid) { List <VersionViewModel> result = new List <VersionViewModel>(); using (var db = new MinProContext()) { result = (from c in db.t_version where c.is_delete == false orderby c.version descending select new VersionViewModel { id = c.id, version = c.version }).Take(1).ToList(); if (result.Count == 0) { t_version version = new t_version(); version.version = 1; version.created_by = userid; version.created_on = DateTime.Now; version.is_delete = false; db.t_version.Add(version); db.SaveChanges(); result = (from c in db.t_version where c.is_delete == false select new VersionViewModel { id = c.id, version = c.version }).ToList(); } } return(result); }
//SET TO DB public static ResponResultViewModel Save(FeedbackViewModel entity, long userid) { ResponResultViewModel res = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_feedback feedback = new t_feedback(); feedback.version_id = entity.version_id; feedback.test_id = entity.test_id; feedback.json_feedback = entity.json_feedback; feedback.created_by = userid; feedback.created_on = DateTime.Now; feedback.is_delete = false; db.t_feedback.Add(feedback); db.SaveChanges(); res.Entity = feedback; } else { res.Success = false; res.Message = "Feedback Not Found"; } } } catch (Exception e) { res.Success = false; res.Message = e.Message; } return(res); }
// Untuk melakukan deaktivasi item public static ResponResultViewModel Deactivate(RoomViewModel entity) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_room room = db.t_room.Where(item => item.id == entity.id).FirstOrDefault(); if (room != null) { room.active = false; // user yang merubah room.modified_by = 1; room.modified_on = DateTime.Now; result.Entity = entity; db.SaveChanges(); } else { result.Success = false; result.Message = "Item not found"; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
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 Delete(VersionViewModel entity, long userid) { //Delete Version ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_version version = db.t_version.Where(o => o.id == entity.id).FirstOrDefault(); if (version != null) { version.version = entity.version; version.deleted_by = userid; version.deleted_on = DateTime.Now; version.is_delete = true; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "Version not Found!"; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
// Untuk melakukan pembuatan item baru dan perubahan item yang sudah ada public static ResponResultViewModel Update(RoomViewModel entity) { ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { // membuat item baru if (entity.id == 0) { t_room room = new t_room(); room.id = entity.id; room.code = entity.code; room.name = entity.name; room.capacity = entity.capacity; room.any_projector = entity.any_projector; room.notes = entity.notes; room.office_id = entity.office_id; // user yang membuat data room.created_by = 1; room.created_on = DateTime.Now; // simpan ke result result.Entity = entity; // menyimpan ke obyek DbContext dan menyimpan perubahan data db.t_room.Add(room); db.SaveChanges(); } // merubah item lama else { t_room room = db.t_room.Where(item => item.id == entity.id).FirstOrDefault(); if (room != null) { room.id = entity.id; room.code = entity.code; room.name = entity.name; room.capacity = entity.capacity; room.any_projector = entity.any_projector; room.notes = entity.notes; room.office_id = entity.office_id; // user yang merubah data room.modified_by = 1; room.modified_on = DateTime.Now; // simpan ke obyek result result.Entity = entity; // simpan perubahan data di database db.SaveChanges(); } else { result.Success = false; result.Message = "Item not found"; } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }