示例#1
0
        public async Task <RESTResult> AddOrUpdatePermissionAsync(PermissionTransferDataObject permissionInfo, Guid currentUserId, bool IsDeleted)
        {
            RESTResult result = new RESTResult {
                Code = RESTStatus.Success
            };

            if (Guid.Empty.Equals(permissionInfo.Id) || permissionInfo.Id == null)
            {
                //TODO:Add a new department
                var permissionEntity = Mapper.Map <PermissionTransferDataObject, Permission>(permissionInfo);
                if (permissionInfo.PermissionData != null)
                {
                    permissionInfo.PermissionData.Id       = Guid.NewGuid();
                    permissionInfo.PermissionData.ParentId = permissionInfo.PermissionData.ParentId != null ? permissionInfo.PermissionData.ParentId : Guid.Empty;
                    permissionEntity.DataXml = _serializer.Serialize(permissionInfo.PermissionData);
                }
                permissionEntity.CreateTime     = DateTime.Now;
                permissionEntity.CreateByUserId = currentUserId;
                result.Data = await _permissionRepository.InsertAsync(permissionEntity);
            }
            else
            {
                //TODO:Update department
                var permissionEntity = await _permissionRepository.GetAsync(permissionInfo.Id.Value);

                permissionEntity.Name           = permissionInfo.Name;
                permissionEntity.ModifyByUserId = currentUserId;
                permissionEntity.ModifyTime     = DateTime.Now;
                permissionEntity.IsDeleted      = IsDeleted;
                permissionEntity.DataXml        = permissionInfo.PermissionData != null?_serializer.Serialize(permissionInfo.PermissionData) : permissionEntity.DataXml;

                result.Data = await _permissionRepository.UpdateAsync(permissionEntity);
            }

            if (result.Data != null)
            {
                return(result);
            }
            result.Code = RESTStatus.Failed;
            return(result);
        }
示例#2
0
 public async Task <IActionResult> AddOrUpdatePermission([FromBody] PermissionTransferDataObject permissionInfo)
 {
     return(Ok(await _userAppService.AddOrUpdatePermissionAsync(permissionInfo, CurrentUser.Id.Value, false)));
 }