public async Task <IActionResult> DeletePhotos([Bind("_id", "ToBeDelete")] List <PhotoModelForDelete> photos)
        {
            List <string> blobsReferenceName = new List <string>();

            using (
                MyBlobStorageManager myBlobStorageManager = new MyBlobStorageManager(Variables.BlobStorageConnectionString, _userId))
            {
                foreach (var photo in photos)
                {
                    if (photo.ToBeDelete)
                    {
                        var photosName = await _myMongoDbManager.GetPhotosNameAsync(new ObjectId(photo._id));

                        blobsReferenceName.AddRange(photosName);
                        _myMongoDbManager.RemovePhotoAsync(new ObjectId(photo._id));
                    }
                }

                foreach (var name in blobsReferenceName)
                {
                    await myBlobStorageManager.RemoveDocumentByNameAsync(name);
                }
            }

            return(RedirectToAction("Gallery", "Gallery"));
        }
Esempio n. 2
0
        public async Task <List <PhotoModelForMap> > GetPhotosForMapAsync(string id)
        {
            using (CollectionManager <PhotoModel> collectionManager =
                       new CollectionManager <PhotoModel>(database, Variables.MongoDBPhotosCollectionName))
                using (MyBlobStorageManager myBlobStorageManager =
                           new MyBlobStorageManager(Variables.BlobStorageConnectionString, id))
                {
                    var photosForMap = new List <PhotoModelForMap>();

                    var res = await collectionManager.mongoCollection.Find(
                        x => x.PhotoGpsLatitude != null &&
                        x.PhotoGpsLongitude != null).ToListAsync();

                    var sasKey = myBlobStorageManager.GetContainerSasUri(10);

                    foreach (var photo in res)
                    {
                        photosForMap.Add(new PhotoModelForMap
                        {
                            _id            = photo._id.ToString(),
                            IconPath       = photo.PhotoPhatIcon + sasKey,
                            PhotoName      = photo.ImageName,
                            PhotoLatitude  = photo.PhotoGpsLatitude ?? 0,
                            PhotoLongitude = photo.PhotoGpsLongitude ?? 0
                        });
                    }

                    return(photosForMap);
                }
        }
        public IActionResult SharePhoto(SharePhotoModel sharePhotoModel)
        {
            int totalMinutes = (int)sharePhotoModel.DateOfExpire.Subtract(DateTime.Now).TotalMinutes;

            using (MyBlobStorageManager myBlobStorageManager = new MyBlobStorageManager(Variables.BlobStorageConnectionString, _userId))
            {
                sharePhotoModel.UriForSheredImage = sharePhotoModel.PhotoUri + myBlobStorageManager.GetContainerSasUri(totalMinutes);
            }

            return(RedirectToAction("SinglePhoto", new { photoId = sharePhotoModel._id, sharePhotoModel.UriForSheredImage }));
        }
        public IActionResult GetBlobDownload(PhotoModelForDownload photo)
        {
            using (MyBlobStorageManager myBlobStorageManager = new MyBlobStorageManager(Variables.BlobStorageConnectionString, _userId))
            {
                photo.Link += myBlobStorageManager.GetContainerSasUri();

                var net         = new System.Net.WebClient();
                var data        = net.DownloadData(photo.Link);
                var content     = new System.IO.MemoryStream(data);
                var contentType = "APPLICATION/octet-stream";
                var fileName    = photo.OriginalName;
                return(File(content, contentType, fileName));
            }
        }
Esempio n. 5
0
        public async void DeleteUserData()
        {
            using (var myMongoDBManager =
                       new MyMongoDBManager(Variables.MongoDBConnectionStringRW, Variables.MongoDBDatbaseName))
                using (var myBlobStorageManager =
                           new MyBlobStorageManager(Variables.BlobStorageConnectionString, _userId))
                {
                    var response = await myBlobStorageManager.DeleteUserContainerAsync();

                    if (response.IsSuccess)
                    {
                        var photos = await myMongoDBManager.GetPhotoForGalleryAsync(_userId);

                        foreach (var photo in photos)
                        {
                            myMongoDBManager.RemovePhotoAsync(photo._id);
                        }
                    }
                }
        }
Esempio n. 6
0
        public IActionResult Gallery(string tag = "", bool multipleDeletes = false)
        {
            var          photos       = _myMongoDbManager.GetPhotoForGalleryAsync(_userId, tag);
            GalleryModel galleryModel = null;

            using (MyBlobStorageManager myBlobStorageManager =
                       new MyBlobStorageManager(Variables.BlobStorageConnectionString, _userId))
            {
                string sasUri = myBlobStorageManager.GetContainerSasUri();

                photos.Result.ForEach(x => x.PhotoPhatPreview += sasUri);

                galleryModel = new GalleryModel()
                {
                    Photos          = photos.Result,
                    LastTag         = tag,
                    MultipleDeletes = multipleDeletes
                };
            }

            return(View(galleryModel));
        }
        public async Task <IActionResult> SinglePhoto(string photoId, string UriForSheredImage = "")
        {
            ObjectId _id = new ObjectId(photoId);
            PhotoModelForSinglePage photo;

            var photoResponse = await _myMongoDbManager.GetPhotoAsync(_id);

            if (photoResponse == null)
            {
                return(Content("Wrong parameter"));
            }

            photo = new PhotoModelForSinglePage(photoResponse);
            photo.UriForSheredImage = UriForSheredImage;

            using (MyBlobStorageManager myBlobStorageManager = new MyBlobStorageManager(Variables.BlobStorageConnectionString, _userId))
            {
                photo.LPhotoPhatOriginalSizeWithSasKey = photo.PhotoPhatOriginalSize + myBlobStorageManager.GetContainerSasUri();
            }

            return(View(photo));
        }
Esempio n. 8
0
        public async Task <PhotoModelForMap> GetPhotoForMapAsync(string id, ObjectId _id)
        {
            using (CollectionManager <PhotoModel> collectionManager =
                       new CollectionManager <PhotoModel>(database, Variables.MongoDBPhotosCollectionName))
                using (MyBlobStorageManager myBlobStorageManager =
                           new MyBlobStorageManager(Variables.BlobStorageConnectionString, id))
                {
                    var res = await collectionManager.mongoCollection.Find(
                        x => x._id == _id).FirstOrDefaultAsync();

                    var sasKey = myBlobStorageManager.GetContainerSasUri(10);

                    var photoForMap = new PhotoModelForMap()
                    {
                        _id            = res._id.ToString(),
                        IconPath       = res.PhotoPhatIcon + sasKey,
                        PhotoName      = res.ImageName,
                        PhotoLatitude  = res.PhotoGpsLatitude ?? 0,
                        PhotoLongitude = res.PhotoGpsLongitude ?? 0
                    };

                    return(photoForMap);
                }
        }