public ActionResult Create()
        {
            var db = new TeachingScheduleEntities();

            ViewBag.MaBoMons = db.BoMons.Where(q => q.Active != false).CreateSelectList(q => q.MaBoMon, q => q.TenBoMon);
            return(View(new GV()));
        }
        public ActionResult Edit(int?id)
        {
            var db  = new TeachingScheduleEntities();
            var obj = id > 0 ? db.MonHocs.Find(id) : new MonHoc();

            ViewBag.BoMons = db.BoMons.ToList().Where(q => q.Active != false).CreateSelectList(q => q.MaBoMon, q => q.TenBoMon, obj.MaBoMon);
            return(View(obj));
        }
        public ActionResult Detail(int id, int?tab)
        {
            ViewBag.tab = tab;
            var db = new TeachingScheduleEntities();

            ViewBag.MaBoMons = db.BoMons.Where(q => q.Active != false).CreateSelectList(q => q.MaBoMon, q => q.TenBoMon);
            return(View(db.GVs.FirstOrDefault(q => q.MaGV == id)));
        }
        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()));
        }
        public ActionResult Edit(int?id)
        {
            var db = new TeachingScheduleEntities();
            var ob = db.GVs.FirstOrDefault(q => q.MaGV == (id ?? 0));

            if (ob == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.MaBoMons = db.BoMons.Where(q => q.Active != false).CreateSelectList(q => q.MaBoMon, q => q.TenBoMon, ob.MaBoMon);
            return(View(ob));
        }
示例#6
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"));
        }