public ActionResult Update(int?HT_id) { // ModelState.Clear(); var model = HT_id.HasValue ? db.nvQTHocTap.Find(HT_id) : new nvQTHocTap(); var prefix = "" + Request.Form["Prefix"]; TryUpdateModel(model, !HT_id.HasValue ? prefix : prefix + ".item"); if (ModelState.IsValid) { if (!HT_id.HasValue) { //check db khi deploy if (!model.QuocGia_id.HasValue) { model.QuocGia_id = 1; } if (!model.XepLoaiTotNghiep_id.HasValue) { model.XepLoaiTotNghiep_id = 4; } if (!model.HienTrang_id.HasValue) { model.HienTrang_id = 1; } db.nvQTHocTap.Add(model); } else { db.Entry(model).State = EntityState.Modified; } db.SaveChanges(); if (model.KetThucChinhThuc.HasValue) { try { int tmp = 0; tmp = db.nvBangCap.Where(m => m.HoTro == model.id).Select(m => m.id).FirstOrDefault(); nvBangCap bc = db.nvBangCap.Find(tmp); if (tmp != 0) { bc.Xoa = false; db.SaveChanges(); } else { themBangCap(Convert.ToInt32(model.NV_id), Convert.ToInt32(model.LoaiBangCap_id), 1, model.TenTruong, Convert.ToInt32(model.ChuyenNganh_id), model.ChuyenNganh, Convert.ToInt32(model.LoaiHinhDaoTao_id), Convert.ToDateTime(model.KetThucChinhThuc), Convert.ToInt32(model.XepLoaiTotNghiep_id), false, model.GhiChu, Convert.ToInt32(model.NoiHoc_id), Convert.ToInt32(model.QuocGia_id), false, model.id); } } catch { } } TempData["Message"] = "Thành công"; } else { TempData["Model"] = model; } TempData["ModelState"] = ModelState; return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { nvBangCap model = db.nvBangCap.Find(id); // db.nvBangCap.Remove(model); model.Xoa = true; db.SaveChanges(); TempData["Message"] = "CapNhatThanhCong"; return(RedirectToAction("Details/" + model.NV_id, "HSNhanSu", new { tab = "QTHocTap" })); }
public ActionResult Delete(int id) { nvBangCap model = db.nvBangCap.Find(id); // db.nvBangCap.Remove(model); model.Xoa = true; db.SaveChanges(); try { nvQTHocTap ht = db.nvQTHocTap.Find(model.HoTro); int tmp = 0; tmp = db.nvQTHocTap.Where(m => m.id == model.HoTro).Select(m => m.id).FirstOrDefault(); if (tmp != 0) { ht.KetThucChinhThuc = null; db.SaveChanges(); } } catch { } TempData["Message"] = "CapNhatThanhCong"; return(RedirectToAction("Details/" + model.NV_id, "HSNhanSu", new { tab = "QTHocTap" })); }
private int themBangCap(int nv_id, int loaibangcap_id, int danhhieu_id, string tentruong, int chuyennganh_id, string chuyennganh, int loaihinhdaotao_id, DateTime ngaytn, int xeploaitotnghiep_id, bool chuyennganhchinh, string ghichu, int noihoc_id, int quocgia_id, bool danhhieuchinh, int hotro) { using (var db = new HRMDBEntities()) { //check danh hieu cho từng loại db int danhhieu = 0; switch (loaibangcap_id) { case 1: danhhieu = 3; break; case 2: danhhieu = 1; break; case 3: danhhieu = 7; break; case 4: danhhieu = 8; break; case 5: danhhieu = 9; break; case 6: break; case 7: danhhieu = 2; break; default: break; } var tv = new nvBangCap { NV_id = nv_id, LoaiBangCap_id = loaibangcap_id, DanhHieu_id = danhhieu, TenTruong = tentruong, ChuyenNganh_id = chuyennganh_id, ChuyenNganh = chuyennganh, LoaiHinhDaoTao_id = loaibangcap_id, NgayTN = ngaytn, XepLoaiTotNghiep_id = xeploaitotnghiep_id, ChuyenNganhChinh = chuyennganhchinh, GhiChu = ghichu, NoiHoc_id = noihoc_id, QuocGia_id = quocgia_id, DanhHieuChinh = danhhieuchinh, HoTro = hotro, Xoa = false, SauKhiVeTruong = true }; db.nvBangCap.Add(tv); db.SaveChanges(); return(tv.id); } }