Beispiel #1
0
        /// <summary>
        /// 设置实体
        /// </summary>
        /// <returns>返回对象实体</returns>
        /// <param name="dr">行</param>
        private Model.VM_SysUser SetEntityForVM(DataRow dr)
        {
            Model.VM_SysUser model = new Model.VM_SysUser();
            if (dr != null)
            {
                if (dr.Table.Columns.Contains("Row"))
                {
                    if (dr["Row"].ToString() != "")
                    {
                        model.Row = int.Parse(dr["Row"].ToString());
                    }
                }
                if (dr["UserID"].ToString() != "")
                {
                    model.UserID = int.Parse(dr["UserID"].ToString());
                }
                model.LoginName = dr["LoginName"].ToString();
                if (dr["RoleID"].ToString() != "")
                {
                    model.RoleID = int.Parse(dr["RoleID"].ToString());
                }
                model.RoleName = dr["RoleName"].ToString();
                model.Name     = dr["Name"].ToString();
                if (dr["Gender"].ToString() != "")
                {
                    if ((dr["Gender"].ToString() == "1") || (dr["Gender"].ToString().ToLower() == "true"))
                    {
                        model.Gender = true;
                    }
                    else
                    {
                        model.Gender = false;
                    }
                }
                model.Telephone    = dr["Telephone"].ToString();
                model.Department   = dr["Department"].ToString();
                model.RegisterDate = DateTime.Parse(dr["RegisterDate"].ToString());
                if (dr["State"].ToString() != "")
                {
                    if ((dr["State"].ToString() == "1") || (dr["State"].ToString().ToLower() == "true"))
                    {
                        model.State = true;
                    }
                    else
                    {
                        model.State = false;
                    }
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 更新用户登陆及基本信息
 /// </summary>
 /// <returns>The update.</returns>
 public int Update(Model.VM_SysUser model)
 {
     Model.SysUser m = new Model.SysUser();
     m.UserID    = model.UserID;
     m.LoginName = model.LoginName;
     m.RoleID    = model.RoleID;
     Model.SysUserInfo ui = new Model.SysUserInfo();
     ui.Gender     = model.Gender;
     ui.Department = model.Department;
     ui.Name       = model.Name;
     ui.Telephone  = model.Telephone;
     ui.UserID     = model.UserID;
     return(dal.Update(m, ui));
 }
Beispiel #3
0
 /// <summary>
 /// 新增系统用户
 /// </summary>
 public int Insert(Model.VM_SysUser model)
 {
     Model.SysUser m = new Model.SysUser();
     m.LoginName     = model.LoginName;
     m.LoginPassword = "******";
     m.ParentID      = model.ParentID;
     m.RoleID        = model.RoleID;
     m.State         = true;
     Model.SysUserInfo ui = new Model.SysUserInfo();
     ui.Gender       = model.Gender;
     ui.Department   = model.Department;
     ui.Name         = model.Name;
     ui.RegisterDate = DateTime.Now;
     ui.Telephone    = model.Telephone;
     return(dal.Insert(m, ui));
 }
Beispiel #4
0
        /// <summary>
        /// 新增/修改 展示页面
        /// </summary>
        /// <returns>The new.</returns>
        /// <param name="id">Identifier.</param>
        public ActionResult New(int?id)
        {
            int UserID = id == null ? 0 : (int)id;

            Model.VM_SysUser model = new Model.VM_SysUser();

            if (UserID > 0)
            {
                model          = Opr.GetEntity(UserID);
                ViewBag.Title  = "正在编辑用户: " + model.Name;
                ViewBag.RoleID = model.RoleID;
            }
            else
            {
                Model.SysUser cm = (Model.SysUser)Session["UserInfo"];
                model.ParentID = cm.UserID;
                model.UserID   = 0;
                model.State    = true;
                ViewBag.Title  = "后端管理系统-新增系统用户";
            }
            return(View(model));
        }
Beispiel #5
0
        public ActionResult New(Model.VM_SysUser model)
        {
            Helper.ResultInfo <int> rs = new Helper.ResultInfo <int>();
            JsonResult jr = new JsonResult();

            if (ModelState.IsValid)
            {
                if (model.UserID > 0)
                {
                    //修改
                    rs.Data = Opr.Update(model);
                    if (rs.Data > 0)
                    {
                        rs.Msg    = "更新成功.";
                        rs.Result = true;
                    }
                    else
                    {
                        rs.Msg    = "更新失败.";
                        rs.Result = false;
                    }
                    jr.Data = rs;
                    return(jr);
                }
                else
                {
                    rs.Data = Opr.Insert(model);
                    if (rs.Data > 0)
                    {
                        rs.Msg    = "新增成功.";
                        rs.Result = true;
                    }
                    else
                    {
                        rs.Msg    = "新增失败.";
                        rs.Result = false;
                    }
                    jr.Data = rs;
                    return(jr);
                }
            }
            else
            {
                System.Text.StringBuilder sbErrors = new System.Text.StringBuilder();
                foreach (var item in ModelState.Values)
                {
                    if (item.Errors.Count > 0)
                    {
                        for (int i = item.Errors.Count - 1; i >= 0; i--)
                        {
                            sbErrors.Append(item.Errors[i].ErrorMessage);
                            sbErrors.Append("<br/>");
                        }
                    }
                }
                rs.Data   = 0;
                rs.Msg    = sbErrors.ToString();
                rs.Result = false;
                rs.Url    = "";
                jr.Data   = rs;
                return(jr);
            }
        }