public async Task <ReferenceDataViewModel> GetSubmissionsPerCollectionAsync( string containerName, string collectionName, string reportName, int maxRows = Constants.MaxFilesToDisplay, CancellationToken cancellationToken = default(CancellationToken)) { var model = new ReferenceDataViewModel(); // get job info from db var files = (await _referenceDataServiceClient.GetSubmittedFilesPerCollectionAsync(Api, collectionName, cancellationToken)) .OrderByDescending(f => f.SubmissionDate) .Take(maxRows) .ToList(); var container = _cloudStorageService.GetStorageContainer(containerName); // get file info from result report await Task.WhenAll( files .Select(file => _fileUploadJobMetaDataModelBuilderService .PopulateFileUploadJobMetaDataModelForReferenceDataUpload( file, reportName, SummaryFileName, container, collectionName, cancellationToken))); model.Files = files; model.ReferenceDataCollectionName = collectionName; return(model); }
public async Task <IActionResult> UploadFiles(Image file, string containerName) { if (ModelState.IsValid) { try { // http://www.mikesdotnetting.com/article/288/asp-net-5-uploading-files-with-asp-net-mvc-6 // http://dotnetthoughts.net/file-upload-in-asp-net-5-and-mvc-6/ if (file.File.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.File.ContentDisposition).FileName.Trim('"'); // Extension method update RC2 has removed this //await file.File.SaveAsAsync(Path.Combine(_imageServiceOptions.Value.ServerUploadFolder, fileName)); var container = _cloudService.GetStorageContainer(containerName); await file.File.SaveInAzureAsync(container, fileName); var imageDesc = new ImageDescription { ContentType = file.File.ContentType, FileName = file.File.FileName, ContainerName = container.Name, CreatedTimestamp = DateTime.UtcNow, UpdatedTimestamp = DateTime.UtcNow, Description = file.Id }; _repo.AddOrUpdateFileDescriptions(imageDesc); var imageModel = Mapper.Map <ImageDescriptionViewModel>(imageDesc); GetImageUri(imageModel); return(Ok(new { Message = "Image uploaded", Image = imageModel })); } } catch (Exception ex) { _logger.LogError("Error loading Image", ex); ModelState.AddModelError("", "Error loading Image"); return(BadRequest(new { Message = "Error loading Image" })); } } ModelState.AddModelError("", "Invalid Model Error"); return(BadRequest(new { Message = "Image could not be uploaded, please try again" })); }
public async Task <IActionResult> Register(RegisterViewModel model, IFormFile profileImage, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new LunarUser { UserName = model.UserName, Email = model.Email, FirstWords = model.FirstWords }; var image = new Image { File = profileImage }; var fileName = ContentDispositionHeaderValue.Parse(image.File.ContentDisposition).FileName.Trim('"'); var container = _cloudService.GetStorageContainer("profileimages"); await image.File.SaveInAzureAsync(container, fileName); user.ProfileImage = new ImageDescription { ContainerName = container.Name, ContentType = image.File.ContentType, CreatedTimestamp = DateTime.Now, Description = image.Id, FileName = image.File.FileName }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { //await _signInManager.SignInAsync(user, isPersistent: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Auth", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await _emailService.SendEmailAsync(model.Email, _authMail, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(View("RegisterConfirmation", model.Email)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IEnumerable <FileUploadJobMetaDataModel> > GetSubmissionsPerPeriodAsync( int year, int period, CancellationToken cancellationToken = default(CancellationToken)) { // get job info from db var files = (await GetSubmittedFilesPerPeriodAsync(year, period, cancellationToken)) .OrderByDescending(f => f.SubmissionDate) .Take(Constants.MaxFilesToDisplay) .ToList(); foreach (var foundPeriod in files.GroupBy(f => f.PeriodNumber).Select(f => f.Key)) { var file = files .Where(f => f.PeriodNumber == foundPeriod) .OrderByDescending(f => f.SubmissionDate) .First(); file.UsedForPeriodEnd = true; } var container = _cloudStorageService.GetStorageContainer(Constants.ALLFStorageContainerName); // get file info from result report await Task.WhenAll( files .Where(f => f.JobStatus == JobStatuses.JobStatus_Completed) .Select(file => _fileUploadJobMetaDataModelBuilderService .PopulateFileUploadJobMetaDataModel( file, GenericActualsCollectionErrorReportName, ResultReportName, container, Constants.ALLFPeriodPrefix, cancellationToken))); return(files); }