Exemple #1
0
        public async Task <ActionResult> Manage(string name, string uname, int page = 1)
        {
            await UC.InitializeAsync(this);

            if (!(ViewBag.myPerms as BsonArray).Any(p => p["key"].AsString == "perm_superuser"))
            {
                return(View("AccessDenied"));
            }
            name = name.ToStringFarsi();
            var limit = 50;
            var skip  = limit * (page - 1);

            ViewBag.page          = page;
            ViewBag.plimit        = limit;
            ViewBag.RowIndexStart = (page * limit) - limit;
            ViewBag.name          = name;
            ViewBag.uname         = uname;
            string q = "{aggregate:'users',pipeline:[{$match:{$and:[{'status':{$ne:'حذف شده'}},";

            if (!string.IsNullOrWhiteSpace(name))
            {
                q += "{name:{$regex:'" + name + "'}},";
            }
            if (!string.IsNullOrWhiteSpace(uname))
            {
                q += "{'uname':'" + uname + "'},";
            }
            q = q.Trim(',') + "]}}{$sort : { '_id' : -1 }},{$skip:" + skip.ToString() + "},{$limit:" + limit.ToString() + "}]}";
            var model = await NoSql.Instance.RunCommandAsync <BsonDocument>(q);

            ViewBag.active_users = "active";
            return(View(model.GetValue("result")));
        }
Exemple #2
0
        public async Task <ActionResult> Edit(string id, string name, string email, string[] roles, string[] categories)
        {
            email = (email ?? "").ToLower();
            name  = name.ToStringFarsi();
            //if (string.IsNullOrWhiteSpace(name))
            //    TempData["MSG"] = "لطفا نام و نام خانوادگی را وارد کنید";

            if (string.IsNullOrWhiteSpace(email))
            {
                TempData["MSG"] = "لطفا پست الکترونیک را وارد کنید";
            }


            else
            {
                //string q = "{update:'users',updates:[{q:{_id:ObjectId('"+id+ "')},u:{$set:{name:'" + name+"',email:'"+email+"',roles:[" + string.Join(",", roles.Select(r=>"'"+r+"'"))  +"]}}}]}";
                string q = "{update:'users',updates:[{q:{_id:ObjectId('" + id + "')},u:{$set:{email:'" + email + "',roles:" + (roles ?? new string[] { }).toJSON() + ",categories:" + (categories ?? new string[] { }).toJSON() + "}}}]}";
                await NoSql.Instance.RunCommandAsync <BsonDocument>(q);

                return(RedirectToAction("Manage"));
            }
            ViewBag.name  = name;
            ViewBag.email = email;
            ViewBag.roles = await UC.AllRolesAsync();

            ViewBag.categories = await UC.AllCategoriesAsync();

            return(View());
        }
Exemple #3
0
        public async Task <ActionResult> Roles()
        {
            await UC.InitializeAsync(this);

            string q     = "{aggregate:'roles',pipeline:[{$sort : { '_id' : 1 }}]}";
            var    model = await NoSql.Instance.RunCommandAsync <BsonDocument>(q);

            ViewBag.active_roles = "active";
            return(View(model.GetValue("result")));
        }
Exemple #4
0
        public async Task <ActionResult> New()
        {
            await UC.InitializeAsync(this);

            ViewBag.roles = await UC.AllRolesAsync();

            ViewBag.categories = await UC.AllCategoriesAsync();

            ViewBag.active_users = "active";
            return(View());
        }
Exemple #5
0
        public async Task <ActionResult> Edit(string id)
        {
            await UC.InitializeAsync(this);

            string q     = "{aggregate:'users',pipeline:[{$match:{_id:ObjectId('" + id + "')}},{$limit:1}]}";
            var    model = await NoSql.Instance.RunCommandAsync <BsonDocument>(q);

            ViewBag.roles = await UC.AllRolesAsync();

            ViewBag.categories = await UC.AllCategoriesAsync();

            ViewBag.active_users = "active";
            return(View(model.GetValue("result")[0]));
        }
Exemple #6
0
        public async Task <ActionResult> New(string name, string uname, string password, string email, string[] roles, string[] categories)
        {
            await UC.InitializeAsync(this);

            uname = (uname ?? "").ToLower();
            email = (email ?? "").ToLower();
            name  = name.ToStringFarsi();
            if (string.IsNullOrWhiteSpace(name))
            {
                TempData["MSG"] = "لطفا نام و نام خانوادگی را وارد کنید";
            }
            else if (string.IsNullOrWhiteSpace(uname))
            {
                TempData["MSG"] = "لطفا نام کاربری را وارد کنید";
            }
            else if (string.IsNullOrWhiteSpace(password))
            {
                TempData["MSG"] = "لطفا رمزعبور را وارد کنید";
            }
            else if (string.IsNullOrWhiteSpace(email))
            {
                TempData["MSG"] = "لطفا پست الکترونیک را وارد کنید";
            }
            else if (roles == null)
            {
                TempData["MSG"] = "لطفا حدافل یک نقش  را انتخاب کنید";
            }
            else if (categories == null)
            {
                TempData["MSG"] = "لطفا حدافل یک سرویس  را انتخاب کنید";
            }
            else if ((await NoSql.Instance.RunCommandAsync <BsonDocument>("{aggregate:'users',pipeline:[{$match:{uname:'" + uname + "'}},{$limit:1}]}")).GetValue("result").AsBsonArray.Count > 0)
            {
                TempData["MSG"] = "این نام کاربری هم اکنون در سیستم موجود است";
            }
            else if ((await NoSql.Instance.RunCommandAsync <BsonDocument>("{aggregate:'users',pipeline:[{$match:{name:'" + name + "'}},{$limit:1}]}")).GetValue("result").AsBsonArray.Count > 0)
            {
                TempData["MSG"] = "کاربری با این نام و نام خانوادگی هم اکنون در سیستم موجود است";
            }
            else
            {
                var collection = NoSql.Instance.GetCollection <BsonDocument>("users");
                var bdoc       = new BsonDocument {
                    { "name", name }, { "uname", uname }, { "password", password }, { "email", email }, { "status", "فعال" }, { "createdat", DateTime.Now }
                };
                if (roles.Length > 0)
                {
                    bdoc.Add("roles", new BsonArray(roles));
                }
                if (categories.Length > 0)
                {
                    bdoc.Add("categories", new BsonArray(categories));
                }
                await collection.InsertOneAsync(bdoc);

                return(RedirectToAction("Manage"));
            }

            ViewBag.name  = name;
            ViewBag.uname = uname;
            ViewBag.email = email;
            ViewBag.roles = await UC.AllRolesAsync();

            ViewBag.categories = await UC.AllCategoriesAsync();

            return(View());
        }
Exemple #7
0
        public async Task <ActionResult> my()
        {
            await UC.InitializeAsync(this);

            return(View(await UC.UserInfoAsync()));
        }