Exemplo n.º 1
0
        public JsonResult Add_Edit(string id, string tenlkh, string mota)
        {
            var lkh = new LoaiKhoaHoc();

            if (id != null)
            {
                var rId = int.Parse(id);
                lkh = db.LoaiKhoaHocs.Single(z => z.ID == rId);
            }
            lkh.TenLoaiKhoaHoc = tenlkh;
            lkh.MoTa           = mota;
            lkh.MetaTitle      = MetaTitle(tenlkh);
            try
            {
                if (id == null)
                {
                    db.LoaiKhoaHocs.Add(lkh);
                }
                db.SaveChanges();
                return(Json(new { data = true }));
            }
            catch
            {
                return(Json(new { data = false }));
            }
        }
Exemplo n.º 2
0
        public JsonResult Add_Edit()
        {
            var inputCount = Request.Form.Count;
            var rID        = Request.Form["id"];
            var tt         = new TinTuc();

            if (rID != "-1")
            {
                var rId = int.Parse(rID);
                tt = db.TinTucs.Single(z => z.ID == rId);
            }
            tt.TieuDe    = Request.Form["tieude"];
            tt.TomTat    = Request.Form["tomtat"];
            tt.TrangThai = Request.Form["trangthai"] == "true" ? true : false;
            var noidungRaw = Request.Form["noidung"];
            var noidung    = HttpUtility.UrlDecode(noidungRaw);

            tt.NoiDung   = noidung;
            tt.MetaTitle = MetaTitle(tt.TieuDe);
            try
            {
                if (rID == "-1")
                {
                    db.TinTucs.Add(tt);
                }
                db.SaveChanges();
                return(Json(new { data = true }));
            }
            catch
            {
                return(Json(new { data = false }));
            }
        }
Exemplo n.º 3
0
        public JsonResult Add_Edit(string id, string hoten, string ngaysinh, string sdt, string email, string diachi, string idtaikhoan)
        {
            var hv = new HocVien();

            if (id != null)
            {
                var rId = int.Parse(id);
                hv = db.HocViens.Single(z => z.ID == rId);
            }
            hv.HoTen    = hoten;
            hv.NgaySinh = ngaysinh.Replace('-', '/');
            hv.SDT      = sdt;
            hv.Email    = email;
            hv.DiaChi   = diachi;
            if (id == null)// Just Add Info
            {
                var idTK     = int.Parse(idtaikhoan);
                var lhv      = db.TaiKhoans.Where(z => z.IDChucVu == 3);
                var taikhoan = lhv.SingleOrDefault(z => z.ID == idTK);
                if (taikhoan == null) // Not Create TK
                {
                    return(Json(new { data = false }));
                }
                if (taikhoan != null)
                {
                    var hocvien = db.HocViens.SingleOrDefault(z => z.IDTaiKhoan == taikhoan.ID);
                    if (hocvien != null)
                    {    // Already have infomation connect to this account
                        return(Json(new { data = false }));
                    }
                    else
                    {
                        hv.IDTaiKhoan = idTK; // Have account but not have infomation
                    }
                }
            }
            try
            {
                if (id == null)
                {
                    db.HocViens.Add(hv);
                }
                db.SaveChanges();
                return(Json(new { data = true }));
            }
            catch
            {
                return(Json(new { data = false }));
            }
        }
