public BasicResponse <RightInfo> AddRight(RightAddRequest rightrequest) { RightInfo rightDTO = rightrequest.RightInfo; if (rightDTO.CreateTime != null) { rightDTO.CreateTime = Convert.ToDateTime(rightDTO.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")); } if (string.IsNullOrEmpty(rightDTO.RightCode)) { ThrowException("AddRight", new Exception("权限编码不能为空,请重新输入!")); } if (string.IsNullOrEmpty(rightDTO.RightName)) { ThrowException("AddRight", new Exception("权限名称不能为空,请重新输入!")); } if (CheckRightNameExist(rightDTO.RightName)) { //校验权限名是否重复 ThrowException("AddRight", new Exception(String.Format("权限名:{0} 已存在,请重新输入!", rightDTO.RightName))); } if (CheckRightCodeExist(rightDTO.RightCode)) { //校验权限编码是否重复 ThrowException("AddRight", new Exception(String.Format("权限编码:{0} 已存在,请重新输入!", rightDTO.RightCode))); } //判断权限名是否存在,只有不存在才能插入 if (CheckRightNameExist(rightDTO.RightName)) { //校验权限名是否重复 ThrowException("AddRight", new Exception(String.Format("权限名:{0} 已存在,请重新输入!", rightDTO.RightName))); } var _right = ObjectConverter.Copy <RightInfo, RightModel>(rightDTO); var resultright = _Repository.AddRight(_right); var rightresponse = new BasicResponse <RightInfo>(); rightresponse.Data = ObjectConverter.Copy <RightModel, RightInfo>(resultright); return(rightresponse); }
public BasicResponse <RightInfo> AddRightEx(RightAddRequest rightrequest) { return(_rightService.AddRightEx(rightrequest)); }
/// <summary> /// 添加一个全新信息到权限表并返回成功后的权限对象(支持添加、更新,根据状态来判断) /// </summary> /// <param name="rightrequest"></param> /// <returns></returns> public BasicResponse <RightInfo> AddRightEx(RightAddRequest rightrequest) { BasicResponse <RightInfo> Result = new BasicResponse <RightInfo>(); RightInfo rightDTO = rightrequest.RightInfo; try { long ID = 0; if (rightDTO == null) { ThrowException("AddRightEx", new Exception("权限对象为空,请检查是否已赋值!")); } if (rightDTO.InfoState == InfoState.NoChange) { ThrowException("AddRightEx", new Exception("DTO对象未设置状态,请先设置!")); } if (rightDTO.CreateTime != null) { rightDTO.CreateTime = Convert.ToDateTime(rightDTO.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")); } if (string.IsNullOrEmpty(rightDTO.RightCode)) { ThrowException("AddRightEx", new Exception("权限编码不能为空,请重新输入!")); } if (string.IsNullOrEmpty(rightDTO.RightName)) { //throw new BusinessException("权限名称不能为空,请重新输入!"); ThrowException("AddRightEx", new Exception("权限名称不能为空,请重新输入!")); } if (rightDTO.InfoState == InfoState.AddNew) { //判断权限名是否存在,只有不存在才能插入 if (!CheckRightNameExist(rightDTO.RightName) && !CheckRightCodeExist(rightDTO.RightCode)) { ID = IdHelper.CreateLongId(); rightDTO.RightID = ID.ToString(); var _request = ObjectConverter.Copy <RightInfo, RightModel>(rightDTO); var resultmenu = _Repository.AddRight(_request); Result.Data = ObjectConverter.Copy <RightModel, RightInfo>(resultmenu); } else { //校验权限名是否重复 ThrowException("AddRightEx", new Exception("权限已存在,请重新输入!")); } } else { var _request = ObjectConverter.Copy <RightInfo, RightModel>(rightDTO); _Repository.UpdateRight(_request); var resultmenu = _Repository.GetRightById(rightDTO.RightID); Result.Data = ObjectConverter.Copy <RightModel, RightInfo>(resultmenu); } } catch (System.Exception ex) { Result.Code = 1; Result.Message = ex.Message; } return(Result); }
/// <summary> /// 添加一个全新信息到权限表并返回成功后的权限对象(支持添加、更新,根据状态来判断) /// </summary> /// <param name="rightrequest"></param> /// <returns></returns> public BasicResponse <RightInfo> AddRightEx(RightAddRequest rightrequest) { var responseStr = HttpClientHelper.Post(Webapi + "/v1/Right/AddRightEx?token=" + Token, JSONHelper.ToJSONString(rightrequest)); return(JSONHelper.ParseJSONString <BasicResponse <RightInfo> >(responseStr)); }