Exemplo n.º 1
0
        public IActionResult Index()
        {
            var viewModel = new DataImportViewModel();

            PropagadaDataImportViewModel(viewModel);
            return(View(viewModel));
        }
Exemplo n.º 2
0
        public ActionResult Import(DataImportViewModel vm)
        {
            if (String.IsNullOrEmpty(vm.ImportPassword))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            string requiredHash = "aa7f5180ab596290cf8f1da45378a488";
            var    md5          = MD5.Create();
            var    bytes        = md5.ComputeHash(System.Text.Encoding.Unicode.GetBytes(vm.ImportPassword));

            if (!requiredHash.Equals(BitConverter.ToString(bytes).Replace("-", String.Empty).ToLower()))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            else
            {
                SDC.Library.DummyDataImport.ImportUtility import = new Library.DummyDataImport.ImportUtility();
                //load data.
                import.LoadData();
                //start import
                import.Import(max: vm.Max);

                return(View());
            }
        }
Exemplo n.º 3
0
 private void PropagadaDataImportViewModel(DataImportViewModel viewModel)
 {
     viewModel.SourceTypes = new SelectList(new Dictionary <string, string> {
         { "CSV Datei", Athene.Inventory.Abstractions.DataImport.Constants.InputFormats.Csv },
     }, "Value", "Key");
     viewModel.DataTypes = new SelectList(new Dictionary <string, string> {
         { "Buecher", nameof(Abstractions.Models.Book) },
         { "Buch exemplare", nameof(Abstractions.Models.InventoryItem) },
         { "Schueler", nameof(Inventory.User) },
     }, "Value", "Key");
 }
Exemplo n.º 4
0
        public IActionResult Upload(DataImportViewModel model)
        {
            var dataImport = _dataImports.SingleOrDefault(x =>
                                                          x.InputFormat == model.SourceType &&
                                                          x.OutputFormat == model.DataType);

            if (dataImport == null)
            {
                throw new NotImplementedException();
            }

            var    items          = dataImport.Convert(model.UploadFile.OpenReadStream());
            string serialisedData = "";
            string cachePrefix    = "";
            string viewName       = "";

            switch (dataImport.OutputFormat)
            {
            case nameof(Abstractions.Models.Book):
                var books = (IEnumerable <Book>)items;
                serialisedData = JsonConvert.SerializeObject(books);
                cachePrefix    = _booksDataType;
                viewName       = "Books";
                break;

            case nameof(Abstractions.Models.InventoryItem):
                var invItems = (IEnumerable <InventoryItem>)items;
                MapToArticles(invItems);
                serialisedData = JsonConvert.SerializeObject(invItems, new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                });
                cachePrefix = _invItemsDataType;
                viewName    = "InventoryItems";
                break;

            case nameof(Inventory.User):
                var users = (IEnumerable <IUser>)items;
                serialisedData = JsonConvert.SerializeObject(users);
                items          = users.Select(u => u.ToViewModel());
                cachePrefix    = _studentDataType;
                viewName       = "Students";
                break;

            default:
                throw new NotImplementedException();
            }
            string importId = $"{cachePrefix}_{Guid.NewGuid()}";

            ViewBag.ImportId = importId;
            HttpContext.Session.SetString(importId, serialisedData);
            return(View(viewName, items));
        }
Exemplo n.º 5
0
        public async Task <Either <ActionResult, DataImportViewModel> > GetDataFileImportStatus(Guid releaseId, Guid fileId)
        {
            return(await _persistenceHelper
                   .CheckEntityExists <Release>(releaseId)
                   .OnSuccess(_userService.CheckCanViewRelease)
                   .OnSuccess(async _ =>
            {
                // Ensure file is linked to the Release by getting the ReleaseFile first
                var releaseFile = await _releaseFileRepository.Find(releaseId, fileId);
                if (releaseFile == null || releaseFile.File.Type != FileType.Data)
                {
                    return DataImportViewModel.NotFound();
                }

                return await _dataImportService.GetImport(fileId);
            }));
        }
Exemplo n.º 6
0
        public async Task <DataImportViewModel> GetImport(Guid fileId)
        {
            var import = await _dataImportRepository.GetByFileId(fileId);

            if (import == null)
            {
                return(DataImportViewModel.NotFound());
            }

            return(new DataImportViewModel
            {
                Errors = import.Errors.Select(error => error.Message).ToList(),
                PercentageComplete = import.PercentageComplete(),
                StagePercentageComplete = import.StagePercentageComplete,
                NumberOfRows = import.Rows,
                Status = import.Status
            });
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Import(DataImportViewModel model)
        {
            ImportResult importResult = await _dataPortingService.ImportProductData(model.ImportFile);


            if (importResult == ImportResult.Successful)
            {
                TempData["Success"] = "Successfully imported product data from file.";
            }
            else if (importResult == ImportResult.AlreadyRunning)
            {
                ViewBag.AlreadyRunning = "An import operation is already running. Please wait until it finishes and try again.";
                return(View("Index"));
            }
            else
            {
                TempData["Error"] = "An error occured while trying to import product data. Make sure the file is a valid product data Excel file and try again.";
            }
            return(RedirectToAction("Index", "DataPorting"));
        }