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 string Create(string dm, DanhMuc model) { if (ModelState.IsValid) { var danhmuc = db.makeDanhMuc(dm, model); TryValidateModel(danhmuc); if (ModelState.IsValid) { if (model.stt.HasValue) { db.updateSTT(dm, model.stt.Value); } db.Entry(danhmuc).State = EntityState.Added; db.SaveChanges(); // for unit testing model.id = (int)danhmuc.GetType().GetProperty("id").GetValue(danhmuc, null); return("OK"); } } foreach (var state in ModelState.Values) { if (state.Errors.Count > 0) { return(state.Errors[0].ErrorMessage); } } return("ModelState Invalid!"); }
public ActionResult Update(int NV_id, int[] CT_id) { ModelState.Clear(); var models = db.nvQLTapSu.Where(ct => CT_id.Contains(ct.CT_id)); foreach (var item in models) { TryUpdateModel <nvQLTapSu>(item, String.Format("{0}.{1}", NV_id, item.CT_id)); } if (ModelState.IsValid) { foreach (var item in models) { db.Entry(item).State = EntityState.Modified; } db.SaveChanges(); TempData["Message"] = "CapNhatThanhCong"; } else { TempData["Message"] = "CapNhatKhongThanhCong"; } TempData["NV_id"] = NV_id; return(RedirectToAction("Index", new { From = Request["From"], To = Request["To"], All = Request["All"] })); }
public ActionResult Update(int?BC_id) { var model = BC_id.HasValue ? db.nvBangCap.Find(BC_id) : new nvBangCap(); var prefix = "" + Request.Form["Prefix"]; TryUpdateModel(model, !BC_id.HasValue ? prefix : prefix + ".item"); if (ModelState.IsValid) { if (!BC_id.HasValue) { db.nvBangCap.Add(model); } else { db.Entry(model).State = EntityState.Modified; } db.SaveChanges(); TempData["Message"] = "Thành công"; } else { TempData["Model"] = model; } TempData["ModelState"] = ModelState; return(RedirectToAction("Details/" + model.NV_id, "HSNhanSu", new { tab = "QTHocTap" })); }
public ActionResult Update(int?TH_id) { var model = TH_id.HasValue ? db.TapHuan.Find(TH_id) : new TapHuan(); var prefix = "" + Request.Form["Prefix"]; TryUpdateModel(model, !TH_id.HasValue ? prefix : prefix + ".item"); if (ModelState.IsValid) { if (!TH_id.HasValue) { db.TapHuan.Add(model); } else { db.Entry(model).State = EntityState.Modified; } db.SaveChanges(); TempData["Message"] = "CapNhatThanhCong"; } else { TempData["Model"] = model; } TempData["ModelState"] = ModelState; return(RedirectToAction("Details/" + model.id, "HSNhanSu", new { tab = "SoTayCT" })); }
public ActionResult Update(int?BD_id) { var model = BD_id.HasValue ? db.BoiDuongChuyenMon.Find(BD_id) : new BoiDuongChuyenMon(); var prefix = String.Format("{0}", Request.Form["Prefix"]); TryUpdateModel(model, !BD_id.HasValue ? prefix : prefix + ".item"); if (ModelState.IsValid) { if (!BD_id.HasValue) { db.BoiDuongChuyenMon.Add(model); } else { db.Entry(model).State = EntityState.Modified; } db.SaveChanges(); TempData["Message"] = "CapNhatThanhCong"; } else { TempData["Model"] = model; } TempData["ModelState"] = ModelState; return(RedirectToAction("Details/" + model.NV_id, "HSNhanSu", new { tab = "BoiDuongChuyenMon" })); }
public PartialViewResult Index() { var model = (from donvi in db.dmDonVi orderby donvi.stt select donvi).ToList(); for (int i = 0, c = 1; i < model.Count; i++, c++) { if (model[i].stt != c) { model[i].stt = c; db.Entry(model[i]).State = EntityState.Modified; } } db.SaveChanges(); return(PartialView(model)); }
public PartialViewResult Index() { var model = (from ngach in db.dmNgachVienChuc orderby ngach.stt select ngach).ToList(); for (int i = 0, c = 1; i < model.Count; i++, c++) { if (model[i].stt != c) { model[i].stt = c; db.Entry(model[i]).State = EntityState.Modified; } } db.SaveChanges(); return(PartialView(model)); }
public ActionResult Edit(QuaTrinhHoc quatrinhhoc) { if (ModelState.IsValid) { db.Entry(quatrinhhoc).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(quatrinhhoc)); }
public string Edit(dmBangLuong model) { if (ModelState.IsValid) { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return("OK"); } return("ModelState Invalid!"); }
public string Edit(dmPhuongXa model) { if (ModelState.IsValid) { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return("OK"); } return(ModelState.getErrorMessage()); }
public static void updateSTT(this HRMDBEntities db, string name, int start) { var dbset = db.GetType().GetProperty("dm" + name).GetValue(db, null) as IEnumerable <object>; dbset.Where(dm => dm.stt() >= start).ToList().ForEach( dm => { dm.stt(dm.stt().Value + 1); db.Entry(dm).State = EntityState.Modified; }); }
public ActionResult Edit(DanhHieu danhhieu) { if (ModelState.IsValid) { db.Entry(danhhieu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TenDanhHieu_id = new SelectList(db.dmDanhHieu, "id", "TenDanhHieu", danhhieu.TenDanhHieu_id); ViewBag.NV_id = new SelectList(db.NhanVien, "id", "MaNV", danhhieu.NV_id); return(View(danhhieu)); }
public static void taoNhanVienMoi_Ten(string maHS, string maNV, string HoTen) { taoNhanVienMoi(maHS, maNV); using (var db = new HRMDBEntities()) { var nv = db.NhanViens.All.Single(n => n.MaNV == maNV); var syll = nv.nvSoYeuLyLiches.First(); syll.HoVaTen = HoTen; db.Entry(syll).State = EntityState.Modified; db.SaveChanges(); } }
public string Edit(dmLoaiNghiNganHan model) { if (model.stt <= 0) { return("STT phải lớn hơn 0!"); } if (ModelState.IsValid) { var nghi = db.dmLoaiNghiNganHan.AsNoTracking().Single(dm => dm.id == model.id); if (nghi.stt != model.stt) { db.dmLoaiNghiNganHan.Where(dm => dm.stt >= model.stt).ToList().ForEach( dm => { dm.stt++; db.Entry(dm).State = EntityState.Modified; }); } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return("OK"); } return("ModelState Invalid!"); }
public ActionResult Rename(TaiNguyen model, string folder) { if (ModelState.IsValid) { using (var scope = new TransactionScope()) try { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); model.Include(db); if (model.laThuMuc) { Rename(folder, model.getFolder()); } scope.Complete(); return(RedirectToAction("Index", new { parent = model.idTaiNguyen })); } catch (Exception e) { ModelState.AddModelError("tenTaiNguyen", e.Message); } } return(View(model)); }
public ActionResult Update(int NV_id) { var model = db.NhanViens.All.Find(NV_id).nvTTMoRongs.Single(); ModelState.Clear(); TryUpdateModel(model); if (ModelState.IsValid) { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); TempData["Message"] = "CapNhatThanhCong"; } ViewBag.DB = db; TempData["ModelState"] = ModelState; return(RedirectToAction("Details/" + NV_id, "HSNhanSu", new { tab = "nvTTMoRong" })); }
public static IEnumerable <DanhMuc> loadDanhMuc(this HRMDBEntities db, string name) { var dbset = db.GetType().GetProperty("dm" + name).GetValue(db, null); var list = (dbset as IEnumerable <object>).ToList(); list.Sort(new Comparison <object>((o1, o2) => o1.CompareTo(o2))); for (int i = 0, c = 1; i < list.Count; i++, c++) { if (list[i].stt() != c) { list[i].stt(c); db.Entry(list[i]).State = EntityState.Modified; } } db.SaveChanges(); return((from dm in list select new DanhMuc(name, dm)).ToList()); }
public ActionResult Update(int NV_id, int[] KhoaGiangDay, int[] NganhGiangDay) { var model = db.NhanViens.All.Find(NV_id).nvTTThongKes.Single(); ModelState.Clear(); TryUpdateModel(model); if (ModelState.IsValid) { using (var scope = new TransactionScope()) { db.Entry(model).State = EntityState.Modified; // khoa giang day db.SaveChanges(); model.NhanVien.nvKhoaGiangDays.ToList().ForEach(kgd => db.nvKhoaGiangDay.Remove(kgd)); db.SaveChanges(); if (KhoaGiangDay != null) { KhoaGiangDay.ToList().ForEach(id => db.nvKhoaGiangDay.Add(new nvKhoaGiangDay { NV_id = model.NV_id, KhoaGiangDay = id })); } db.SaveChanges(); // nganh giang day model.NhanVien.nvNganhGiangDays.ToList().ForEach(ngd => db.nvNganhGiangDay.Remove(ngd)); db.SaveChanges(); if (NganhGiangDay != null) { NganhGiangDay.ToList().ForEach(id => db.nvNganhGiangDay.Add(new nvNganhGiangDay { NV_id = model.NV_id, NganhGiangDay = id })); } db.SaveChanges(); scope.Complete(); TempData["Controller"] = "nvTTThongKe"; TempData["Message"] = "CapNhatThanhCong"; } } TempData["ModelState"] = ModelState; return(RedirectToAction("Details/" + NV_id, "HSNhanSu", new { tab = "QTCongTac" })); }
public override void Execute() { #line 5 "..\..\Views\nvTTThongKe\Import.cshtml" ViewBag.Title = "Import"; var excel = new LinqToExcel.ExcelQueryFactory(ViewBag.File); #line default #line hidden WriteLiteral("<table>\r\n<tr>\r\n <th>MaNV</th>\r\n <th>KhoaGiangDayChinh</th>\r\n <th>KhoaGia" + "ngDay</th>\r\n <th>NganhGiangDayChinh</th>\r\n <th>NganhGiangDay</th>\r\n</tr>\r\n" + ""); #line 17 "..\..\Views\nvTTThongKe\Import.cshtml" using (var db = new HRMDBEntities()) { foreach (var row in excel.Worksheet()) { var MaNV = row["(MaNV)"].Value as string; var NhanVien = db.NhanViens.All.SingleOrDefault(nv => nv.MaNV == MaNV); if (NhanVien == null) { #line default #line hidden WriteLiteral(" <tr><td>"); #line 25 "..\..\Views\nvTTThongKe\Import.cshtml" Write(MaNV); #line default #line hidden WriteLiteral(" not found!</td></tr>\r\n"); #line 26 "..\..\Views\nvTTThongKe\Import.cshtml" break; } var maLoai = row["(PhanLoaiCBGVNV)"].Value as string; var Loai = db.dmPhanLoaiCBGVNV.SingleOrDefault(l => l.maPhanLoaiCBGVNV == maLoai); if (Loai == null && !String.IsNullOrEmpty(maLoai)) { #line default #line hidden WriteLiteral(" <tr><td>"); #line 32 "..\..\Views\nvTTThongKe\Import.cshtml" Write(maLoai); #line default #line hidden WriteLiteral(" not found!</td></tr>\r\n"); #line 33 "..\..\Views\nvTTThongKe\Import.cshtml" break; } var maKhoa = row["(KhoaGiangDayChinh)"].Value as string; var Khoa = db.dmKhoaGiangDay.SingleOrDefault(k => k.maKhoaGiangDay == maKhoa); if (Khoa == null && !String.IsNullOrEmpty(maKhoa)) { #line default #line hidden WriteLiteral(" <tr><td>"); #line 39 "..\..\Views\nvTTThongKe\Import.cshtml" Write(maKhoa); #line default #line hidden WriteLiteral(" not found!</td></tr>\r\n"); #line 40 "..\..\Views\nvTTThongKe\Import.cshtml" break; } var maKhoas = (row["(KhoaGiangDay)"].Value as string ?? "").Split(',').Where(m => !String.IsNullOrEmpty(m)); var Khoas = (from m in maKhoas select db.dmKhoaGiangDay.SingleOrDefault(k => k.maKhoaGiangDay == m)); if (Khoas.Contains(null) && !String.IsNullOrEmpty(String.Join("", maKhoas))) { #line default #line hidden WriteLiteral(" <tr><td>"); #line 46 "..\..\Views\nvTTThongKe\Import.cshtml" Write(maKhoas); #line default #line hidden WriteLiteral(" not found!</td></tr>\r\n"); #line 47 "..\..\Views\nvTTThongKe\Import.cshtml" break; } var maNganh = row["(NganhGiangDayChinh)"].Value as string; var Nganh = db.dmNganhGiangDay.SingleOrDefault(n => n.maNganhGiangDay == maNganh); if (Nganh == null && !String.IsNullOrEmpty(maNganh)) { #line default #line hidden WriteLiteral(" <tr><td>"); #line 53 "..\..\Views\nvTTThongKe\Import.cshtml" Write(maNganh); #line default #line hidden WriteLiteral(" not found!</td></tr>\r\n"); #line 54 "..\..\Views\nvTTThongKe\Import.cshtml" break; } var maNganhs = (row["(NganhGiangDay)"].Value as string ?? "").Split(',').Where(m => !String.IsNullOrEmpty(m)); var Nganhs = (from m in maNganhs select db.dmNganhGiangDay.SingleOrDefault(n => n.maNganhGiangDay == m)); if (Nganhs.Contains(null) && !String.IsNullOrEmpty(String.Join("", maNganhs))) { #line default #line hidden WriteLiteral(" <tr><td>"); #line 60 "..\..\Views\nvTTThongKe\Import.cshtml" Write(maNganhs); #line default #line hidden WriteLiteral(" not found!</td></tr>\r\n"); #line 61 "..\..\Views\nvTTThongKe\Import.cshtml" break; } var nvTTThongKe = NhanVien.nvTTThongKes.SingleOrDefault(); if (nvTTThongKe == null) { using (var controller = new nvTTThongKeController()) { controller.Create(NhanVien.id); } } nvTTThongKe.dmPhanLoaiCBGVNV = Loai; nvTTThongKe.dmKhoaGiangDay = Khoa; NhanVien.nvKhoaGiangDays.ToList().ForEach(k => db.Entry(k).State = EntityState.Deleted); Khoas.ToList().ForEach(k => db.nvKhoaGiangDay.Add(new nvKhoaGiangDay { NV_id = NhanVien.id, KhoaGiangDay = k.id })); nvTTThongKe.dmNganhGiangDay = Nganh; NhanVien.nvNganhGiangDays.ToList().ForEach(n => db.Entry(n).State = EntityState.Deleted); Nganhs.ToList().ForEach(n => db.nvNganhGiangDay.Add(new nvNganhGiangDay { NV_id = NhanVien.id, NganhGiangDay = n.id })); db.Entry(nvTTThongKe).State = EntityState.Modified; #line default #line hidden WriteLiteral(" <tr>\r\n <td>"); #line 80 "..\..\Views\nvTTThongKe\Import.cshtml" Write(row["(MaNV)"]); #line default #line hidden WriteLiteral("</td>\r\n <td>"); #line 81 "..\..\Views\nvTTThongKe\Import.cshtml" Write(row["(KhoaGiangDayChinh)"]); #line default #line hidden WriteLiteral("</td>\r\n <td>"); #line 82 "..\..\Views\nvTTThongKe\Import.cshtml" Write(row["(KhoaGiangDay)"]); #line default #line hidden WriteLiteral("</td>\r\n <td>"); #line 83 "..\..\Views\nvTTThongKe\Import.cshtml" Write(row["(NganhGiangDayChinh)"]); #line default #line hidden WriteLiteral("</td>\r\n <td>"); #line 84 "..\..\Views\nvTTThongKe\Import.cshtml" Write(row["(NganhGiangDay)"]); #line default #line hidden WriteLiteral("</td>\r\n </tr>\r\n"); #line 86 "..\..\Views\nvTTThongKe\Import.cshtml" } db.SaveChanges(); } #line default #line hidden WriteLiteral("</table>\r\n"); }