Exemplo n.º 1
0
        // GET: UserManager
        public ActionResult Index(int?page)
        {
            // Show message
            if (Session["mes"] != null)
            {
                ViewBag.message = Session["mes"];
                Session.Remove("mes");
            }
            if (Session["mes_er"] != null)
            {
                ViewBag.message_er = Session["mes_er"];
                Session.Remove("mes_er");
            }

            ViewBag.Active = "manager";
            CustomPrincipal prin     = (CustomPrincipal)User;
            IPagedList      ListUser = null;

            if (prin.ROLE.Equals(ConstanAppkey.ADMIN()))
            {
                ListUser = userModels.GetItems(page ?? 1, ConstanAppkey.PAGESIZE());
            }
            else if (prin.ROLE.Equals(ConstanAppkey.MOD()))
            {
                ListUser = userModels.GetItemsMod(page ?? 1, ConstanAppkey.PAGESIZE(), prin);
            }
            return(View(ListUser));
        }
 protected override bool AuthorizeCore(HttpContextBase httpContext)
 {
     if (CurrentUser == null)
     {
         return(false);
     }
     if (Role == null || Role == "")
     {
         return((CurrentUser == null) ? false : true);
     }
     else
     {
         return((CurrentUser.IsInRole(Role) || CurrentUser.ROLE.Equals(ConstanAppkey.ADMIN())) ? true : false);
     }
 }
Exemplo n.º 3
0
        public ActionResult Add(POST Post, FormCollection form, HttpPostedFileBase PICTURE)
        {
            CustomPrincipal prin = (CustomPrincipal)User;

            if (ModelState.IsValid)
            {
                //upload file
                if (PICTURE != null && PICTURE.ContentLength > 0)
                {
                    var       path      = Server.MapPath("~/Assets/Upload/Post/");
                    ImgUpload imgUpload = new ImgUpload();
                    Post.PICTURE = imgUpload.Upload(PICTURE, path);
                }
                if (prin.ROLE.Equals(ConstanAppkey.ADMIN()))
                {
                    if (this.Request.Form["ACTIVE"] != null)
                    {
                        Post.ACTIVE = true;
                    }
                    else
                    {
                        Post.ACTIVE = false;
                    }
                }
                else
                {
                    Post.ACTIVE = false;
                }
                Post.ID_USER = prin.ID;
                int idPosst = postsModels.AddItem(Post);
                if (idPosst > 0)
                {
                    Session["mes"] = "Thêm thành công";
                }
                else
                {
                    var       dataFile  = Server.MapPath("~/Assets/Upload/Post/" + Post.PICTURE);
                    ImgUpload imgUpload = new ImgUpload();
                    imgUpload.Delete(dataFile);
                    Session["mes_er"] = "Thêm thất bại";
                }
                return(RedirectToAction("Index", "PostManager"));
            }

            ViewBag.ListCategories = categoriesModels.GetAllItem();
            return(View(Post));
        }
