Ejemplo n.º 1
0
        public ActionResult EditUser(Admin_User entity)
        {
            var result = ResModelFactory.ResDefault();

            try
            {
                AdminUserService service = new AdminUserService();
                Admin_User       model   = service.GetEntitys(p => p.Id == entity.Id).FirstOrDefault();
                model.UserName       = entity.UserName;
                model.NickName       = entity.NickName;
                model.Phone          = entity.Phone;
                model.Email          = entity.Email;
                model.Brithday       = entity.Brithday;
                model.Sex            = entity.Sex;
                model.Introduce      = entity.Introduce;
                model.RoleID         = entity.RoleID;
                model.ModifyUserID   = CurrentUser.Id;
                model.ModifyUserName = CurrentUser.UserName;
                model.UpdateDate     = DateTime.Now;
                model.DeleteMark     = entity.DeleteMark;
                var user = service.Update(model);
            }
            catch (Exception ex)
            {
                result = ResModelFactory.ResError(ex.Message);
            }
            return(Json(result));
        }
Ejemplo n.º 2
0
        public ActionResult UploadAvator(string userid)
        {
            if (string.IsNullOrEmpty(userid))
            {
                return(Json(new { code = 0, msg = "参数有误" }));
            }
            var files = HttpContext.Request.Files;
            HttpPostedFileBase file = files[0];
            string             path = string.Empty;
            string             url  = string.Empty;

            do
            {
                url  = "Content/images/" + DateTime.Now.ToString("yyMMddHHmmssfff") + new Random(unchecked ((int)DateTime.Now.Ticks)).Next(1, 100) + "." + file.FileName.Split('.')[1];
                path = Server.MapPath("~/") + url;
            } while (System.IO.File.Exists(path));
            file.SaveAs(path);
            AdminUserService service = new AdminUserService();
            Admin_User       entity  = service.GetEntitys(p => p.Id == userid).FirstOrDefault();

            entity.Photo = "/" + url;
            service.Update(entity);
            return(Json(new
            {
                code = 0,
                msg = "success",
                data = new { src = "/" + url }
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public ActionResult EditUser(string id)
        {
            AdminUserService service = new AdminUserService();
            var user = service.GetEntitys(p => p.Id == id).FirstOrDefault();

            return(View("AddUser", user));
        }
Ejemplo n.º 4
0
        public ActionResult DelteUserByid(string userid)
        {
            if (string.IsNullOrEmpty(userid))
            {
                return(Json(new { code = 999, msg = "参数有误" }));
            }
            AdminUserService service = new AdminUserService();
            Admin_User       entity  = service.GetEntitys(p => p.Id == userid).FirstOrDefault();

            if (entity == null)
            {
                return(Json(new { code = 999, msg = "为获取到用户信息" }));
            }
            entity.DeleteMark = true;//删除
            service.Update(entity);
            return(Json(new
            {
                code = 0,
                msg = "success"
            }));
        }
Ejemplo n.º 5
0
        public ActionResult Login(string userName, string password, string imageCode)
        {
            // 验证码
            var    result = ResModelFactory.ResDefaultData <Admin_User>();
            string code   = Session["ImageCode"].ToString();

            if (!code.Equals(imageCode))
            {
                //验证码错误
                result.code = "999";
                result.msg  = "验证码错误";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            AdminUserService service = new AdminUserService();
            var user = service.GetEntitys(p => p.UserName == userName.Trim() && p.PassWord == password).FirstOrDefault();

            if (user == null)
            {
                result.code = "999";
                result.msg  = "用户名或密码错误";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            string token = JwtHelper.SetJwtEncode(userName, password);

            //result.token = token;
            result.data = new List <Admin_User> {
                user
            }.ToArray();
            //服务端存储
            //客户端存储cookie
            System.Web.HttpCookie cookie = new System.Web.HttpCookie("authorize", token);
            cookie.Expires = DateTime.Now.AddDays(1);
            this.HttpContext.Response.Cookies.Add(cookie);
            //客户端加入header
            this.HttpContext.Response.Headers.Add("Authorization", token);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }