public async Task <BlobResultForSaving> UploadImageAsync(NewIMageModel imageToUpload) { // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); // Retrieve reference to a blob named "myblob". CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob"); if (await container.CreateIfNotExistsAsync()) { // Enable public access on the newly created "images" container await container.SetPermissionsAsync( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); } string imageName = imageToUpload.Id + ".png"; CloudBlockBlob cloudBlockBlob = container.GetBlockBlobReference(imageName); cloudBlockBlob.Properties.ContentType = imageToUpload.FileExtention; await cloudBlockBlob.UploadFromStreamAsync(imageToUpload.File.InputStream); BlobResultForSaving res = new BlobResultForSaving() { URL = cloudBlockBlob.Uri.ToString(), BaseUrl = storageAccount.BlobEndpoint.ToString(), FileName = imageName }; return(res); }
public async Task <ActionResult> Delete(string Id) { ViewBag.Colors = from o in data.ProductColors select new { Id = o.Id, Name = o.ProductColorName }; var _product = await data.Products.FindAsync(Id); List <CheckBoxModel> cbCategoriesList = new List <CheckBoxModel>(); List <CheckBoxModel> cbGenderList = new List <CheckBoxModel>(); foreach (var x in data.ProductCategories) { var IsSelected = false; if (_product.ProductCategories.Where(i => i.Id == x.Id).Count() == 1) { IsSelected = true; } else { IsSelected = false; } CheckBoxModel cb = new Models.CheckBoxModel() { Id = x.Id.ToString(), IsSelected = IsSelected, Label = x.CategoryName }; cbCategoriesList.Add(cb); } foreach (var x in common.GetGenders()) { var IsSelected = false; if (_product.ProductsInGenders.Where(i => i.Gender == x).Count() == 1) { IsSelected = true; } else { IsSelected = false; } CheckBoxModel cb = new CheckBoxModel() { Id = x, IsSelected = IsSelected, Label = x }; cbGenderList.Add(cb); } var _tmpImages = from o in _product.ProductDetails select o.ProductDetailImages; List <NewIMageModel> _images = new List <NewIMageModel>(); foreach (var x in _tmpImages) { foreach (var y in x) { NewIMageModel _imgModel = new NewIMageModel() { Id = y.Id, Url = y.ImageUrl }; _images.Add(_imgModel); } } NewProductModel model = new NewProductModel() { Id = _product.Id, Amount = _product.Amount, Description = _product.Description, Name = _product.ProductName, ColordId = _product.ProductDetails.Select(i => i.ProductColor.Id).First(), MeasurementId = _product.ProductDetails.Select(i => i.ProductMeasurement.Id).First(), Categories = cbCategoriesList, Genders = cbGenderList, Images = _images }; string[] catArray = cbCategoriesList.Where(i => i.IsSelected).Select(i => i.Id).ToArray(); ViewBag.Measurements = await(from p in data.ProductMeasurements. Where(a => catArray.Contains(a.ProductCategoryId.ToString())) select new { Id = p.Id, Name = p.MeasurementName, Value = p.MeasurementValue, }).ToListAsync(); ViewBag.Brands = from o in data.ProductBrands select new { Id = o.Id, Name = o.Name }; ViewBag.Colors = from o in data.ProductColors select new { Id = o.Id, Color = o.ProductColorName }; return(View(model)); }