Exemplo n.º 4
0
        public bool checkUserAdd(USER userCheck)
        {
            ROLE Role = roleModels.GetItem(userCheck.ID_ROLE);

            if (prin.ROLE.Equals(ConstanAppkey.ADMIN()))
            {
                if (!Role.NAME.Equals(ConstanAppkey.ADMIN()))
                {
                    return(true);
                }
            }
            else if (prin.ROLE.Equals(ConstanAppkey.MOD()))
            {
                if (Role.NAME.Equals(ConstanAppkey.USER()))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        public bool checkPostDelete(POST postCheck)
        {
            ROLE Role = roleModels.GetItem(postCheck.USER.ID_ROLE);

            if (postCheck.USER.ID == prin.ID)
            {
                return(true);
            }
            if (prin.ROLE.Equals(ConstanAppkey.ADMIN()))
            {
                return(true);
            }
            else if (prin.ROLE.Equals(ConstanAppkey.MOD()))
            {
                if (Role.NAME.Equals(ConstanAppkey.USER()))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public ActionResult Edit(int id, USER UserE, FormCollection form, HttpPostedFileBase Picture)
        {
            CustomPrincipal prin = (CustomPrincipal)User;

            if (userModels.CheckEmailEdit(UserE.EMAIL, id))
            {
                if (roleModels.GetItem(UserE.ID_ROLE).NAME.Equals(ConstanAppkey.ADMIN()))
                {
                    if (!(id == prin.ID && prin.ROLE.Equals(ConstanAppkey.ADMIN())))
                    {
                        ViewBag.ListRole = roleModels.GetAllItems();
                        return(View(UserE));
                    }
                }
                if (prin.ROLE.Equals(ConstanAppkey.ADMIN()) && id == prin.ID)
                {
                    UserE.ID_ROLE = roleModels.GetItemName(ConstanAppkey.ADMIN()).ID;
                }
                if (this.Request.Form["ACTIVE"] != null)
                {
                    UserE.ACTIVE = true;
                }
                else
                {
                    UserE.ACTIVE = false;
                }
                if (ModelState.IsValid)
                {
                    USER user1 = userModels.GetItem(id);
                    //upload file
                    string picture_new = "";
                    string picture_old = "";
                    if (Picture != null && Picture.ContentLength > 0)
                    {
                        // create new file
                        ImgUpload imgUpload = new ImgUpload();
                        var       path      = Server.MapPath("~/Assets/Upload/User");
                        UserE.PICTURE = imgUpload.Upload(Picture, path);
                        picture_new   = UserE.PICTURE;
                        picture_old   = user1.PICTURE;
                    }
                    else
                    {
                        UserE.PICTURE = user1.PICTURE;
                    }
                    if (userModels.EditItem(id, UserE) > 0)
                    {
                        if (!picture_old.Equals(""))
                        {
                            // delete file old
                            var       dataFile  = Server.MapPath("~/Assets/Upload/User/" + picture_old);
                            ImgUpload imgUpload = new ImgUpload();
                            imgUpload.Delete(dataFile);
                        }
                        Session["mes"] = "Sửa thành công";
                    }
                    else
                    {
                        if (!picture_new.Equals(""))
                        {
                            // delete file old
                            var       dataFile  = Server.MapPath("~/Assets/Upload/User/" + picture_new);
                            ImgUpload imgUpload = new ImgUpload();
                            imgUpload.Delete(dataFile);
                        }
                        Session["mes_er"] = "Sửa thất bại";
                    }
                    return(RedirectToAction("Index", "UserManager"));
                }
            }
            else
            {
                ViewBag.message_er = "Sửa thất bại! Email đã tồn tại";
            }
            ViewBag.ListRole = roleModels.GetAllItems();
            return(View(UserE));
        }
Exemplo n.º 7
0
        public ActionResult Edit(int id, POST Post, FormCollection form, HttpPostedFileBase PICTURE)
        {
            CustomPrincipal prin = (CustomPrincipal)User;

            if (ModelState.IsValid)
            {
                POST   PostEdit    = postsModels.GetItem(id);
                string picture_old = "";
                string picture_new = "";
                //upload file
                if (PICTURE != null && PICTURE.ContentLength > 0)
                {
                    var       path      = Server.MapPath("~/Assets/Upload/Post/");
                    ImgUpload imgUpload = new ImgUpload();
                    Post.PICTURE = imgUpload.Upload(PICTURE, path);
                    picture_new  = Post.PICTURE;
                    picture_old  = PostEdit.PICTURE;
                }
                else
                {
                    Post.PICTURE = PostEdit.PICTURE;
                }
                if (this.Request.Form["ACTIVE"] != null)
                {
                    Post.ACTIVE = true;
                }
                else
                {
                    if (prin.ROLE.Equals(ConstanAppkey.ADMIN()) || prin.ROLE.Equals(ConstanAppkey.MOD()))
                    {
                        Post.ACTIVE = false;
                    }
                    else
                    {
                        Post.ACTIVE = PostEdit.ACTIVE;
                    }
                }
                int idPosst = postsModels.EditItem(id, Post);
                if (idPosst > 0)
                {
                    if (!picture_old.Equals(""))
                    {
                        var       dataFile  = Server.MapPath("~/Assets/Upload/Post/" + picture_old);
                        ImgUpload imgUpload = new ImgUpload();
                        imgUpload.Delete(dataFile);
                    }
                    Session["mes"] = "Sửa thành công";
                }
                else
                {
                    if (!picture_new.Equals(""))
                    {
                        var       dataFile  = Server.MapPath("~/Assets/Upload/Post/" + picture_new);
                        ImgUpload imgUpload = new ImgUpload();
                        imgUpload.Delete(dataFile);
                    }
                    Session["mes_er"] = "Sửa thất bại";
                }
                return(RedirectToAction("Index", "PostManager"));
            }
            ViewBag.ListCategories = categoriesModels.GetAllItem();
            return(View(Post));
        }