Exemplo n.º 1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            NganHangNKH nganHangNKH = await db.NganHangNKHs.FindAsync(id);

            db.NganHangNKHs.Remove(nganHangNKH);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = "MaNKH,STKNH,MaNH,ChiNhanhNH,GhiChu")] NganHangNKH nganHangNKH, int?manhakhoahoc)
        {
            if (ModelState.IsValid)
            {
                db.Entry(nganHangNKH).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Edit", "AdminNhaKhoaHoc", new { id = manhakhoahoc }));
            }
            ViewBag.MaNH  = new SelectList(db.NganHangs, "MaNH", "TenNH", nganHangNKH.MaNH);
            ViewBag.MaNKH = new SelectList(db.NhaKhoaHocs, "MaNKH", "MaNKHHoSo", nganHangNKH.MaNKH);
            return(View(nganHangNKH));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "MaNKH,STKNH,MaNH,ChiNhanhNH,GhiChu")] NganHangNKH nganHangNKH, int?manhakhoahoc)
        {
            if (ModelState.IsValid)
            {
                db.NganHangNKHs.Add(nganHangNKH);
                await db.SaveChangesAsync();

                return(RedirectToAction("Edit", "AdminNhaKhoaHoc", new { id = manhakhoahoc }));
            }

            ViewBag.MaNH         = new SelectList(db.NganHangs, "MaNH", "TenNH");
            ViewBag.manhakhoahoc = manhakhoahoc;
            return(View());
        }
        // GET: AdminNganHangNKHs/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NganHangNKH nganHangNKH = await db.NganHangNKHs.FindAsync(id);

            if (nganHangNKH == null)
            {
                return(HttpNotFound());
            }
            return(View(nganHangNKH));
        }
Exemplo n.º 5
0
        // GET: AdminNganHangNKHs/Edit/5
        public async Task <ActionResult> Edit(int?id, int?manhakhoahoc)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NganHangNKH nganHangNKH = await db.NganHangNKHs.Where(p => p.MaNH == id && p.MaNKH == manhakhoahoc).FirstOrDefaultAsync();

            if (nganHangNKH == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaNH         = new SelectList(db.NganHangs, "MaNH", "TenNH");
            ViewBag.manhakhoahoc = manhakhoahoc;
            return(View(nganHangNKH));
        }
