コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileDetail"></param>
        /// <returns></returns>
        public static string GenerateFileName(AzureBlobFile fileDetail)
        {
            StringBuilder strBuilder = new StringBuilder(GenerateFilePath(fileDetail));

            if (fileDetail.InterfaceFileType == InterfaceFileTypes.Artwork)
            {
                strBuilder.Append(fileDetail.AfterHeaderSecond).Append("_");
            }

            //add file guid
            strBuilder.Append(fileDetail.FileGuid);

            //add file extension
            if (fileDetail.FileExtension == FileExtensions.mp4 || fileDetail.FileExtension == FileExtensions.png)
            {
                strBuilder.Append(".");
            }
            else
            {
                strBuilder.Append("_");
            }

            strBuilder.Append(fileDetail.FileExtension.ToString().ToLower());

            return(strBuilder.ToString());
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Name,Description,FullName,Order,Active,IconUrl,ImageUrl,ThumbUrl")] ArtistModel artistModel, IFormFile IconUrlFile, IFormFile ImageUrlFile, IFormFile ThumbUrlFile)
        {
            //check the model is valid
            if (ModelState.IsValid)
            {
                artistModel.Active       = true;
                artistModel.CreationTime = DateTime.UtcNow;
                artistModel.Guid         = Guid.NewGuid().ToString();

                #region Upload File to azure storage

                List <IFormFile> allFiles = new List <IFormFile> {
                    IconUrlFile, ImageUrlFile, ThumbUrlFile
                };

                foreach (IFormFile file in allFiles)
                {
                    if (file == null)
                    {
                        continue;
                    }

                    //create file class to use uploading files
                    AzureBlobFile azureBlobFile = new AzureBlobFile(Enums.InterfaceFileTypes.Artist,
                                                                    file,
                                                                    await file.GetBytes(),
                                                                    artistModel.Name,
                                                                    string.Empty,
                                                                    Configuration.GetConnectionString("AccessKey"),
                                                                    Configuration.GetConnectionString("ContainerName"));

                    //create azure storace service
                    BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                    //upload file to azure storage
                    string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                    //Set azure storage file nime into the model property
                    Helper.Helper.UpdateProperty(artistModel, azureBlobFile.PropertyName, uploadedFileName);
                }

                #endregion

                _context.Add(artistModel);
                await _context.SaveChangesAsync();

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

            return(View(artistModel));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Title,Description,ExhibitionId,Order,Active,ScanRadius,ShowOnMap,VaGuid,Va,IconUrl,MapIconUrl,MapUrl,ThumbUrl,IconUrlFile,MapIconUrlFile,MapUrlFile,ThumbUrlFile")] ExhibitionRoomModel exhibitionRoomModel)
        {
            if (ModelState.IsValid)
            {
                exhibitionRoomModel.Active = true;

                #region Upload File to azure storage

                List <IFormFile> allFiles = new List <IFormFile> {
                    exhibitionRoomModel.MapIconUrlFile, exhibitionRoomModel.MapUrlFile, exhibitionRoomModel.ThumbUrlFile, exhibitionRoomModel.IconUrlFile
                };

                foreach (IFormFile file in allFiles)
                {
                    if (file == null)
                    {
                        continue;
                    }

                    //create file class to use uploading files
                    AzureBlobFile azureBlobFile = new AzureBlobFile(Enums.InterfaceFileTypes.Exhibition,
                                                                    file,
                                                                    await file.GetBytes(),
                                                                    exhibitionRoomModel.Title,
                                                                    string.Empty,
                                                                    Configuration.GetConnectionString("AccessKey"),
                                                                    Configuration.GetConnectionString("ContainerName"));

                    //create azure storace service
                    BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                    //upload file to azure storage
                    string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                    //Set azure storage file nime into the model property
                    Helper.Helper.UpdateProperty(exhibitionRoomModel, azureBlobFile.PropertyName, uploadedFileName);
                }

                #endregion

                _context.Add(exhibitionRoomModel);
                await _context.SaveChangesAsync();

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

            PopulateExhibitionsDropDownList(0);

            return(View(exhibitionRoomModel));
        }
コード例 #4
0
 public string UploadFileToBlob(AzureBlobFile fileDetail)
 {
     try
     {
         var _task = Task.Run(() => this.UploadFileToBlobAsync(fileDetail.FileBytes, fileDetail.MimeType, fileDetail));
         _task.Wait();
         string fileUrl = _task.Result;
         return(fileUrl);
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileDetail"></param>
        /// <returns></returns>
        public static string GenerateFilePath(AzureBlobFile fileDetail)
        {
            StringBuilder strBuilder = new StringBuilder();

            //add header
            strBuilder.Append(fileDetail.InterfaceFileType.ToString().ToLower());

            //add file type
            strBuilder.Append("/").Append(fileDetail.FileType.ToString().ToLower());

            //add first part of the url
            strBuilder.Append("/").Append(fileDetail.AfterHeaderFirst).Append("/");

            return(strBuilder.ToString());
        }
コード例 #6
0
        public async Task <ActionResult> Edit(long?id, ArtistModel artistModel)
        {
            if (id == null)
            {
                return(NotFound());
            }

            //getting the artist
            var artistToUpdate = await _context.Artists.FirstOrDefaultAsync(m => m.ArtistId == id);

            if (ModelState.IsValid)
            {
                List <IFormFile> allFiles = new List <IFormFile> {
                    artistModel.IconUrlFile, artistModel.ImageUrlFile, artistModel.ThumbUrlFile
                };

                //preparing the properties to update
                if (await TryUpdateModelAsync <ArtistModel>(
                        artistToUpdate,
                        "",
                        i => i.Name,
                        i => i.Description,
                        i => i.FullName,
                        i => i.Order,
                        i => i.Active,
                        i => i.IconUrl,
                        i => i.ImageUrl,
                        i => i.ThumbUrl))
                {
                    try
                    {
                        #region Upload File to azure storage

                        foreach (IFormFile file in allFiles)
                        {
                            if (file == null)
                            {
                                continue;
                            }

                            //create file class to use uploading files
                            AzureBlobFile azureBlobFile = new AzureBlobFile(Enums.InterfaceFileTypes.Artist,
                                                                            file,
                                                                            await file.GetBytes(),
                                                                            artistToUpdate.Name,
                                                                            string.Empty,
                                                                            Configuration.GetConnectionString("AccessKey"),
                                                                            Configuration.GetConnectionString("ContainerName"));

                            //create azure storace service
                            BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                            //upload file to azure storage
                            string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                            //if the previous file exists delete
                            //If necessary, open the remove option
                            //string previousPropertyBlobUrlToUpdate = Helper.Helper.GetPropertyValue(artistToUpdate, azureBlobFile.PropertyName);

                            //if (!string.IsNullOrEmpty(previousPropertyBlobUrlToUpdate))
                            //{
                            //    objBlobService.DeleteBlobData(previousPropertyBlobUrlToUpdate, azureBlobFile.FilePath);
                            //}

                            //Set azure storage file nime into the model property
                            Helper.Helper.UpdateProperty(artistToUpdate, azureBlobFile.PropertyName, uploadedFileName);
                        }

                        #endregion

                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateException ex)
                    {
                        _logger.LogError($"Artist -> Edit -> exception: {ex.ToString()}");

                        //Log the error (uncomment ex variable name and write a log.)
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(View(artistToUpdate));
        }
コード例 #7
0
        public async Task <ActionResult> Edit(long?id, [Bind("ArtworkId,Name,Description,Creation,ArtistId,Type,SourceMeta,Guid,ObjectUrl,ImageUrl,IconUrl,ThumbUrl,SignUrl,TradeUrl,WpId,PrefabName,MarshalCode,SizeDescription,Year,EditionSize,Color,Size,ApSize,Preload,Active,IosFile,AndroidFile,ImageUrlFile,IconUrlFile,ThumbUrlFile,SignUrlFile,TradeUrlFile")] ArtworkModel artworkModel)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var artworkToUpdate = await _context.Artworks.Include(x => x.Artist).FirstOrDefaultAsync(m => m.ArtworkId == id);

                List <IFormFile> allFiles = new List <IFormFile>
                {
                    artworkModel.IconUrlFile,
                    artworkModel.ImageUrlFile,
                    artworkModel.ThumbUrlFile,
                    artworkModel.TradeUrlFile,
                    artworkModel.SignUrlFile,
                    artworkModel.IosFile,
                    artworkModel.AndroidFile
                };

                if (await TryUpdateModelAsync <ArtworkModel>(
                        artworkToUpdate,
                        "",
                        i => i.Name,
                        i => i.Description,
                        i => i.ArtistId,
                        i => i.Type,
                        i => i.SourceMeta,
                        i => i.ObjectUrl,
                        i => i.PrefabName,
                        i => i.MarshalCode,
                        i => i.SizeDescription,
                        i => i.Size,
                        i => i.Active,
                        i => i.Year,
                        i => i.EditionSize,
                        i => i.Color,
                        i => i.ImageUrl,
                        i => i.ThumbUrl,
                        i => i.IconUrl,
                        i => i.TradeUrl,
                        i => i.SignUrl))
                {
                    try
                    {
                        #region Upload File to azure storage

                        foreach (IFormFile file in allFiles)
                        {
                            if (file == null)
                            {
                                continue;
                            }

                            //create file class to use uploading files
                            AzureBlobFile azureBlobFile = new AzureBlobFile(InterfaceFileTypes.Artwork,
                                                                            file,
                                                                            await file.GetBytes(),
                                                                            artworkToUpdate.Artist.Name,
                                                                            artworkToUpdate.Name,
                                                                            Configuration.GetConnectionString("AccessKey"),
                                                                            Configuration.GetConnectionString("ContainerName"));

                            //create azure storace service
                            BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                            //upload file to azure storage
                            string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                            //if the previous file exists delete
                            //string previousPropertyBlobUrlToUpdate = Helper.Helper.GetPropertyValue(artworkToUpdate, azureBlobFile.PropertyName);
                            //If necessary, open the remove option
                            //if (!string.IsNullOrEmpty(previousPropertyBlobUrlToUpdate))
                            //{
                            //    objBlobService.DeleteBlobData(previousPropertyBlobUrlToUpdate, azureBlobFile.FilePath);
                            //}

                            //Set azure storage file nime into the model property
                            Helper.Helper.UpdateProperty(artworkToUpdate, azureBlobFile.PropertyName, uploadedFileName);
                        }

                        #endregion

                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateException ex)
                    {
                        _logger.LogError($"Artwork -> Edit -> exception: {ex.ToString()}");

                        //Log the error (uncomment ex variable name and write a log.)
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }

            PopulateTypesDropDownList(artworkModel.Type);
            PopulateArtistsDropDownList(artworkModel.ArtistId);

            return(View(artworkModel));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("Name,Description,ArtistId,Type,SourceMeta,WpId,PrefabName,MarshalCode,SizeDescription,Year,EditionSize,Color,Size,Active,IosFile,AndroidFile,ImageUrlFile,IconUrlFile,ThumbUrlFile,SignUrlFile,TradeUrlFile")] ArtworkModel artworkModel)
        {
            if (ModelState.IsValid)
            {
                artworkModel.Active   = true;
                artworkModel.Guid     = Guid.NewGuid().ToString();
                artworkModel.Creation = DateTime.UtcNow;
                artworkModel.WpId     = Guid.NewGuid().ToString();
                artworkModel.ApSize   = 1;
                artworkModel.Preload  = false;
                artworkModel.Artist   = await _context.Artists.FirstOrDefaultAsync(artist => artist.ArtistId == artworkModel.ArtistId);

                #region Upload File to azure storage

                List <IFormFile> allFiles = new List <IFormFile>
                {
                    artworkModel.IconUrlFile,
                    artworkModel.ImageUrlFile,
                    artworkModel.ThumbUrlFile,
                    artworkModel.TradeUrlFile,
                    artworkModel.SignUrlFile,
                    artworkModel.IosFile,
                    artworkModel.AndroidFile
                };

                foreach (IFormFile file in allFiles)
                {
                    if (file == null)
                    {
                        continue;
                    }

                    //create file class to use uploading files
                    AzureBlobFile azureBlobFile = new AzureBlobFile(InterfaceFileTypes.Artwork,
                                                                    file,
                                                                    await file.GetBytes(),
                                                                    artworkModel.Artist.Name,
                                                                    artworkModel.Name,
                                                                    Configuration.GetConnectionString("AccessKey"),
                                                                    Configuration.GetConnectionString("ContainerName"));

                    //create azure storace service
                    BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                    //upload file to azure storage
                    string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                    //Set azure storage file nime into the model property
                    Helper.Helper.UpdateProperty(artworkModel, azureBlobFile.PropertyName, uploadedFileName);
                }

                #endregion

                _context.Add(artworkModel);
                await _context.SaveChangesAsync();

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

            PopulateTypesDropDownList(0);
            PopulateArtistsDropDownList(0);

            return(View(artworkModel));
        }
コード例 #9
0
        public async Task <ActionResult> Edit(long?id, [Bind("ExhibitionId,OwnerId,Title,Description,GeoFenced,Latitude,Longitude,Radius,MetaData,Created,StartDate,EndDate,Active,Guid,Order,MapUrl,IconUrl,ThumbUrl,MainMapUrl,IntroUrl,Howto,MapUrlFile,IconUrlFile,ThumbUrlFile,MainMapUrlFile,IntroUrlFile,HowtoFile,UseGps,ScanRadius,ShowRadius,ViewRadius,ExhibitionArtworkIds")] ExhibitionModel exhibitionModel)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                List <IFormFile> allFiles = new List <IFormFile> {
                    exhibitionModel.IconUrlFile, exhibitionModel.ThumbUrlFile, exhibitionModel.MainMapUrlFile, exhibitionModel.MapUrlFile, exhibitionModel.IntroUrlFile, exhibitionModel.HowtoFile
                };

                var exhibitionToUpdate = await _context.Exhibitions
                                         .FirstOrDefaultAsync(m => m.ExhibitionId == id);

                if (await TryUpdateModelAsync <ExhibitionModel>(
                        exhibitionToUpdate,
                        "",
                        i => i.Title,
                        i => i.Description,
                        i => i.OwnerId,
                        i => i.GeoFenced,
                        i => i.Latitude,
                        i => i.Longitude,
                        i => i.Radius,
                        i => i.StartDate,
                        i => i.EndDate,
                        i => i.Active,
                        i => i.Order,
                        i => i.UseGps,
                        i => i.ScanRadius,
                        i => i.ShowRadius,
                        i => i.ViewRadius,
                        i => i.MainMapUrl,
                        i => i.MapUrl,
                        i => i.IconUrl,
                        i => i.ThumbUrl,
                        i => i.IntroUrl,
                        i => i.Howto))
                {
                    try
                    {
                        #region Upload File to azure storage

                        foreach (IFormFile file in allFiles)
                        {
                            if (file == null)
                            {
                                continue;
                            }

                            //create file class to use uploading files
                            AzureBlobFile azureBlobFile = new AzureBlobFile(InterfaceFileTypes.Exhibition,
                                                                            file,
                                                                            await file.GetBytes(),
                                                                            exhibitionToUpdate.Title,
                                                                            string.Empty,
                                                                            Configuration.GetConnectionString("AccessKey"),
                                                                            Configuration.GetConnectionString("ContainerName"));

                            //create azure storace service
                            BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                            //upload file to azure storage
                            string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                            //if the previous file exists delete
                            //string previousPropertyBlobUrlToUpdate = Helper.Helper.GetPropertyValue(exhibitionToUpdate, azureBlobFile.PropertyName);
                            //If necessary, open the remove option
                            //if (!string.IsNullOrEmpty(previousPropertyBlobUrlToUpdate))
                            //{
                            //    objBlobService.DeleteBlobData(previousPropertyBlobUrlToUpdate, azureBlobFile.FilePath);
                            //}

                            //Set azure storage file nime into the model property
                            Helper.Helper.UpdateProperty(exhibitionToUpdate, azureBlobFile.PropertyName, uploadedFileName);
                        }

                        #endregion

                        #region Exhibition Artworks

                        IQueryable <ExhibitionArtworkModel> exhibitionArtworkModels = _context.ExhibitionArtworks.Where(where => where.ExhibitionId == id);

                        //there ara no selected artworks so that if any relation exists on the db must be deleted
                        if (exhibitionModel.ExhibitionArtworkIds != null && exhibitionModel.ExhibitionArtworkIds.Length == 0 && exhibitionArtworkModels.Count() > 0)
                        {
                            _context.ExhibitionArtworks.RemoveRange(exhibitionArtworkModels);
                        }

                        //there are selected artworks on UI
                        if (exhibitionModel.ExhibitionArtworkIds != null && exhibitionModel.ExhibitionArtworkIds.Length > 0)
                        {
                            //there is no relation record for the exhibiton
                            //add items to db
                            if (exhibitionArtworkModels.Count() == 0)
                            {
                                addExhibitionArtworkModel((Int64)id, exhibitionModel.ExhibitionArtworkIds.ToList());
                            }
                            else//there are items on the db and selected items too
                            {
                                var newListArtworkList = exhibitionModel.ExhibitionArtworkIds.Except(exhibitionArtworkModels.Select(select => select.ArtworkId).ToList());
                                IQueryable <ExhibitionArtworkModel> itemsToBeRemoved = exhibitionArtworkModels.Where(where => !exhibitionModel.ExhibitionArtworkIds.Any(any => any == where.ArtworkId));

                                //some items removed from the list
                                if (itemsToBeRemoved.Count() > 0)
                                {
                                    _context.ExhibitionArtworks.RemoveRange(itemsToBeRemoved);
                                }

                                //there are new items added
                                if (newListArtworkList.Count() > 0)
                                {
                                    //add the new added items
                                    addExhibitionArtworkModel((Int64)id, newListArtworkList.ToList());
                                }
                            }
                        }

                        #endregion Exhibition Artworks

                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateException ex)
                    {
                        _logger.LogError($"Exhibition -> Edit -> exception: {ex.ToString()}");

                        //Log the error (uncomment ex variable name and write a log.)
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }

            PopulateExhibitionRoomsDropDownList(exhibitionModel.ExhibitionId);

            ViewBag.UserList    = GetUserList(exhibitionModel.OwnerId);
            ViewBag.ArtworkList = GetArtworkNewList(exhibitionModel.ExhibitionId);

            exhibitionModel.ExhibitionArtworkIds = GetExhibitionArtworks(exhibitionModel.ExhibitionId).Select(select => select.ArtworkId).ToArray();

            return(View(exhibitionModel));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("OwnerId,Title,Description,GeoFenced,Latitude,Longitude,Radius,MetaData,StartDate,EndDate,Active,Order,MapUrlFile,IconUrlFile,ThumbUrlFile,MainMapUrlFile,IntroUrlFile,HowtoFile,UseGps,ScanRadius,ShowRadius,ViewRadius")] ExhibitionModel exhibitionModel)
        {
            if (ModelState.IsValid)
            {
                exhibitionModel.Active  = true;
                exhibitionModel.Guid    = Guid.NewGuid().ToString();
                exhibitionModel.Created = DateTime.UtcNow;
                //exhibitionModel.WpId = Guid.NewGuid().ToString();

                #region Upload File to azure storage

                List <IFormFile> allFiles = new List <IFormFile>
                {
                    exhibitionModel.IconUrlFile,
                    exhibitionModel.ThumbUrlFile,
                    exhibitionModel.MainMapUrlFile,
                    exhibitionModel.MapUrlFile,
                    exhibitionModel.IntroUrlFile,
                    exhibitionModel.HowtoFile
                };

                foreach (IFormFile file in allFiles)
                {
                    if (file == null)
                    {
                        continue;
                    }

                    //create file class to use uploading files
                    AzureBlobFile azureBlobFile = new AzureBlobFile(Enums.InterfaceFileTypes.Exhibition,
                                                                    file,
                                                                    await file.GetBytes(),
                                                                    exhibitionModel.Title,
                                                                    string.Empty,
                                                                    Configuration.GetConnectionString("AccessKey"),
                                                                    Configuration.GetConnectionString("ContainerName"));

                    //create azure storace service
                    BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                    //upload file to azure storage
                    string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                    //Set azure storage file nime into the model property
                    Helper.Helper.UpdateProperty(exhibitionModel, azureBlobFile.PropertyName, uploadedFileName);
                }

                #endregion

                _context.Add(exhibitionModel);
                await _context.SaveChangesAsync();

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

            PopulateExhibitionRoomsDropDownList(exhibitionModel.ExhibitionId);

            ViewBag.UserList    = GetUserList(exhibitionModel.OwnerId);
            ViewBag.ArtworkList = GetArtworkNewList(exhibitionModel.ExhibitionId);

            exhibitionModel.ExhibitionArtworkIds = new List <long>().ToArray();

            return(View(exhibitionModel));
        }
コード例 #11
0
        public async Task <ActionResult> Edit(AssetModel assetModel)
        {
            string key = "hero_intro_image";

            //getting the artist
            var assetToUpdate = await _context.Assets.FirstOrDefaultAsync(m => m.AssetKey == key);

            if (ModelState.IsValid && assetModel.AssetValueFile != null)
            {
                //preparing the properties to update
                if (await TryUpdateModelAsync <AssetModel>(
                        assetToUpdate,
                        "",
                        i => i.AssetKey,
                        i => i.AssetValue))
                {
                    try
                    {
                        #region Upload File to azure storage

                        //create file class to use uploading files
                        AzureBlobFile azureBlobFile = new AzureBlobFile(Enums.InterfaceFileTypes.Asset,
                                                                        assetModel.AssetValueFile,
                                                                        await assetModel.AssetValueFile.GetBytes(),
                                                                        assetToUpdate.AssetKey,
                                                                        string.Empty,
                                                                        Configuration.GetConnectionString("AccessKey"),
                                                                        Configuration.GetConnectionString("ContainerName"));

                        //create azure storace service
                        BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                        //upload file to azure storage
                        string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);

                        //if the previous file exists delete
                        //If necessary, open the remove option
                        //string previousPropertyBlobUrlToUpdate = Helper.Helper.GetPropertyValue(artistToUpdate, azureBlobFile.PropertyName);

                        //if (!string.IsNullOrEmpty(previousPropertyBlobUrlToUpdate))
                        //{
                        //    objBlobService.DeleteBlobData(previousPropertyBlobUrlToUpdate, azureBlobFile.FilePath);
                        //}

                        //Set azure storage file nime into the model property
                        Helper.Helper.UpdateProperty(assetToUpdate, azureBlobFile.PropertyName, uploadedFileName);


                        #endregion

                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateException ex)
                    {
                        _logger.LogError($"Artist -> Edit -> exception: {ex.ToString()}");

                        //Log the error (uncomment ex variable name and write a log.)
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                    return(RedirectToAction(nameof(HomeController.Index), "Home"));
                }
            }

            return(View(assetToUpdate));
        }
コード例 #12
0
        public async Task <ActionResult> Edit(long?id, [Bind("RoomId,Title,Description,ExhibitionId,Order,Active,ScanRadius,ShowOnMap,VaGuid,Va,IconUrl,MapIconUrl,MapUrl,ThumbUrl,IconUrlFile,MapIconUrlFile,MapUrlFile,ThumbUrlFile")] ExhibitionRoomModel exhibitionRoomModel)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var exhibitionRoomToUpdate = await _context.ExhibitionRooms.Include(d => d.Exhibition)
                                             .FirstOrDefaultAsync(m => m.RoomId == id);

                List <IFormFile> allFiles = new List <IFormFile> {
                    exhibitionRoomModel.MapIconUrlFile, exhibitionRoomModel.MapUrlFile, exhibitionRoomModel.ThumbUrlFile, exhibitionRoomModel.IconUrlFile
                };

                if (await TryUpdateModelAsync <ExhibitionRoomModel>(
                        exhibitionRoomToUpdate,
                        "",
                        i => i.Title,
                        i => i.Description,
                        i => i.ExhibitionId,
                        i => i.Order, i =>
                        i.ScanRadius, i =>
                        i.ShowOnMap, i =>
                        i.VaGuid, i => i.Va,
                        i => i.MapIconUrl,
                        i => i.MapUrl,
                        i => i.ThumbUrl,
                        i => i.IconUrl))
                {
                    try
                    {
                        #region Upload File to azure storage

                        foreach (IFormFile file in allFiles)
                        {
                            if (file == null)
                            {
                                continue;
                            }

                            //create file class to use uploading files
                            AzureBlobFile azureBlobFile = new AzureBlobFile(InterfaceFileTypes.Exhibition,
                                                                            file,
                                                                            await file.GetBytes(),
                                                                            exhibitionRoomToUpdate.Title,
                                                                            string.Empty,
                                                                            Configuration.GetConnectionString("AccessKey"),
                                                                            Configuration.GetConnectionString("ContainerName"));

                            //create azure storace service
                            BlobStorageService objBlobService = new BlobStorageService(azureBlobFile.AccessKey, azureBlobFile.ContainerName);

                            //upload file to azure storage
                            string uploadedFileName = objBlobService.UploadFileToBlob(azureBlobFile);
                            //If necessary, open the remove option
                            //if the previous file exists delete
                            //string previousPropertyBlobUrlToUpdate = Helper.Helper.GetPropertyValue(exhibitionRoomToUpdate, azureBlobFile.PropertyName);

                            //if (!string.IsNullOrEmpty(previousPropertyBlobUrlToUpdate))
                            //{
                            //    objBlobService.DeleteBlobData(previousPropertyBlobUrlToUpdate, azureBlobFile.FilePath);
                            //}

                            //Set azure storage file nime into the model property
                            Helper.Helper.UpdateProperty(exhibitionRoomToUpdate, azureBlobFile.PropertyName, uploadedFileName);
                        }

                        #endregion

                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateException ex)
                    {
                        _logger.LogError($"ExhibitionRoom -> Edit -> exception: {ex.ToString()}");

                        //Log the error (uncomment ex variable name and write a log.)
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }

            PopulateExhibitionsDropDownList(exhibitionRoomModel.ExhibitionId);

            return(View(exhibitionRoomModel));
        }
コード例 #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileData"></param>
        /// <param name="fileMimeType"></param>
        /// <param name="fileDetail"></param>
        /// <param name="filePathToDelete"></param>
        /// <returns></returns>
        private async Task <string> UploadFileToBlobAsync(byte[] fileData, string fileMimeType, AzureBlobFile fileDetail)
        {
            try
            {
                CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(this._accessKey);
                CloudBlobClient     cloudBlobClient     = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer  cloudBlobContainer  = cloudBlobClient.GetContainerReference(this._containerName);


                string fileName = Helper.Helper.GenerateFileName(fileDetail);

                if (await cloudBlobContainer.CreateIfNotExistsAsync())
                {
                    await cloudBlobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
                }

                if (fileName != null && fileData != null)
                {
                    CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(fileName);
                    cloudBlockBlob.Properties.ContentType = fileMimeType;
                    await cloudBlockBlob.UploadFromByteArrayAsync(fileData, 0, fileData.Length);

                    return(cloudBlockBlob.Uri.AbsoluteUri);
                }
                return("");
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }