Пример #1
0
        public async Task <IActionResult> RequestForm([Bind("ActivityId", "ActivityName", "Description", "ActivityDate", "Price", "ClientId")] Activity activity, IFormFile file)
        {
            if (file == null)
            {
                return(Content("File is not selected"));
            }
            Path.GetTempFileName();
            if (ModelState.IsValid)
            {
                activity.ClientId = (long)HttpContext.Session.GetInt32("token");
                _context.Activity.Add(activity);
            }
            await _context.SaveChangesAsync();

            CloudBlobContainer container      = BlobsController.GetClouldBlobContainer();
            CloudBlockBlob     cloudBlockBlob = container.GetBlockBlobReference(activity.ActivityId + "_" + file.FileName);
            var stream = file.OpenReadStream();

            await cloudBlockBlob.UploadFromStreamAsync(stream);

            stream.Dispose();

            activity.RequestFormPath = "https://whatsapstorage.blob.core.windows.net/whatsap/" + activity.ActivityId + "_" + file.FileName;
            _context.Update(activity);
            await _context.SaveChangesAsync();


            return(RedirectToAction("ActivityRequest", "Client", new { id = activity.ClientId }));
        }
Пример #2
0
        public async Task <IActionResult> Download()
        {
            var filename = "ActivityReqeustForm.docx";
            CloudBlobContainer container = BlobsController.GetClouldBlobContainer();
            CloudBlockBlob     blob      = container.GetBlockBlobReference(filename);

            Stream blobStream = await blob.OpenReadAsync();

            return(File(blobStream, blob.Properties.ContentType, filename));
        }