Ejemplo n.º 1
0
        internal virtual PutPermissionResponse PutPermission(PutPermissionRequest request)
        {
            var marshaller   = PutPermissionRequestMarshaller.Instance;
            var unmarshaller = PutPermissionResponseUnmarshaller.Instance;

            return(Invoke <PutPermissionRequest, PutPermissionResponse>(request, marshaller, unmarshaller));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initiates the asynchronous execution of the PutPermission operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutPermission operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/events-2015-10-07/PutPermission">REST API Reference for PutPermission Operation</seealso>
        public virtual Task <PutPermissionResponse> PutPermissionAsync(PutPermissionRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = PutPermissionRequestMarshaller.Instance;
            var unmarshaller = PutPermissionResponseUnmarshaller.Instance;

            return(InvokeAsync <PutPermissionRequest, PutPermissionResponse>(request, marshaller,
                                                                             unmarshaller, cancellationToken));
        }
        internal virtual PutPermissionResponse PutPermission(PutPermissionRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PutPermissionRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PutPermissionResponseUnmarshaller.Instance;

            return(Invoke <PutPermissionResponse>(request, options));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the PutPermission operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutPermission operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/events-2015-10-07/PutPermission">REST API Reference for PutPermission Operation</seealso>
        public virtual Task <PutPermissionResponse> PutPermissionAsync(PutPermissionRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PutPermissionRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PutPermissionResponseUnmarshaller.Instance;

            return(InvokeAsync <PutPermissionResponse>(request, options, cancellationToken));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <PutPermissionResponse> > UpdatePermission(
            [Required] string meUserId,
            [Required] string permissionId,
            [FromBody]
            PutPermissionRequest putPermission)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(new PutPermissionResponse()));
                }

                var currentUser = await CurrentUser();

                if (currentUser.UserId.Equals(meUserId))
                {
                    return(Forbid());
                }

                var locationDocument = (await
                                        _locationParentsService.Handle(
                                            new LocationParentsQuery(putPermission.LocationId)))
                                       .ToLocationPath();

                if (!CanAsync(Permission.UpdateUserPermission, locationDocument))
                {
                    return(Forbid());
                }

                var user = await _userRetrievalByIdService.Handle(new UserRetrievalByIdQuery(meUserId));

                if (user == null)
                {
                    return(NotFound(new PutPermissionResponse()));
                }

                var permissionToUpdate = user.Permissions.SingleOrDefault(p => p.PermissionId == permissionId);

                if (permissionToUpdate == null)
                {
                    return(NotFound(new PutPermissionResponse()));
                }

                if (user.Permissions.Any(usersPermission => usersPermission.LocationId == putPermission.LocationId && usersPermission.UserRole == putPermission.UserRole))
                {
                    return(Conflict());
                }

                permissionToUpdate = Mapper.Map(putPermission, permissionToUpdate);

                var updateUser = new UserUpdatePermissions
                {
                    UserId      = user.UserId,
                    Permissions = user.Permissions,
                };

                await _userUpdateService.Handle(new UserUpdateQuery(updateUser, currentUser));

                var locationOfPermission =
                    _locationRetrievalService.Handle(new LocationRetrievalByIdQuery(permissionToUpdate.LocationId)).Result;

                var permissionLocation = new PermissionLocation(permissionToUpdate, locationOfPermission, meUserId);

                var result = Mapper.Map <PutPermissionResponse>(permissionLocation);

                return(Ok(result));
            }
            catch (DocumentClientException)
            {
                return(NotFound(new PutPermissionResponse()));
            }
            catch (ArgumentException)
            {
                return(NotFound(new PutPermissionResponse()));
            }
        }