public ActionResult AddParticipant(ClazzViewModel model) { ResponseResult result = BatchRepo.Add(model); return(Json(new { success = result.Success, message = result.ErrorMessage, entity = result.Entity }, JsonRequestBehavior.AllowGet)); }
public ActionResult Delete(ClazzViewModel model) { ResponseResult result = ClazzRepo.Delete(model); return(Json(new { success = result.Success, message = result.ErrorMessage, entity = result.Entity }, JsonRequestBehavior.AllowGet)); }
// 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); }
public static ClazzViewModel ById(long id) { ClazzViewModel result = new ClazzViewModel(); using (var db = new XBC_Context()) { result = (from cl in db.t_clazz where cl.id == id select new ClazzViewModel { id = cl.id, batchId = cl.batch_id, biodataId = cl.biodata_id, }).FirstOrDefault(); if (result == null) { result = new ClazzViewModel(); } } 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); }