Пример #1
0
        public ActionResult Delete(int id)
        {
            S3Helper s3       = new S3Helper();
            var      model    = _context.Artefacts.FirstOrDefault(x => x.Id == id);
            var      filename = model.Filename;

            s3.DeleteFile(filename);


            _context.Artefacts.Remove(_context.Artefacts.FirstOrDefault(x => x.Id == id));
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        public async Task <ActionResult> Edit(ArtefactsCreateViewModel model)
        {
            S3Helper s3 = new S3Helper();

            s3.DeleteFile(model.Artefact.Filename);

            try
            {
                if (model.Artefact.AccessionNumber != null)
                {
                    // set date
                    model.Artefact.DateAccessioned = DateTime.Now;

                    // if completed correctly
                    if (model.Artefact.AdlibReference != null)
                    {
                        model.Artefact.IsCompleted = true;
                    }
                }

                if (model.Image != null)
                {
                    // change image in storage
                    string fileName = "artefact-" + DateTime.Now.ToString("yyyyMMddTHH:mm:ssZ");
                    model.Artefact.Filename = fileName;
                    var imageUrl = s3.GetFilePath(fileName);
                    model.Artefact.ImageUrl = imageUrl;
                    s3.UploadFile(model.Image, fileName);
                }

                // update last edited by
                var user = await _userManager.GetUserAsync(this.User);

                model.Artefact.UserLastEditedById = user.Id;

                _context.Artefacts.Update(model.Artefact);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(model));
            }
        }
Пример #3
0
        private async void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var           s3BucketName = GetS3BucketName(_currentNode);
            StringBuilder sb           = new StringBuilder();
            S3Helper      s3Helper     = new S3Helper(
                GlobalVariables.Enviroment,
                GlobalVariables.Region,
                GlobalVariables.Color,
                s3BucketName
                );

            try
            {
                if (dgViewS3Files.SelectedRows.Count > 0)
                {
                    StringBuilder deletedFiles = new StringBuilder();
                    foreach (var row in dgViewS3Files.SelectedRows)
                    {
                        deletedFiles.Append(((DataGridViewRow)row).Cells[0].Value.ToString() + ",");
                    }
                    var confirmResult = MessageBox.Show(
                        string.Format("Are you sure to delete file(s): '{0}' from S3 Bucket?",
                                      deletedFiles.ToString().Substring(0, deletedFiles.ToString().Length - 1)),
                        "Confirm Delete S3 Bucket Files",
                        MessageBoxButtons.YesNo);
                    if (confirmResult == DialogResult.Yes)
                    {
                        foreach (var row in dgViewS3Files.SelectedRows)
                        {
                            var s3FilePath = ((DataGridViewRow)row).Cells[0].Value.ToString();
                            sb.Append((((DataGridViewRow)row).Cells[0].Value.ToString()) + ",");
                            await s3Helper.DeleteFile(s3FilePath);
                        }
                        RefreshGridviewControl();
                    }
                    WriteNotification(string.Format("Files {0} were deleted from {1}", sb.ToString(), s3BucketName));
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }