Beispiel #1
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public BusinessBaseViewModel <string> Update(UpdateSystemStaffRequestModel requestModel)
        {
            var res = new BusinessBaseViewModel <string>()
            {
                Status = ResponseStatus.Fail
            };

            if (requestModel == null)
            {
                res.Status = ResponseStatus.ParameterError;
                return(res);
            }
            if (requestModel.NickName.IsNullOrWhiteSpace())
            {
                res.ErrorMessage = "呢称不能为空";
                res.Status       = ResponseStatus.ParameterError;
                return(res);
            }
            var entity = _staffRepostory.FirstOrDefault(x => x.Id == requestModel.Id);

            if (entity.IsNull())
            {
                res.ErrorMessage = "当前用户不存在或已被删除";
                return(res);
            }

            entity.Eamil      = requestModel.Eamil;
            entity.Mobile     = requestModel.Mobile;
            entity.Tel        = requestModel.Tel;
            entity.SectionId  = requestModel.SectionId;
            entity.NickName   = requestModel.NickName;
            entity.ModifyTime = DateTime.Now;


            var roleList = new List <SystemStaffRole>();

            requestModel.RoleId.ForEach(m =>
            {
                roleList.Add(new SystemStaffRole()
                {
                    RoleId  = m,
                    StaffId = entity.Id
                });
            });

            _staffRepostory.Update(entity);
            _systemStaffRoleRepository.SqlExecute("delete s_SystemStaffRole where StaffId = @StaffId", new[] { new SqlParameter("StaffId", entity.Id) });
            _systemStaffRoleRepository.Insert(roleList);
            _systemStaffRoleRepository.SaveChanges();

            res.Status = ResponseStatus.Success;
            return(res);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public ActionResult Update(UpdateSystemStaffRequestModel requestModel)
        {
            var ret = _systemStaffService.Update(requestModel);

            return(Content(ret.ToJsonString()));
        }