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!");
 }
Ejemplo n.º 2
0
        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 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?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" }));
        }
Ejemplo n.º 5
0
        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 string Create(dmBangLuong model)
 {
     if (ModelState.IsValid)
     {
         db.dmBangLuong.Add(model);
         db.SaveChanges();
         return("OK");
     }
     return("ModelState Invalid!");
 }
Ejemplo n.º 7
0
 public string Create(dmPhuongXa model)
 {
     if (ModelState.IsValid)
     {
         db.dmPhuongXa.Add(model);
         db.SaveChanges();
         return("OK");
     }
     return(ModelState.getErrorMessage());
 }
 public string Create(dmQuyetDinh model)
 {
     if (ModelState.IsValid)
     {
         db.dmQuyetDinh.Add(model);
         db.SaveChanges();
         return("OK");
     }
     return("ModelState Invalid!");
 }
Ejemplo n.º 9
0
        public ActionResult Create(QuaTrinhHoc quatrinhhoc)
        {
            if (ModelState.IsValid)
            {
                db.QuaTrinhHoc.Add(quatrinhhoc);
                db.SaveChanges();
                return(RedirectToAction("Index", "QTHocTap", new RouteValueDictionary(new{ Controller = "QuaTrinhHoc", Action = "Index", id = quatrinhhoc.NV_id })));
            }

            return(View(quatrinhhoc));
        }
        public ActionResult Create(DanhHieu danhhieu)
        {
            if (ModelState.IsValid)
            {
                db.DanhHieu.Add(danhhieu);
                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));
        }
Ejemplo n.º 11
0
        public PartialViewResult Create(int id)
        {
            var model = db.NhanViens.All.Find(id).nvTTMoRongs.SingleOrDefault();

            if (model == null)
            {
                model = new nvTTMoRong()
                {
                    NV_id = id
                };
                db.nvTTMoRong.Add(model);
                db.SaveChanges();
            }
            return(Edit(model.id));
        }
        public string Create(dmLoaiNghiNganHan model)
        {
            if (model.stt <= 0)
            {
                return("STT phải lớn hơn 0!");
            }
            if (ModelState.IsValid)
            {
                db.dmLoaiNghiNganHan.Add(model);
                db.SaveChanges();
                return("OK");
            }

            return("ModelState Invalid!");
        }
Ejemplo n.º 13
0
        public void Delete(int id)
        {
            nvQTHocTap nvqthoctap = db.nvQTHocTap.Find(id);

            // db.nvBangCap.Remove(model);
//            nvqthoctap.Xoa = true;
            db.SaveChanges();
            TempData["Message"] = "CapNhatThanhCong";
        }
        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));
        }
Ejemplo n.º 15
0
        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 static void taoNhanVienMoi(string maHS, string maNV)
 {
     using (var db = new HRMDBEntities())
     {
         db.NhanViens.All.Add(new NhanVien
         {
             MaHS = maHS, MaNV = maNV
         });
         db.SaveChanges();
     }
 }
 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 ActionResult Create(TaiNguyen model)
 {
     if (ModelState.IsValid)
     {
         using (var scope = new TransactionScope())
         {
             db.TaiNguyen.Add(model);
             db.SaveChanges();
             model.Include(db);
             if (model.laThuMuc)
             {
                 try
                 {
                     Create(model.getFolder());
                     scope.Complete();
                     return(RedirectToAction("Index", new { parent = model.idTaiNguyen }));
                 }
                 catch (Exception e)
                 {
                     ModelState.AddModelError("tenTaiNguyen", e.Message);
                 }
             }
             else
             {
                 try
                 {
                     if (!String.IsNullOrEmpty(model.tepDinhKem))
                     {
                         var file = Request.Files[0];
                         model.tepDinhKem = file.FileName;
                         db.SaveChanges();
                         Upload(file, model.getFolder());
                     }
                     scope.Complete();
                     return(RedirectToAction("Index", new { parent = model.idTaiNguyen }));
                 }
                 catch (Exception e)
                 {
                     ModelState.AddModelError("tepDinhKem", e.Message);
                 }
             }
         }
     }
     return(View(model));
 }
Ejemplo n.º 19
0
        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 static int themQuanLyThuViec(string MaThuViec, string HoVaTen, DateTime ThoiGianBatDau, int?DonVi_id, int?ViTriCongTac_id)
        {
            using (var db = new HRMDBEntities())
            {
                var tv = new nvQLThuViec
                {
                    maThuViec         = MaThuViec,
                    HoVaTen           = HoVaTen,
                    ThoiGianBatDau    = ThoiGianBatDau,
                    DonVi_id          = DonVi_id,
                    ChucDanhChucVu_id = ViTriCongTac_id
                                        //ThoiGianKetThuc = ThoiGianBatDau.AddDays(Convert.ToDouble(thuviec)),
                };

                db.nvQLThuViec.Add(tv);
                db.SaveChanges();
                return(tv.id);
            }
        }
Ejemplo n.º 21
0
        private int themchungchi(int nv_id, int loaichungchi_id, string capdo, string noicap, DateTime ngaycap, string ghichu, int hotro)
        {
            using (var db = new HRMDBEntities())
            {
                var tv = new ChungChi
                {
                    NV_id           = nv_id,
                    LoaiChungChi_id = loaichungchi_id,
                    Capdo           = capdo,
                    NoiCap          = noicap,
                    NgayCap         = ngaycap,
                    GhiChu          = ghichu,
                    HoTro           = hotro,
                    SauKhiVeTruong  = true
                };

                db.ChungChi.Add(tv);
                db.SaveChanges();
                return(tv.id);
            }
        }
Ejemplo n.º 22
0
        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);
            }
        }
Ejemplo n.º 23
0
        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");
        }