示例#1
0
        public ActionResult Create(Model.EF.Student student)
        {
            var session = (AdminLogin)Session[CommonConstants.USER_SESSION];

            if (session.id_permission != 1)
            {
                return(View("Error"));
            }
            ViewBag.AdminName = session.name;
            if (ModelState.IsValid)
            {
                var dao = new StudentDao();
                if (!string.IsNullOrEmpty(student.password) && dao.IsUserNameExist(student.username))
                {
                    ModelState.AddModelError("", "Tên đăng nhập đã tồn tại.");
                }
                else
                {
                    if (!string.IsNullOrEmpty(student.password))
                    {
                        var encryptedMd5Pas = Encryptor.MD5Hash(student.password);
                        student.password = encryptedMd5Pas;
                    }
                    int id = dao.Insert(student);
                    if (id > 0)
                    {
                        //để thông báo thêm thành công
                        SetNotice("Hệ thống đã thêm thành công.", "success");
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm sinh viên không thành công.");
                    }
                }
            }
            SetViewBag();
            return(View());
        }
示例#2
0
        public ActionResult Edit(Model.EF.Student tmp)
        {
            var session = (AdminLogin)Session[CommonConstants.USER_SESSION];

            if (session.id_permission != 1)
            {
                return(View("Error"));
            }
            ViewBag.AdminName = session.name;

            var dao = new StudentDao();

            if (!dao.IsUserNameIDExist(tmp.username, tmp.id_student))
            {
                ModelState.AddModelError("", "Tên đăng nhập đã tồn tại.");
            }
            else
            {
                if (!string.IsNullOrEmpty(tmp.password))
                {
                    var encryptedMd5Pas = Encryptor.MD5Hash(tmp.password);
                    tmp.password = encryptedMd5Pas;
                }

                var id = dao.Update(tmp);
                if (id)
                {
                    SetNotice("Hệ thống đã sửa thành công " + tmp.student_name + ".", "success");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhật tài khoản không thành công.");
                }
            }
            SetViewBag(tmp.id_student);
            return(View());
        }