public async Task <ActionResult> Create([Bind(Include = "Id,Notes,PictureReference,ConstructionProjectId")] ProgressTrackingEntry progressTrackingEntry)
        {
            if (ModelState.IsValid)
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];
                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var mimeType = MimeMapping.GetMimeMapping(fileName);
                        var filePath = await _filesStorageService.UploadFile(fileName, file.InputStream, mimeType);

                        progressTrackingEntry.PictureReference = filePath;
                    }
                }

                progressTrackingEntry.EntryDate = DateTime.Now;
                _db.ProgressTrackingEntries.Add(progressTrackingEntry);
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.ConstructionProjectId = new SelectList(_db.ConstructionProjects, "Id", "Name", progressTrackingEntry.ConstructionProjectId);
            return(View(progressTrackingEntry));
        }
Пример #2
0
        public static void ProcessQueueMessage([ServiceBusTrigger("resizepicturesqueue")] ResizePictureMessage message, TextWriter logger)
        {
            var azureStorageConnectionString = ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString;

            byte[] data;
            using (var client = new WebClient())
            {
                data = client.DownloadData(message.PictureReference);
            }

            var thumbnail = ImageResizer.CreateThumbnail(Image.FromStream(new MemoryStream(data)));

            var filesStorageService = new FilesStorageService(azureStorageConnectionString);

            var uploadedFileUrl = filesStorageService.UploadFile(Guid.NewGuid().ToString(), thumbnail, "image/jpeg").Result;

            using (var context = new ConstructionsProgressTrackerContext())
            {
                context.ProgressTrackingEntries.Single(e => e.Id == message.Id).ThumbnailPictureReference = uploadedFileUrl;
                context.SaveChanges();
            }

            logger.WriteLine($"Thumbnail for entry: {message.Id} successfully created. Available at {uploadedFileUrl}.");
        }