Ejemplo n.º 1
0
        /// <summary>
        /// 添加管理员,此处还可以扩展加为小编等其他角色
        /// </summary>
        /// <param name="username"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public JsonResult AddAdmin(string username, string type)
        {
            var user = PrivateDb.One((User u) => u.UserName == username);//先判断有无这个人
            string str;
            if (user != null)
            {
                //再判断这个人有没有加入Role
                var o = PrivateDb.One(r => r.UserId == user.UserId && r.RoleType == type);
                if (o != null)
                {
                    str = "该用户已经是" + type;
                }
                else
                {
                    var role = new Role(type, user.UserId);
                    PrivateDb.Add(role);
                    var ads = PrivateDb.AdminStatisticAll().SingleOrDefault(n => n.UserId == user.UserId);

                    if (ads == null)
                    {
                        var amdst = new AdminStatistic
                        {
                            UserId = user.UserId,
                            CheckImgCount = 0,
                            CheckInfoCount = 0,
                            LastLogin = DateTime.Now,
                            SignInDays = 0,
                            Experience = 0,
                            Gold = 0
                        };
                        PrivateDb.Add(amdst);
                    }

                    str = "ok";
                    Logger.Trace("管理员:" + GetUserNameById(CheckValid()) + "添加了" + user.UserName + "为" + type);
                }

            }
            else
            {
                str = "该用户名不存在";
            }
            return Json(str);
        }
Ejemplo n.º 2
0
 public Admin GetAdmin(Role role)
 {
     var user = PrivateDb.One((User n) => n.UserId == role.UserId);
     return new Admin
     {
         Role = role,
         ImgUrl = user.ImgUrl,
         UserName = user.UserName
     };
 }