Esempio n. 1
0
        public async Task <ActionResult <ResponseData> > Delete(Guid groupId, Guid fileId, bool depGroup = false)
        {
            try
            {
                var operatorId = GetEmployeeId();
                var group      = !depGroup
                            ? await _groupAppService.GetByIdAsync(groupId)
                            : await _departmentAppService.GetDepGroupByIdAsync(groupId);

                if (group == null)
                {
                    return(ResponseData.BuildFailedResponse(message: "群组不存在"));
                }
                if (IsGroupOwner(group.Members, operatorId) || await IsFileOwnerAsync(fileId, operatorId))
                {
                    await _groupFileControlApp.DeleteFileItemAsync(fileId);

                    _cache.Remove(groupId);
                    return(ResponseData.BuildSuccessResponse());
                }
                else
                {
                    return(ResponseData.BuildFailedResponse(message: "没有操作权限"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(LogError(_logger, ex)));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <ResponseData <FileItemDto> > > UploadFileAsync(Guid groupId, string storeId, string fileName, bool depGroup = false)
        {
            try
            {
                if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(storeId) || Guid.Empty.Equals(groupId))
                {
                    return(ResponseData <FileItemDto> .BuildFailedResponse(message : "参数错误"));
                }
                var uploaderId = GetEmployeeId();
                var group      = !depGroup
                    ? await _groupAppService.GetByIdAsync(groupId)
                    : await _departmentAppService.GetDepGroupByIdAsync(groupId);

                if (group == null)
                {
                    return(ResponseData <FileItemDto> .BuildFailedResponse(message : "群组不存在"));
                }
                if (!IsMemeberInGroup(group.Members, uploaderId))
                {
                    return(ResponseData <FileItemDto> .BuildFailedResponse(message : "无上传权限"));
                }
                var attachment = await _attachmentAppServiceFactory(storeId).GetByIdAsync(storeId);

                if (attachment == null)
                {
                    return(ResponseData <FileItemDto> .BuildFailedResponse(message : "文件上传失败"));
                }
                var input = new UploadInput
                {
                    FileName = fileName,
                    GroupId  = groupId,
                    StoreId  = storeId
                };
                await SendMessageAsync(groupId, GetUserId(), fileName, attachment);

                var result = await _groupFileControlApp.UploadFileAsync(input, uploaderId);

                _cache.Remove(groupId);
                if (result != null)
                {
                    result.Size         = attachment.Size;
                    result.UploaderName = GetUserFullName();
                    return(ResponseData <FileItemDto> .BuildSuccessResponse(result));
                }
                else
                {
                    return(ResponseData <FileItemDto> .BuildFailedResponse());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(LogError(_logger, ex)));
            }
        }