/// <summary>
        /// 添加
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public ActionResult Insert(AddSystemStaffRequestModel requestModel)
        {
            var ret = _systemStaffService.Insert(requestModel);

            return(Content(ret.ToJsonString()));
        }
示例#2
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public BusinessBaseViewModel <string> Insert(AddSystemStaffRequestModel requestModel)
        {
            var res = new BusinessBaseViewModel <string>()
            {
                Status = ResponseStatus.Fail
            };

            if (requestModel == null)
            {
                res.Status = ResponseStatus.ParameterError;
                return(res);
            }
            if (requestModel.LoginName.IsNullOrWhiteSpace())
            {
                res.ErrorMessage = "登录名称不能为空";
                res.Status       = ResponseStatus.ParameterError;
                return(res);
            }
            //if (requestModel.LoginPwd.IsNullOrWhiteSpace())
            //{
            //    res.ErrorMessage = "登录密码不能为空";
            //    res.Status = ResponseStatus.ParameterError;
            //    return res;
            //}
            if (requestModel.NickName.IsNullOrWhiteSpace())
            {
                res.ErrorMessage = "呢称不能为空";
                res.Status       = ResponseStatus.ParameterError;
                return(res);
            }
            if (requestModel.RoleId.IsNull())
            {
                res.ErrorMessage = "账号角色不能为空";
                res.Status       = ResponseStatus.ParameterError;
                return(res);
            }
            var maskCode = Guid.NewGuid().ToString().Replace("-", "");
            var model    = new SystemStaff()
            {
                LoginName  = requestModel.LoginName,
                Eamil      = requestModel.Eamil,
                Mobile     = requestModel.Mobile,
                Tel        = requestModel.Tel,
                Status     = (int)SystemStaffStatus.Using,
                MaskCode   = maskCode,
                LoginPwd   = DESEncrypt.Md5To32Lens(requestModel.Mobile + maskCode),
                SectionId  = requestModel.SectionId,
                NickName   = requestModel.NickName,
                ModifyTime = DateTime.Now,
                CreateTime = DateTime.Now
            };

            _staffRepostory.Insert(model);
            _staffRepostory.SaveChanges();

            var roleList = new List <SystemStaffRole>();

            requestModel.RoleId.ForEach(m =>
            {
                roleList.Add(new SystemStaffRole()
                {
                    RoleId  = m,
                    StaffId = model.Id
                });
            });
            _systemStaffRoleRepository.Insert(roleList);
            _systemStaffRoleRepository.SaveChanges();

            res.Status = ResponseStatus.Success;
            return(res);
        }