示例#1
0
        public ActionResult Add(FarmMonitor.Model.SysUserInfo model, string roleinfoName)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                return(Content("<script>alert('名字不能为空');window.location.href='/UserInfoManage/Add/'</script>"));
            }
            if (string.IsNullOrEmpty(model.Password))
            {
                return(Content("<script>alert('密码不能为空';window.location.href='/UserInfoManage/Add/')</script>"));
            }
            if (string.IsNullOrEmpty(model.Tel) && string.IsNullOrEmpty(model.Mobile))
            {
                return(Content("<script>alert('电话和手机不能为空');window.location.href='/UserInfoManage/Add/'</script>"));
            }
            if (string.IsNullOrEmpty(model.Province.ToString()) || string.IsNullOrEmpty(model.City.ToString()))
            {
                return(Content("<script>alert('省份城市不能为空');window.location.href='/UserInfoManage/Add/'</script>"));
            }
            var usero = userinfoman.GetModelByUserName(model.Name);

            if (usero != null)
            {
                return(Content("<script>alert('用户名重复');window.location.href='/UserInfoManage/Add/'</script>"));
            }
            #region 增加用户信息
            userinfo.Name       = model.Name;
            userinfo.Password   = EncryptCommon.EncryptMD5(model.Password);
            userinfo.UserCode   = model.UserCode;
            userinfo.Sex        = model.Sex;
            userinfo.Tel        = model.Tel == null ? "" : model.Tel;
            userinfo.Birthday   = model.Birthday;
            userinfo.Province   = model.Province;
            userinfo.City       = model.City;
            userinfo.Mobile     = model.Mobile == null ? "" : model.Mobile;
            userinfo.Email      = model.Email == null ? "" : model.Email;
            userinfo.UserState  = model.UserState;
            userinfo.Remark     = model.Remark == null ? "" : model.Remark;
            userinfo.CreateDate = DateTime.Now;
            userinfoman.Add(userinfo);
            #endregion

            #region 增加用户角色关联表
            SysUserRoleMan userroleman = new SysUserRoleMan();
            SysUserRole    userrole    = new SysUserRole();
            userrole.RoleId     = Convert.ToInt32(roleinfoName);
            userrole.UserId     = userinfo.ID;
            userrole.CreateTime = DateTime.Now;
            userroleman.Add(userrole);
            #endregion
            return(Content("<script>alert('增加成功');window.location.href='/UserInfoManage/Index/'</script>"));
        }
示例#2
0
        public ActionResult Edit(FarmMonitor.Model.SysUserInfo model, string roleinfoName)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                return(Content("<script>alert('名字不能为空');window.location.href='/UserInfoManage/Edit/@model.ID'</script>"));
            }
            //if (string.IsNullOrEmpty(model.Password))
            //{
            //    return Content("<script>alert('密码不能为空';window.location.href='/UserInfoManage/Edit/@model.ID')</script>");
            //}
            if (string.IsNullOrEmpty(model.Tel) && string.IsNullOrEmpty(model.Mobile))
            {
                return(Content("<script>alert('电话和手机不能为空');window.location.href='/UserInfoManage/Edit/@model.ID'</script>"));
            }
            if (string.IsNullOrEmpty(model.Province.ToString()) || string.IsNullOrEmpty(model.City.ToString()))
            {
                return(Content("<script>alert('省份城市不能为空');window.location.href='/UserInfoManage/Add/'</script>"));
            }
            var userInfoModel = userinfoman.GetEntity(model.ID);

            #region 用户信息更新
            userInfoModel.Name      = model.Name;
            userInfoModel.UserCode  = model.UserCode == null ? "" : model.UserCode;
            userInfoModel.Sex       = model.Sex;
            userInfoModel.Birthday  = model.Birthday;
            userInfoModel.Tel       = model.Tel == null ? "" : model.Tel;
            userInfoModel.Province  = model.Province;
            userInfoModel.City      = model.City;
            userInfoModel.Mobile    = model.Mobile == null ? "" : model.Mobile;
            userInfoModel.Email     = model.Email == null ? "" : model.Email;
            userInfoModel.UserState = model.UserState;
            userInfoModel.Remark    = model.Remark == null ? "" : model.Remark;
            if (model.Password != "")
            {
                userInfoModel.Password = EncryptCommon.EncryptMD5(model.Password);
            }
            userinfoman.Update(userInfoModel);
            #endregion

            #region 更新用户角色关联表
            SysUserRoleMan userroleman   = new SysUserRoleMan();
            var            userroleModel = userroleman.GetModelByUserId(model.ID);
            userroleModel.RoleId     = Convert.ToInt32(roleinfoName);
            userroleModel.UserId     = model.ID;
            userroleModel.UpdateTime = DateTime.Now;
            userroleman.Update(userroleModel);
            #endregion
            return(Content("<script>alert('更新成功');window.location.href='/UserInfoManage/Index/'</script>"));
        }