示例#1
0
        public ActionResult Import(int?IDNamHoc, HttpPostedFileBase excel, string LHDT, int sheet = 1)
        {
            if (Path.GetExtension(excel.FileName) != ".xlsx")
            {
                ViewBag.IDNamHocs = db.NamHocs.Where(q => q.Active != false).CreateSelectList(q => q.IDNamHoc, q => q.mNamHoc, IDNamHoc);
                ModelState.AddModelError("", "Vui lòng chọn tệp tin định dạng .xlsx");
                return(View());
            }
            var workbook = new ClosedXML.Excel.XLWorkbook(excel.InputStream);
            var ws       = workbook.Worksheet(sheet);
            var lst      = (from row in ws.Rows(2, ws.RowsUsed().Count())
                            select GetLopHP(IDNamHoc, row)).ToList();

            lst.ForEach(q =>
            {
                if (q != null)
                {
                    q.LHDT = LHDT;
                    _fillHeSo(q);
                    db.LopHPs.Add(q);
                }
            });
            db.SaveChanges();
            return(RedirectToAction("Index", new { IDNamHoc }));
        }
        public ActionResult Index(CT_DMG[] array, int?MaDMG)
        {
            foreach (var item in array)
            {
                if (item.IDCT_DMG > 0 && item.MaCV == null)
                {
                    db.Entry(item).State = EntityState.Deleted;
                }
                else if (item.IDCT_DMG == 0 && item.MaCV > 0)
                {
                    db.CT_DMG.Add(item);
                }
            }

            db.SaveChanges();

            var obj = db.DMGs.Find(MaDMG);

            obj.TongHeSo = db.CT_DMG.Where(q => q.MaDMG == obj.MaDMG).Sum(q => q.ChucVu.HeSo) ?? 0;
            if (obj.TongHeSo > 50)
            {
                obj.TongHeSo = 50;
            }
            obj.TongDMG = db.HocHams.Find(obj.MaHocHam).DMG *(100 - obj.TongHeSo) / 100;
            db.SaveChanges();
            return(RedirectToAction("Detail", "GV", new { id = obj.MaGV, tab = 3 }));
        }
        public ActionResult Edit(NCKH nCKH)
        {
            var files = Request.Files;

            if (files.Count == 1)
            {
                var file = files[0];
                if (file != null && file.ContentLength > 0)
                {
                    var name_file = $"{DateTime.Now.ToString("hhmmssddMMyyyy")}_{Path.GetFileName(file.FileName)}";
                    var path      = "/Content/Upload/" + name_file;
                    file.SaveAs(Server.MapPath(path));
                    nCKH.TaiLieu = path;
                }
            }

            if (nCKH.MaNCKH > 0)
            {
                db.Entry(nCKH).State = EntityState.Modified;
            }
            else
            {
                db.NCKHs.Add(nCKH);
            }
            db.SaveChanges();
            return(RedirectToAction("Detail", "GV", new { id = nCKH.MaGV, tab = 2 }));
        }
示例#4
0
 public ActionResult Edit(PCGD pCGD)
 {
     if (pCGD.MaPCGD > 0)
     {
         db.Entry(pCGD).State = EntityState.Modified;
     }
     else
     {
         db.PCGDs.Add(pCGD);
     }
     db.SaveChanges();
     return(RedirectToAction("Index", "LopHP", new { db.LopHPs.Find(pCGD.MaHP).IDNamHoc }));
 }
 public ActionResult Edit(NamHoc obj)
 {
     obj.KyHoc   = $"Kỳ {obj.KyHoc}";
     obj.NamHoc1 = $"Năm học {obj.NamHoc1}";
     if (obj.IDNamHoc == 0)
     {
         obj.Active    = true;
         obj.TrangThai = "INIT";
         db.NamHocs.Add(obj);
     }
     else
     {
         db.Entry(obj).State = EntityState.Modified;
     }
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#6
0
 public ActionResult Edit(DMG obj)
 {
     if (obj.MaDMG > 0)
     {
         db.Entry(obj).State = EntityState.Modified;
     }
     else
     {
         db.DMGs.Add(obj);
     }
     obj.TongHeSo = db.CT_DMG.Where(q => q.MaDMG == obj.MaDMG).Sum(q => q.ChucVu.HeSo) ?? 0;
     if (obj?.TongHeSo > 50)
     {
         obj.TongHeSo = 50;
     }
     obj.TongDMG = db.HocHams.Find(obj.MaHocHam).DMG ?? 0;
     db.SaveChanges();
     return(RedirectToAction("Detail", "GV", new { id = obj.MaGV, tab = 3 }));
 }
        public JsonResult Delete(int id)
        {
            var db = new TeachingScheduleEntities();

            if (db.GVs.FirstOrDefault(q => q.MaGV == id) is GV value)
            {
                value.Active = false;
            }
            return(Json(db.SaveChanges()));
        }
示例#8
0
        public ActionResult Edit(LichGD lichGD)
        {
            if (lichGD.NgayBD >= lichGD.NgayKT)
            {
                ModelState.AddModelError("", "Vui lòng nhập thời gian hợp lệ!");
                return(View(lichGD));
            }

            if (lichGD.MaLichGD > 0)
            {
                db.Entry(lichGD).State = EntityState.Modified;
            }
            else
            {
                db.LichGDs.Add(lichGD);
            }
            db.SaveChanges();
            return(RedirectToAction("Index", "LopHP", new { MaPCGD = lichGD.MaPCGD }));
        }
 public ActionResult Edit(DNDoiGio obj)
 {
     if (obj.MaDN > 0)
     {
         db.Entry(obj).State = EntityState.Modified;
     }
     else
     {
         obj.NgayTao = DateTime.Now;
         db.DNDoiGios.Add(obj);
     }
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#10
0
        public ActionResult Edit(ChucVu obj)
        {
            var db = new TeachingScheduleEntities();

            if (obj.MaCV == 0)
            {
                obj.Active = true;
                db.ChucVus.Add(obj);
            }
            else
            {
                db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(GV obj)
        {
            var db = new TeachingScheduleEntities();

            if (obj.MaGV == 0)
            {
                db.GVs.Add(obj);
            }
            else
            {
                db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
            }

            var files = Request.Files;

            if (files.Count == 1)
            {
                var file = files[0];
                if (file != null && file.ContentType.Contains("image") && file.ContentLength > 0)
                {
                    var name_file = $"{DateTime.Now.ToString("hhmmssddMMyyyy")}_{Path.GetFileName(file.FileName)}";
                    var path      = "/Content/Upload/img/" + name_file;
                    file.SaveAs(Server.MapPath(path));
                    obj.Avatar = path;
                }
            }

            if (db.SaveChanges() == 0)
            {
                ModelState.AddModelError("", "Thêm thất bại");
                return(View());
            }
            if (obj.MaGV == Account.MaGV)
            {
                return(RedirectToAction("Logout", "Login"));
            }
            return(RedirectToAction("Index"));
        }