public async Task <IActionResult> ShowPropertyFullDetails(int propertyId)
        {
            var propertyDetails = await _repo.GetPropertyDetails(propertyId);

            var vm = propertyDetails.ToViewModel(RealEstateHelpers.IsUserAdmin(User));

            return(View("Details", vm));
        }
        /// <summary>
        /// Stores an image in the configured Azure blob storage account.
        /// </summary>
        /// <param name="filename">name of the blob</param>
        /// <param name="imageStream">image data to be saved</param>
        /// <returns></returns>
        public async Task <string> StoreImage(string filename, Stream imageStream)
        {
            // create connection to Azure Storage
            var storageAccount = new CloudStorageAccount(
                // Credentials.
                new StorageCredentials(_accountName, _accountKey),
                // Base URI of the blob storage.
                new StorageUri(new Uri(_baseUrl)),
                // URIs of other storage options we are not using (eg Queue).
                null, null, null);

            var blobClient = storageAccount.CreateCloudBlobClient();

            // Get access to the container and blob.
            var container = blobClient.GetContainerReference(_containerName);

            await container.CreateIfNotExistsAsync();

            await container.SetPermissionsAsync(new BlobContainerPermissions()
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            var blob = container.GetBlockBlobReference(filename);

            // Delete the blob if it exists
            var blobExists = await blob.ExistsAsync();

            if (blobExists)
            {
                await blob.DeleteAsync();
            }

            await blob.UploadFromStreamAsync(imageStream);

            // The image's URL is in the format "BASE_URL/CONTAINER_NAME/FILENAME".
            var fullImagePath = RealEstateHelpers.CombineUri(_baseUrl, _containerName, filename);

            return(fullImagePath);
        }
Exemplo n.º 3
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            // Using fluent API to configure entities: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/fluent/types-and-properties
            builder.Entity <Property>()
            .HasMany(p => p.Assets)
            .WithOne(a => a.Property);

            builder.Entity <Property>()
            .ToTable("Properties")
            .HasKey(x => x.Id);

            builder.Entity <PropertyAsset>()
            .ToTable("PropertyAssets")
            .HasKey(x => x.Id);

            // Seed some data: https://docs.microsoft.com/en-us/ef/core/modeling/data-seeding
            var(properties, assets) = RealEstateHelpers.CreateProperties();
            builder.Entity <Property>().HasData(properties);
            builder.Entity <PropertyAsset>().HasData(assets);
        }