Exemplo n.º 6
0
        // GET: AdminNganHangNKHs/Delete/5
        public async Task <ActionResult> Delete(int?id, int?manhakhoahoc)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NganHangNKH nganHangNKH = await db.NganHangNKHs.Where(p => p.MaNH == id && p.MaNKH == manhakhoahoc).FirstOrDefaultAsync();

            if (nganHangNKH == null)
            {
                return(HttpNotFound());
            }
            db.NganHangNKHs.Remove(nganHangNKH);
            await db.SaveChangesAsync();

            return(RedirectToAction("Edit", "AdminNhaKhoaHoc", new { id = manhakhoahoc }));
        }
        public async Task <ActionResult> Edit(HttpPostedFileBase fileUpload, List <int> DSLinhVucNC, List <int> DSChuyenMonGD, [Bind(Include = "MaNKH,MaNKHHoSo,HoNKH,TenNKH,GioiTinhNKH,NgaySinh,DiaChiLienHe,DienThoai,EmailLienHe,MaHocHam,MaHocVi,MaCNDaoTao,MaDonViQL,AnhDaiDien,MaNgachVienChuc")] NhaKhoaHoc nhaKhoaHoc, [Bind(Include = "MaNKH,STKNH,MaNH,ChiNhanhNH,GhiChu")] NganHangNKH nganHangNKH)
        {
            if (ModelState.IsValid)
            {
                // upload image
                var nhakh = db.NhaKhoaHocs.Where(p => p.MaNKH == nhaKhoaHoc.MaNKH).Include(p => p.LinhVucs).FirstOrDefault();

                if (repo.HasFile(fileUpload))
                {
                    string mimeType   = fileUpload.ContentType;
                    Stream fileStream = fileUpload.InputStream;
                    string fileName   = Path.GetFileName(fileUpload.FileName);
                    int    fileLength = fileUpload.ContentLength;
                    byte[] fileData   = new byte[fileLength];

                    fileStream.Read(fileData, 0, fileLength);
                    nhaKhoaHoc.AnhCaNhan = fileData;
                }

                db.NhaKhoaHocs.AddOrUpdate(nhaKhoaHoc);


                if (DSLinhVucNC != null)
                {
                    var deletedlinhvuc = nhakh.LinhVucs.Where(p => !DSLinhVucNC.Contains(p.MaLinhVuc)).ToList();
                    var addedlinhvuc   = DSLinhVucNC.Except(nhakh.LinhVucs.Select(p => p.MaLinhVuc)).ToList();
                    var addlinhvuc     = db.LinhVucs.Where(p => addedlinhvuc.Contains(p.MaLinhVuc)).ToList();

                    foreach (var x in deletedlinhvuc)
                    {
                        nhakh.LinhVucs.Remove(x);
                    }

                    foreach (var x in addlinhvuc)
                    {
                        nhakh.LinhVucs.Add(x);
                    }
                }
                else
                {
                    foreach (var x in nhakh.LinhVucs)
                    {
                        nhakh.LinhVucs.Remove(x);
                    }
                }

                /*
                 * if (DSTrinhDoNN != null) {
                 *  var deletednn = nhakh.NgoaiNguNKHs.Where(p => !DSTrinhDoNN.Contains(p.MaTrinhDoNN)).ToList();
                 *  var addednn = DSTrinhDoNN.Except(nhakh.NgoaiNguNKHs.Select(p => p.MaTrinhDoNN)).ToList();
                 *  var addnn = db.TrinhDoNgoaiNgus.Where(p => addednn.Contains(p.MaTrinhDoNN)).ToList();
                 *  foreach (var x in deletednn)
                 *  {
                 *      nhakh.NgoaiNguNKHs.Remove(x);
                 *  }
                 *  foreach (var x in addnn)
                 *  {
                 *      var newnn = new NgoaiNguNKH
                 *      {
                 *          MaNKH = nhakh.MaNKH,
                 *          MaTrinhDoNN = x.MaTrinhDoNN,
                 *
                 *      };
                 *      nhakh.NgoaiNguNKHs.Add(newnn);
                 *  }
                 * }
                 * else
                 * {
                 *  foreach(var x in nhakh.NgoaiNguNKHs)
                 *  {
                 *      nhakh.NgoaiNguNKHs.Remove(x);
                 *  }
                 * }      */


                if (DSChuyenMonGD != null)
                {
                    db.ChuyenMonNKHs.Where(p => p.MaNKH == nhaKhoaHoc.MaNKH).ForEach(x => db.ChuyenMonNKHs.Remove(x));
                    foreach (var item in DSChuyenMonGD)
                    {
                        ChuyenMonNKH chuyenmonNKH = new ChuyenMonNKH
                        {
                            MaNKH       = nhaKhoaHoc.MaNKH,
                            MaChuyenMon = item,
                            NgayCapNhat = DateTime.Now
                        };
                        db.ChuyenMonNKHs.Add(chuyenmonNKH);
                        db.SaveChanges();
                    }
                }

                if (nganHangNKH != null)
                {
                    db.NganHangNKHs.AddOrUpdate(nganHangNKH);
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }


            ViewBag.MaCNDaoTao      = new SelectList(db.ChuyenNganhs, "MaChuyenNganh", "TenChuyenNganh", nhaKhoaHoc.MaCNDaoTao);
            ViewBag.MaDonViQL       = new SelectList(db.DonViQLs, "MaDonVi", "TenDonVI", nhaKhoaHoc.MaDonViQL);
            ViewBag.MaHocHam        = new SelectList(db.HocHams, "MaHocHam", "TenHocHam", nhaKhoaHoc.MaHocHam);
            ViewBag.MaHocVi         = new SelectList(db.HocVis, "MaHocVi", "TenHocVi", nhaKhoaHoc.MaHocVi);
            ViewBag.MaNgachVienChuc = new SelectList(db.NgachVienChucs, "MaNgach", "TenNgach", nhaKhoaHoc.MaNgachVienChuc);
            NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHoc);

            return(View(nkh));
        }