public IActionResult CreateIntervento(int idCantiere) { InterventoViewModel i = new InterventoViewModel(); i.IdCantiere = idCantiere; return(View(i)); }
public async Task <IActionResult> CreateIntervento(InterventoViewModel intervento) { Intervento i = new Intervento { IdCantiere = intervento.IdCantiere, Note = intervento.Note, StimaCosto = intervento.StimaCosto, Tipo = intervento.Tipo }; if (intervento.Photo != null) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_configuration["ConnectionStrings:StorageAccountCS"]); CloudBlobClient cbc = storageAccount.CreateCloudBlobClient(); var photoContainer = cbc.GetContainerReference("interventi"); var id = Guid.NewGuid(); var fileExtension = Path.GetExtension(intervento.Photo.FileName); var blobName = $"photo/{id}{fileExtension}"; var blobRef = photoContainer.GetBlockBlobReference(blobName); using (var stream = intervento.Photo.OpenReadStream()) { await blobRef.UploadFromStreamAsync(stream); } i.UriPhoto = blobRef.Uri.AbsoluteUri; } await _interventoRepo.InsertIntervento(i); return(RedirectToAction("GetCantiereDetails", intervento.IdCantiere)); }