public ActionResult Index() { LARSUploadModel model = new LARSUploadModel(); GetLastUploadDetails(model); return(View(model)); }
private void GetLastUploadDetails(LARSUploadModel model) { String taskName = AutomationController.AutomatedTaskName.LARSImport.ToString(); AutomatedTask at = db.AutomatedTasks.Where(x => x.TaskName == taskName).FirstOrDefault(); if (at != null) { model.IsAutomationInProgress = at.InProgress; } MetadataUpload dataUpload = db.MetadataUploads.Where(m => m.MetadataUploadTypeId == (Int32)Constants.MetadataUploadType.LearningAim).OrderByDescending(m => m.CreatedDateTimeUtc).FirstOrDefault(); if (dataUpload != null) { if (dataUpload.AspNetUser == null) { AspNetUser user = db.AspNetUsers.Find(dataUpload.CreatedByUserId); if (user != null) { model.LastUploadedBy = user.Name; } } else { model.LastUploadedBy = dataUpload.AspNetUser.Name ?? dataUpload.AspNetUser.Email; } model.LastUploadDateTimeUtc = dataUpload.CreatedDateTimeUtc; DateTime.SpecifyKind(model.LastUploadDateTimeUtc.Value, DateTimeKind.Utc); model.LastUploadFileName = dataUpload.FileName; } }
public ActionResult Index(LARSUploadModel model) { if (ModelState.IsValid) { String[] validFileTypes = { ".zip" }; Boolean validFileType = false; String LARSFolder = Constants.ConfigSettings.LARSUploadVirtualDirectoryName; if (LARSFolder.EndsWith(@"\")) { LARSFolder = LARSFolder.Substring(0, LARSFolder.Length - 1); } // Check if config setting is valid if (String.IsNullOrEmpty(LARSFolder) || !Directory.Exists(LARSFolder)) { ModelState.AddModelError("", AppGlobal.Language.GetText(this, "LARSFolderNotConfigured", "Configuration setting VirtualDirectoryNameForStoringLARSFiles is not set or is incorrect")); } if (ModelState.IsValid) { try { foreach (String fileType in validFileTypes) { if (model.File.FileName.ToLower().EndsWith(fileType)) { validFileType = true; break; } } if (!validFileType) { ModelState.AddModelError("File", AppGlobal.Language.GetText(this, "ZIPFilesOnly", "Please upload a ZIP file")); } else { String ZIPFile = String.Format("{0}/LARS.zip", LARSFolder); // Save the zip file model.File.SaveAs(ZIPFile); // Import the file ImportLARSFile(Permission.GetCurrentUserGuid().ToString(), AppGlobal.Language.GetLanguageIdForThisRequest()); if (ModelState.IsValid) { ViewBag.Message = AppGlobal.Language.GetText(this, "ImportSuccessful", "LARS Data Successfully Imported"); } } } catch (Exception ex) { // Create a model error ModelState.AddModelError("", ex.Message); } // Delete the existing files foreach (FileInfo file in new DirectoryInfo(LARSFolder).GetFiles()) { file.Delete(); } } } GetLastUploadDetails(model); return(View(model)); }