Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Delete(DeleteItems request)
        {
            var ids = string.IsNullOrWhiteSpace(request.Ids)
                ? Array.Empty <string>()
                : request.Ids.Split(',');

            foreach (var i in ids)
            {
                var item = _libraryManager.GetItemById(i);
                var auth = _authContext.GetAuthorizationInfo(Request);
                var user = auth.User;

                if (!item.CanDelete(user))
                {
                    if (ids.Length > 1)
                    {
                        throw new SecurityException("Unauthorized access");
                    }

                    continue;
                }

                _libraryManager.DeleteItem(item, new DeleteOptions
                {
                    DeleteFileLocation = true
                }, true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Delete(DeleteItems request)
        {
            var ids = string.IsNullOrWhiteSpace(request.Ids)
             ? new string[] { }
             : request.Ids.Split(',');

            var tasks = ids.Select(i =>
            {
                var item = _libraryManager.GetItemById(i);
                var auth = _authContext.GetAuthorizationInfo(Request);
                var user = _userManager.GetUserById(auth.UserId);

                if (!item.CanDelete(user))
                {
                    if (ids.Length > 1)
                    {
                        throw new SecurityException("Unauthorized access");
                    }

                    return(Task.FromResult(true));
                }

                return(item.Delete(new DeleteOptions
                {
                    DeleteFileLocation = true
                }));
            }).ToArray(ids.Length);

            Task.WaitAll(tasks);
        }