Exemple #1
0
        public async Task <IActionResult> Insert(int id, InterventionInsertViewModel model)
        {
            var storageAccount = CloudStorageAccount.Parse(_configuration["BlobStorageConnectionString"]);

            var blobClient = storageAccount.CreateCloudBlobClient();

            var buildingSiteNow = _buildingSiteRepository.Get(id);

            var container =
                blobClient.GetContainerReference(buildingSiteNow.BuildingSiteLocation.ToLower().Replace(" ", "-"));
            //await container.CreateIfNotExistsAsync();

            var folder = model.Title.ToLower().Replace(" ", "_");

            foreach (var file in model.Photos)
            {
                var idFile        = Guid.NewGuid();
                var fileExtension = Path.GetExtension(file.FileName);

                var blobName = $"{folder}/{idFile}{fileExtension}";

                var blobRef = container.GetBlockBlobReference(blobName);

                using (var stream = file.OpenReadStream())
                {
                    await blobRef.UploadFromStreamAsync(stream);
                }
            }

            if (ModelState.IsValid)
            {
                var todo = new Intervention()
                {
                    Title          = model.Title,
                    Type           = model.Type,
                    Notes          = model.Notes,
                    Cost           = model.Cost,
                    BuidingSiteId  = id,
                    PhotoFolderUri = $"{container.Name}/{folder}"
                };
                _interventionRepository.Insert(todo);

                return(RedirectToAction("../BuildingSite/Index"));
            }

            ModelState.AddModelError("", "Errore generico");

            return(View(model));
        }
Exemple #2
0
        public IActionResult Insert()
        {
            var model = new InterventionInsertViewModel();

            return(View(model));
        }