Exemplo n.º 4
0
        public JsonResult SwitchesControl(int id)
        {
            // Check Exists
            var tk = db.TaiKhoans.Single(z => z.ID == id);

            if (tk != null)
            {
                tk.TrangThai = !tk.TrangThai;
            }
            try
            {
                db.SaveChanges();
                return(Json(new { data = true, status = tk.TrangThai, name = tk.TenDangNhap }, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(new { data = false }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 5
0
        public ActionResult Register(FormCollection fc)
        {
            var hoten    = fc["hoTen"].ToString();
            var gioitinh = fc["gioiTinh"].ToString();
            var ngay     = fc["day"].ToString();
            var thang    = fc["month"].ToString();
            var nam      = fc["year"].ToString();
            var ngaysinh = ngay + "/" + thang + "/" + nam;

            // Validate TenDangNhap
            var      tendangnhap = fc["tendangnhap"].ToString();
            TaiKhoan taikhoan    = db.TaiKhoans.SingleOrDefault(z => z.TenDangNhap == tendangnhap);

            if (taikhoan != null)
            {
                ModelState.AddModelError("", "Tên tài khoản đã tồn tại");
                return(View("Register"));
            }
            var email   = fc["email"].ToString();
            var matkhau = fc["matkhau"].ToString();

            TaiKhoan tk = new TaiKhoan();

            tk.TenDangNhap = tendangnhap;
            tk.MatKhau     = GetHashString(matkhau);
            tk.NgayTao     = DateTime.Now.ToString("dd/MM/yyyy").ToString();
            tk.IDChucVu    = 3;
            tk.TrangThai   = true;
            db.TaiKhoans.Add(tk);
            db.SaveChanges();
            var     idtk = db.TaiKhoans.SingleOrDefault(z => z.TenDangNhap == tendangnhap).ID;
            HocVien hv   = new HocVien();

            hv.HoTen      = hoten;
            hv.NgaySinh   = ngaysinh;
            hv.Email      = email;
            hv.IDTaiKhoan = idtk;
            db.HocViens.Add(hv);
            db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 6
0
        public JsonResult ProcessStatus(string id)
        {
            var rID = int.Parse(id);
            var kh  = db.KhoaHocs.Single(z => z.ID == rID);

            if (kh != null)
            {
                kh.TrangThai = !kh.TrangThai;
                try
                {
                    db.SaveChanges();
                    return(Json(new { data = true, status = kh.TrangThai }));
                }
                catch
                {
                    return(Json(new { data = false, status = kh.TrangThai }));
                }
            }
            return(Json(new { data = false, status = kh.TrangThai }));
        }
Exemplo n.º 7
0
        public JsonResult Delete(string id)
        {
            int rId = int.Parse(id);
            var gy  = db.Gopies.Single(z => z.ID == rId);

            if (gy != null)
            {
                db.Gopies.Remove(gy);
                try
                {
                    db.SaveChanges();
                    return(Json(new { data = true }));
                }
                catch
                {
                    return(Json(new { data = false }));
                }
            }
            return(Json(new { data = false }));
        }
Exemplo n.º 8
0
        public ActionResult SuaThongTin(FormCollection fc, HttpPostedFileBase file)
        {
            int       idtk = int.Parse(fc["idtk"]);
            GiangVien gv   = db.GiangViens.SingleOrDefault(z => z.IDTaiKhoan == idtk);

            if (file != null)
            {
                gv.Anh = file.FileName;
                var path = Path.Combine(Server.MapPath("../../HinhAnh"), file.FileName);
                file.SaveAs(path);
            }
            if (gv != null)
            {
                gv.HoTen_GV = fc["hotengv"];
                gv.NgaySinh = fc["ngaysinh"];
                gv.SDT      = fc["sdt"];
                gv.Email    = fc["email"];
                gv.DiaChi   = fc["diachi"];
                gv.MoTa     = fc["mota1"];

                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 9
0
        public JsonResult Add_Edit()
        {
            var fileCount  = Request.Files.Count;
            var count_form = Request.Form.Count;
            var rID        = Request.Form["id"];
            var gv         = new GiangVien();

            if (rID != "-1")
            {
                var rId = int.Parse(rID);
                gv = db.GiangViens.Single(z => z.ID == rId);
            }
            gv.HoTen_GV   = Request.Form["hotengv"];
            gv.NgaySinh   = DateFormat(Request.Form["ngaysinh"]);
            gv.SDT        = Request.Form["sdt"];
            gv.Email      = Request.Form["email"];
            gv.DiaChi     = Request.Form["diachi"];
            gv.SoGioGiang = int.Parse(Request.Form["sogiogiang"]);
            gv.Luong      = int.Parse(Request.Form["luong"]);

            gv.IDTaiKhoan = int.Parse(Request.Form["idtaikhoan"]);

            var motaRaw = Request.Form["mota"];
            var mota    = HttpUtility.UrlDecode(motaRaw);

            gv.MoTa = mota;
            if (rID == "-1")// Just Add Info
            {
                var idTK     = int.Parse(Request.Form["idtaikhoan"]);
                var lgv      = db.TaiKhoans.Where(z => z.IDChucVu == 2);
                var taikhoan = lgv.SingleOrDefault(z => z.ID == idTK);
                if (taikhoan == null) // Not Create TK
                {
                    return(Json(new { data = false }));
                }
                if (taikhoan != null)
                {
                    var giangvien = db.GiangViens.SingleOrDefault(z => z.IDTaiKhoan == taikhoan.ID);
                    if (giangvien != null)
                    {    // Already have infomation connect to this account
                        return(Json(new { data = false }));
                    }
                    else
                    {
                        gv.IDTaiKhoan = idTK; // Have account but not have infomation
                    }
                }
            }
            if (fileCount == 1)// Have data file image in [input file]
            {
                var fileAnh = Request.Files["anh"];
                var path    = Path.Combine(Server.MapPath("~/HinhAnh"), fileAnh.FileName);
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                else
                {
                    fileAnh.SaveAs(path);
                    gv.Anh = fileAnh.FileName;
                }
            }
            try
            {
                if (rID == "-1")
                {
                    db.GiangViens.Add(gv);
                }
                db.SaveChanges();
                return(Json(new { data = true }));
            }
            catch
            {
                return(Json(new { data = false }));
            }
        }