public JsonResult delete()
        {
            try
            {
                int id = -1;
                int.TryParse(Request["id"], out id);
                if (id > 0)
                {
                    var obj = DataProvider.Entities.VaiTroes.FirstOrDefault(x => x.Id == id);
                    if (obj.NguoiDungs.Count > 0 || obj.PhanQuyens.Count > 0)
                    {
                        return(Json(new JsonPostBack("Không thể xóa vai trò này, vì sẽ ảnh hưởng đến dữ liệu khác", false), JsonRequestBehavior.AllowGet));
                    }
                    DataProvider.Entities.VaiTroes.Remove(obj);
                    QuanTri.SaveLog("Xóa vai trò ", "Quản lý vai trò", (int)CommonAdmin.ConstantCommon.Action.Edit);
                    DataProvider.Entities.SaveChanges();

                    return(Json(new JsonPostBack("Xóa thành công", true), JsonRequestBehavior.AllowGet));
                }
                return(Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public ActionResult CheckLogin(string username, string pwd, string remember)
        {
            //Lưu trang hiện tại để khi đăng nhập thành công có thể đến
            //string currenturl = AdminBaseController.strControlerCurrent;
            //ViewBag.Url = currenturl;
            NguoiDung obj = getObjByUser(username);

            if (obj.Id > 0)
            {
                if (obj.MatKhau.Equals(QuanTri.ToMD5(pwd)))
                { //Đăng nhập thành công
                    Session.Add(ConstantData.USER_SESSION, obj);
                    if (Convert.ToBoolean(remember))
                    {
                        HttpCookie cookie = new HttpCookie(ConstantData.USER_COOKIES);
                        cookie[ConstantData.USERNAME_COOKIES] = obj.TenDangNhap;
                        cookie[ConstantData.PASSWORD_COOKIES] = pwd;
                        cookie.Expires = DateTime.Now.AddDays(100);
                        Response.Cookies.Add(cookie);
                    }
                    //Lưu nhật kí hệ thống
                    QuanTri.SaveLog("Người dùng " + username + " đã đăng nhập", "Đăng nhập", (int)CommonAdmin.ConstantCommon.Action.Login);
                    return(Json(new { error = false, message = "Đăng nhập thành công" }));
                }
                return(Json(new { error = true, message = "Mật khẩu không chính xác" }));
            }
            return(Json(new { error = true, message = "Tài khoản không chính xác" }));
        }
        /// <summary>
        /// Xóa quền theo list chức năng Id
        /// </summary>
        /// <param name="id"> vai trò id</param>
        /// <param name="itemId"> list chức năng Id</param>
        /// <returns></returns>
        public JsonResult Delete(string id, string itemId)
        {
            int vaitroId = -1;

            string[] lstIdChucNang;
            if (!string.IsNullOrEmpty(itemId))
            {
                lstIdChucNang = itemId.Split('-');
            }
            else
            {
                return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
            }
            try
            {
                int.TryParse(id, out vaitroId);
                if (vaitroId > 0)
                {
                    foreach (var item in lstIdChucNang)
                    {
                        int       Idchucnang = int.Parse(item);
                        PhanQuyen obj        = DataProvider.Entities.PhanQuyens.Where(x => x.ChucNangId == Idchucnang && x.VaiTroId == vaitroId).First();
                        DataProvider.Entities.PhanQuyens.Remove(obj);
                    }
                    DataProvider.Entities.SaveChanges();
                    QuanTri.SaveLog("Cấp quyền và chức năng", "Phân quyền", (int)CommonAdmin.ConstantCommon.Action.Add);
                    return(Json(new JsonPostBack("Xóa thành công", true), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new JsonPostBack("Xóa thất bại", false), JsonRequestBehavior.AllowGet));
            }
            return(Json(new JsonPostBack("Xóa thất bại", false), JsonRequestBehavior.AllowGet));
        }
        public virtual JsonResult Edit(Menu model, HttpPostedFileBase file)
        {
            try
            {
                Menu obj = DataProvider.Entities.Menus.Find(model.Id);
                if (obj.Id > 0)
                {
                    if (model.ParentId == null || !model.ParentId.HasValue)
                    {
                        model.ParentId = 0;
                    }
                    if (model.SapXep == null || !model.SapXep.HasValue)
                    {
                        model.SapXep = 0;
                    }
                    obj.TenItem   = model.TenItem;
                    obj.MoTa      = model.MoTa;
                    obj.ParentId  = model.ParentId;
                    obj.SapXep    = model.SapXep;
                    obj.Link      = model.Link;
                    obj.HeadTitle = model.HeadTitle;
                    obj.ChuDeId   = model.ChuDeId;

                    if (file != null && file.ContentLength > 0)
                    {
                        obj.ImagePath = file.FileName;
                        //tải file về
                        file.SaveAs(Server.MapPath("~/Content/Images/Menu/" + obj.ImagePath));
                    }
                    DataProvider.Entities.SaveChanges();
                    QuanTri.SaveLog("Chỉnh sửa menu ", "Quản lý menu", (int)CommonAdmin.ConstantCommon.Action.Edit);
                    //return Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet);
                    return(Json(new JsonResponse
                    {
                        Message = ResponseMessage.SuccessUpdate,
                        Success = true
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
                    return(Json(new JsonResponse
                    {
                        Message = ResponseMessage.Error,
                        Success = false
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error + ". Chi tiết: " + ex.Message,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #5
0
        public ActionResult Logout()
        {
            //Session.Remove(ConstantData.USER_SESSION);
            QuanTri.SaveLog("Người dùng đăng xuất", "Đăng nhập", (int)CommonAdmin.ConstantCommon.Action.Logout);
            //AdminBaseController.strControlerCurrent = string.Empty;
            Session[ConstantData.USER_SESSION] = null;
            //Lưu nhật kí

            return(RedirectToAction("Index", "login"));
        }
Beispiel #6
0
 public ActionResult Add(KhachHang model)
 {
     if (ModelState.IsValid)
     {
         DataProvider.Entities.KhachHangs.Add(model);
         DataProvider.Entities.SaveChanges();
         QuanTri.SaveLog("Thêm mới khách hàng ", "Quản lý khách hàng", (int)CommonAdmin.ConstantCommon.Action.Add);
         return(RedirectToAction("Index", "KhachHang"));
     }
     else
     {
         PrepareDDLTinhThanh();
         PrepareDDLLoaiKH();
         return(View());
     }
 }
        /// <summary>
        /// Thêm mới các chức năng theo Id truyền vào
        /// </summary>
        /// <param name="id">vài trò id</param>
        /// <param name="itemId"> list chức năng id</param>
        /// <returns></returns>
        public JsonResult Add(string id, string itemId)
        {
            int  vaitroId = -1;
            bool xem      = Convert.ToBoolean(Request["xem"]);
            bool xoa      = Convert.ToBoolean(Request["xoa"]);
            bool sua      = Convert.ToBoolean(Request["sua"]);
            bool them     = Convert.ToBoolean(Request["them"]);
            bool baocao   = Convert.ToBoolean(Request["baocao"]);

            string[] lstIdChucNang;
            if (!string.IsNullOrEmpty(itemId))
            {
                lstIdChucNang = itemId.Split('-');
            }
            else
            {
                return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
            }
            try
            {
                int.TryParse(id, out vaitroId);
                if (vaitroId > 0)
                {
                    //Thêm mới quyền
                    foreach (var item in lstIdChucNang)
                    {
                        PhanQuyen obj = new PhanQuyen();
                        obj.ChucNangId = int.Parse(item);
                        obj.VaiTroId   = vaitroId;
                        obj.Xem        = xem;
                        obj.Sua        = sua;
                        obj.Xoa        = xoa;
                        obj.Them       = them;
                        obj.BaoCao     = baocao;
                        DataProvider.Entities.PhanQuyens.Add(obj);
                    }
                    DataProvider.Entities.SaveChanges();
                    QuanTri.SaveLog("Cấp quyền và chức năng", "Phân quyền", (int)CommonAdmin.ConstantCommon.Action.Add);
                    return(Json(new JsonPostBack("Xóa thành công", true), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
            }
            return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
        }
Beispiel #8
0
        public ActionResult Edit(KhachHang model)
        {
            if (ModelState.IsValid)
            {
                KhachHang obj = DataProvider.Entities.KhachHangs.Find(model.Id);
                if (obj != null)
                {
                    DataProvider.Entities.Entry(obj).CurrentValues.SetValues(model);

                    DataProvider.Entities.SaveChanges();
                    QuanTri.SaveLog("Thêm mới khách hàng ", "Quản lý khách hàng", (int)CommonAdmin.ConstantCommon.Action.Add);
                    return(RedirectToAction("Index", "KhachHang"));
                }
            }
            PrepareDDLTinhThanh();
            PrepareDDLLoaiKH();
            return(View());
        }
Beispiel #9
0
        public JsonResult Delete(int id)
        {
            try
            {
                if (id > 0)
                {
                    var obj = DataProvider.Entities.AnhSanPhams.FirstOrDefault(x => x.Id == id);

                    DataProvider.Entities.AnhSanPhams.Remove(obj);
                    QuanTri.SaveLog("Xóa ảnh ", "Quản lý ảnh", (int)CommonAdmin.ConstantCommon.Action.Delete);
                    DataProvider.Entities.SaveChanges();
                    //xóa ảnh trên server
                    var      path     = Server.MapPath("~/Content/Images/SanPham/AnhSP/" + obj.Avatar);
                    FileInfo fileInfo = new FileInfo(path);
                    if (fileInfo.Exists)
                    {
                        fileInfo.Delete();
                    }

                    return(Json(new JsonResponse
                    {
                        Message = ResponseMessage.SuccessDelete,
                        Success = true
                    }, JsonRequestBehavior.AllowGet));
                }
                //return Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //return Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult DeleteAll(string id)
        {
            int itemId = -1;

            try
            {
                int.TryParse(id, out itemId);
                if (itemId > 0)
                {
                    DeleteAllByVaiTroId(itemId);
                    QuanTri.SaveLog("Xóa quyền và chức năng", "Phân quyền", (int)CommonAdmin.ConstantCommon.Action.Delete);
                    return(Json(new JsonPostBack("Xóa thành công", true), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
            }
            return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
        }
        public JsonResult Add(Menu model, HttpPostedFileBase file)
        {
            try
            {
                if (model.ParentId == null || !model.ParentId.HasValue)
                {
                    model.ParentId = 0;
                }

                if (model.SapXep == null || !model.SapXep.HasValue)
                {
                    model.SapXep = 0;
                }

                if (file != null && file.ContentLength > 0)
                {
                    model.ImagePath = file.FileName;
                    //tải file về
                    file.SaveAs(Server.MapPath("~/Content/Images/Menu/" + model.ImagePath));
                }

                DataProvider.Entities.Menus.Add(model);
                DataProvider.Entities.SaveChanges();
                QuanTri.SaveLog("Thêm mới menu ", "Quản lý menu", (int)CommonAdmin.ConstantCommon.Action.Add);
                //return Json(new JsonPostBack("Thêm mới thành công", true), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.SuccessCreate,
                    Success = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult Delete(int id)
        {
            try
            {
                if (id > 0)
                {
                    var obj = DataProvider.Entities.Colors.FirstOrDefault(x => x.Id == id);

                    if (obj.SanPham_Color.Count > 0)
                    {
                        return(Json(new JsonPostBack("Không thể xóa màu này, vì sẽ ảnh hưởng đến dữ liệu khác", false), JsonRequestBehavior.AllowGet));
                    }
                    DataProvider.Entities.Colors.Remove(obj);
                    QuanTri.SaveLog("Xóa màu sắc ", "Quản lý màu sắc", (int)CommonAdmin.ConstantCommon.Action.Delete);
                    DataProvider.Entities.SaveChanges();

                    //return Json(new JsonPostBack("Xóa thành công", true), JsonRequestBehavior.AllowGet);
                    return(Json(new JsonResponse
                    {
                        Message = ResponseMessage.SuccessDelete,
                        Success = true
                    }, JsonRequestBehavior.AllowGet));
                }
                //return Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //return Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
        /// <summary>
        /// Thêm tất cả các chức năng
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        ///
        public JsonResult AddAll(string id)
        {
            int  vaitroId = -1;
            bool xem      = Convert.ToBoolean(Request["xem"]);
            bool xoa      = Convert.ToBoolean(Request["xoa"]);
            bool sua      = Convert.ToBoolean(Request["sua"]);
            bool them     = Convert.ToBoolean(Request["them"]);
            bool baocao   = Convert.ToBoolean(Request["baocao"]);

            try
            {
                int.TryParse(id, out vaitroId);
                if (vaitroId > 0)
                {
                    DeleteAllByVaiTroId(vaitroId);

                    var lstChucNang = DataProvider.Entities.ChucNangs.ToList();
                    foreach (var item in lstChucNang)
                    {
                        PhanQuyen obj = new PhanQuyen();
                        obj.ChucNangId = item.Id;
                        obj.VaiTroId   = vaitroId;
                        obj.Xem        = xem;
                        obj.Sua        = sua;
                        obj.Xoa        = xoa;
                        obj.Them       = them;
                        obj.BaoCao     = baocao;
                        DataProvider.Entities.PhanQuyens.Add(obj);
                    }
                    DataProvider.Entities.SaveChanges();
                    QuanTri.SaveLog("Cấp quyền và chức năng", "Phân quyền", (int)CommonAdmin.ConstantCommon.Action.Add);
                    return(Json(new JsonPostBack("Xóa thành công", true), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
            }
            return(Json(new JsonPostBack("Xóa thành công", false), JsonRequestBehavior.AllowGet));
        }
 public virtual JsonResult Edit(Color model)
 {
     try
     {
         Color obj = DataProvider.Entities.Colors.Find(model.Id);
         if (obj.Id > 0)
         {
             obj.ColorCode = model.ColorCode;
             obj.ColorName = model.ColorName;
             DataProvider.Entities.SaveChanges();
             QuanTri.SaveLog("Chỉnh sửa vai trò ", "Quản lý màu sắc", (int)CommonAdmin.ConstantCommon.Action.Edit);
             //return Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet);
             return(Json(new JsonResponse
             {
                 Message = ResponseMessage.SuccessUpdate,
                 Success = true
             }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
             return(Json(new JsonResponse
             {
                 Message = ResponseMessage.Error,
                 Success = false
             }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception)
     {
         //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
         return(Json(new JsonResponse
         {
             Message = ResponseMessage.Error,
             Success = false
         }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #15
0
        public JsonResult Delete(int id)
        {
            try
            {
                if (id > 0)
                {
                    var obj = DataProvider.Entities.Waists.FirstOrDefault(x => x.Id == id);


                    DataProvider.Entities.Waists.Remove(obj);
                    QuanTri.SaveLog("Xóa waist ", "Quản lý waist", (int)CommonAdmin.ConstantCommon.Action.Delete);
                    DataProvider.Entities.SaveChanges();

                    //return Json(new JsonPostBack("Xóa thành công", true), JsonRequestBehavior.AllowGet);
                    return(Json(new JsonResponse
                    {
                        Message = ResponseMessage.SuccessDelete,
                        Success = true
                    }, JsonRequestBehavior.AllowGet));
                }
                //return Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //return Json(new JsonPostBack("Có lỗi xảy ra", false), JsonRequestBehavior.AllowGet);
                return(Json(new JsonResponse
                {
                    Message = ResponseMessage.Error,
                    Success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
 public virtual JsonResult Edit(LoaiKhachHang model)
 {
     try
     {
         LoaiKhachHang obj = DataProvider.Entities.LoaiKhachHangs.Find(model.Id);
         if (obj != null)
         {
             obj.TenLoai = model.TenLoai;
             DataProvider.Entities.SaveChanges();
             QuanTri.SaveLog("Chỉnh sửa đường may ", "Quản lý đường may", (int)CommonAdmin.ConstantCommon.Action.Edit);
             //return Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet);
             return(Json(new JsonResponse
             {
                 Message = ResponseMessage.SuccessUpdate,
                 Success = true
             }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
             return(Json(new JsonResponse
             {
                 Message = ResponseMessage.Error,
                 Success = false
             }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception)
     {
         //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
         return(Json(new JsonResponse
         {
             Message = ResponseMessage.Error,
             Success = false
         }, JsonRequestBehavior.AllowGet));
     }
 }
 public JsonResult Add(Color model)
 {
     try
     {
         DataProvider.Entities.Colors.Add(model);
         DataProvider.Entities.SaveChanges();
         QuanTri.SaveLog("Thêm mới màu sắc ", "Quản lý màu sắc", (int)CommonAdmin.ConstantCommon.Action.Add);
         //return Json(new JsonPostBack("Thêm mới thành công", true), JsonRequestBehavior.AllowGet);
         return(Json(new JsonResponse
         {
             Message = ResponseMessage.SuccessCreate,
             Success = true
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         //return Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet);
         return(Json(new JsonResponse
         {
             Message = ResponseMessage.Error,
             Success = false
         }, JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult Add()
        {
            try
            {
                int    id     = int.Parse(Request["isInsert"]);
                string vaitro = Request["vaitro"];
                string mota   = Request["mota"];
                if (id < 0)                            //Add
                {
                    if (getObjByVaiTro(vaitro).Id > 0) //Nếu tài khoản đã tồn tại
                    {
                        return(Json(new JsonPostBack("Tên vai trò đã tồn tại. Vui lòng nhập tên tên vai trò khác", false), JsonRequestBehavior.AllowGet));
                    }

                    VaiTro obj = new VaiTro();
                    obj.TenVaiTro = vaitro;
                    obj.MoTa      = mota;
                    DataProvider.Entities.VaiTroes.Add(obj);
                    DataProvider.Entities.SaveChanges();
                    QuanTri.SaveLog("Thêm mới vai trò ", "Quản lý vai trò", (int)CommonAdmin.ConstantCommon.Action.Add);
                    return(Json(new JsonPostBack("Thêm mới thành công", true), JsonRequestBehavior.AllowGet));
                }
                else //Edit
                {
                    VaiTro obj = DataProvider.Entities.VaiTroes.Find(id);
                    if (obj.Id > 0)
                    {
                        //Nếu tên tên vai trò thay đổi
                        if (obj.TenVaiTro != vaitro)
                        {
                            //if tên vai trò đã tồn tại => Erorr
                            if (getObjByVaiTro(vaitro).Id > 0)
                            {
                                return(Json(new JsonPostBack("Tên vai trò đã tồn tại. Vui lòng nhập tên tên vai trò khác", false), JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                obj.TenVaiTro = vaitro;
                                obj.MoTa      = mota;
                                DataProvider.Entities.SaveChanges();
                                QuanTri.SaveLog("Chỉnh sửa vai trò ", "Quản lý vai trò", (int)CommonAdmin.ConstantCommon.Action.Edit);
                                return(Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet));
                            }
                        }
                        else //Tài khoản không đổi
                        {
                            obj.TenVaiTro = vaitro;
                            obj.MoTa      = mota;
                            DataProvider.Entities.SaveChanges();
                            QuanTri.SaveLog("Chỉnh sửa vai trò ", "Quản lý vai trò", (int)CommonAdmin.ConstantCommon.Action.Edit);
                            return(Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        return(Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #19
0
        /// <summary>
        /// Hàm thêm mới hoặc cập nhật chủ đề
        /// Author              Date            Comments
        /// DangBQ          27/09/19        Tạo mới
        /// </summary>
        /// <returns></returns>
        public JsonResult AddOrUpdate()
        {
            try
            {
                bool isInsert = true;
                // Lấy thông tin từ giao diện
                int id = -1;
                int.TryParse(Request["hId"], out id);
                string tenChuDe   = Request["tenChuDe"];
                string maCha      = Request["maCha"];
                string avatar     = Request["avatar"];
                int    chuDeChaId = 0;
                int.TryParse(maCha, out chuDeChaId);

                ChuDe objChuDe = null;

                if (id > 0)//Lấy thông tin chủ đề nếu là sửa
                {
                    //Lấy chủ đề sửa
                    objChuDe = DataProvider.Entities.ChuDes.Where(c => c.Id == id).First();
                }

                //Nếu chủ đề khác null
                if (objChuDe != null)
                {
                    isInsert = false;
                    //Kiểm tra trùng tên
                    if (kiemTraTrungTen(tenChuDe, objChuDe.TenChuDe))
                    {
                        return(Json(new JsonPostBack("Tên chủ đề đã tồn tại. Vui lòng nhập tên tên chủ đề khác", false), JsonRequestBehavior.AllowGet));
                    }
                }
                else//Nếu là thêm mới
                {
                    //Kiểm tra trùng tên
                    if (kiemTraTrungTen(tenChuDe, string.Empty))
                    {
                        return(Json(new JsonPostBack("Tên chủ đề đã tồn tại. Vui lòng nhập tên tên chủ đề khác", false), JsonRequestBehavior.AllowGet));
                    }
                    //Khởi tạo
                    objChuDe = new ChuDe();
                }

                //Gán thông tin vào đối tượng chủ đề
                objChuDe.TenChuDe = tenChuDe;
                objChuDe.MaCha    = chuDeChaId;

                var fileImg = Request.Files["fileImg"];
                //Nếu ảnh có chọn
                if (fileImg.ContentLength > 0)
                {
                    // Kiểm tra file Image đã tồn tại trên server hay chưa
                    string filePath = "~/Content/Admin/images/ChuDe/" + avatar;
                    string Path     = HttpContext.Server.MapPath(filePath);
                    if (!System.IO.File.Exists(Path))
                    {
                        fileImg.SaveAs(Server.MapPath("~/Content/Admin/images/ChuDe/" + fileImg.FileName));
                    }
                }
                else
                {
                    avatar = Request["avatar"];
                }

                objChuDe.Avatar = avatar;
                //Nếu là thêm mới
                if (isInsert)
                {
                    DataProvider.Entities.Entry(objChuDe).State = System.Data.Entity.EntityState.Added;
                    DataProvider.Entities.ChuDes.Add(objChuDe);
                    //Lưu sự thay đổi vào db
                    DataProvider.Entities.SaveChanges();

                    QuanTri.SaveLog("Thêm mới chủ đề", "Quản lý chủ đề", (int)CommonAdmin.ConstantCommon.Action.Add);
                    return(Json(new JsonPostBack("Thêm mới thành công", true), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //Lưu sự thay đổi vào db
                    DataProvider.Entities.SaveChanges();

                    QuanTri.SaveLog("Chỉnh sửa chủ đề", "Quản lý chủ đề", (int)CommonAdmin.ConstantCommon.Action.Edit);
                    return(Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý. Chi tiết: " + ex.Message, false), JsonRequestBehavior.AllowGet));
            }
        }