Exemplo n.º 1
0
        public IActionResult DeleteFileDataById(string fileId)
        {
            if (!Guid.TryParse(fileId, out Guid id))
            {
                return(BadRequest("Invalid file id"));
            }

            var userIdClaim  = User.Claims.Single(c => c.Type == "id");
            var fileMetadata = _fileData.GetFileMetadata(id);

            if (fileMetadata == null)
            {
                return(BadRequest("File not found"));
            }

            if (userIdClaim.Value != fileMetadata.Audit.CreatedUserId)
            {
                return(Unauthorized("User does not own the file"));
            }

            _fileData.Delete(id);
            _fileData.Delete(fileMetadata);

            return(NoContent());
        }
Exemplo n.º 2
0
        private void ImBtn_Click(object sender, EventArgs e)
        {
            if (FilePathTB.Text.Length > 0)
            {
                ImExcel   excel = new ImExcel();
                DataTable dt    = excel.LoadExcel(FilePathTB.Text);
                List <ToolingDataSys.Code.Message> message = null;
                if (type == FileDataOperateType.Insert)
                {
                    message = file.Insert(dt);
                }
                else if (type == FileDataOperateType.Update)
                {
                    message = file.Update(dt);
                }
                else if (type == FileDataOperateType.Delete)
                {
                    message = file.Delete(dt);
                }
                else if (type == FileDataOperateType.TransPosition)
                {
                    IMoldFile moldFile = file as IMoldFile;
                    message = moldFile.TransPosition(dt);
                }

                if (message != null && message.Count > 0)
                {
                    new MessageDialog(message).ShowDialog();
                }
                else
                {
                    MessageBox.Show("导入成功!");
                }
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> DeleteConfirm(Guid id)
        {
            var file = _fileData.Get(id);

            if (file != null)
            {
                var companyId = GetNonAdminUserCompanyId();
                if (!companyId.IsNullOrWhiteSpace() && !file.ContainerName.Equals(companyId, StringComparison.OrdinalIgnoreCase) ||
                    file.ReadOnly)
                {
                    return(RedirectToAction(nameof(AccountController.AccessDenied), nameof(AccountController).GetControllerName(),
                                            new { returnUrl = Request.Path }));
                }

                if (!string.IsNullOrWhiteSpace(file.ContainerName) && !string.IsNullOrWhiteSpace(file.FileName))
                {
                    try
                    {
                        await _blobService.DeleteBlob(file.ContainerName, file.FileName);
                    }
                    catch (ArgumentException)
                    {
                        // no container, fine because it's probably seed data
                    }
                }

                _fileData.Delete(file);
                _fileData.Commit();
                SendFileNotification(FileOperations.Deleted, file.FileName,
                                     User.Claims.FirstOrDefault(_ => _.Type.Equals(AuthConstants.CompanyClaim)).Value);
            }

            return(RedirectToAction(nameof(Index)));
        }