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 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 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 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); }