Пример #1
0
        public async Task <IActionResult> Edit(long id, [FromForm] ArtistViewModel artist)
        {
            if (id != artist.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (artist.formFile != null)
                {
                    //delete old photo
                    var oldPhoto = artist.PhotoName;
                    await _s3Client.DeleteObjectNonVersionedBucketAsync(oldPhoto);

                    //var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
                    FileUploadHelper objFile  = new FileUploadHelper();
                    string           fileName = objFile.GetFileName(artist.formFile, true);
                    await _s3Client.UploadFileAsync(artist.formFile.OpenReadStream(), fileName);

                    artist.PhotoName = fileName;
                }
                if (artist.Alive)
                {
                    artist.DeathDate = null;
                }

                await _culturalClient.Update <ArtistViewModel>(artist, id, Route);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(artist));
        }
Пример #2
0
        public async Task <IActionResult> Create([FromForm] LocationViewModel location)
        {
            if (ModelState.IsValid)
            {
                //var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
                FileUploadHelper objFile  = new FileUploadHelper();
                string           fileName = objFile.GetFileName(location.formFile, true);
                await _s3Client.UploadFileAsync(location.formFile.OpenReadStream(), fileName);

                location.PhotoName = fileName;
                await _culturalClient.CreateAsync <LocationViewModel>(location, Route);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
Пример #3
0
        public async Task <ActionResult> UploadFile()
        {
            var httpRequest = HttpContext.Request;

            if (httpRequest.Files.Count > 0)
            {
                const int fileIndex      = 0;
                var       fileRepository = new FileStorageRepository(GetStorageSettings());

                var fileName = FileUploadHelper.GetFileName(httpRequest, fileIndex);
                using (Stream fileStream = FileUploadHelper.GetInputStream(httpRequest, fileIndex))
                    await fileRepository.UploadAsync(fileStream, fileName);

                return(RedirectToAction("Index"));
            }

            throw new ArgumentException("File count is zero.");
        }
Пример #4
0
        public async Task <IActionResult> Create([FromForm] ArtistViewModel artist)
        {
            if (ModelState.IsValid)
            {
                //var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
                FileUploadHelper objFile  = new FileUploadHelper();
                string           fileName = objFile.GetFileName(artist.formFile, true);
                await _s3Client.UploadFileAsync(artist.formFile.OpenReadStream(), fileName);

                artist.PhotoName = fileName;
                if (artist.Alive)
                {
                    artist.DeathDate = null;
                }
                await _culturalClient.CreateAsync <ArtistViewModel>(artist, Route);


                return(RedirectToAction(nameof(Index)));
            }
            return(View(artist));
        }
Пример #5
0
        public async Task <ActionResult> UploadFile()
        {
            var httpRequest = HttpContext.Request;

            if (httpRequest.Files.Count > 0)
            {
                const int fileIndex      = 0;
                var       blobRepository = new BlobStorageRepository(GetStorageSettings());

                var directory = FileUploadHelper.GetFormValue <string>(httpRequest, "directory", string.Empty);
                var fileName  = string.IsNullOrWhiteSpace(directory) ?
                                FileUploadHelper.GetFileName(httpRequest, fileIndex) :
                                Path.Combine(directory, FileUploadHelper.GetFileName(httpRequest, fileIndex));

                using (Stream fileStream = FileUploadHelper.GetInputStream(httpRequest, fileIndex))
                    await blobRepository.UploadAsync(fileName, fileStream);

                return(RedirectToAction("Index"));
            }

            throw new ArgumentException("File count is zero.");
        }