public async Task ImportFileAsync(string fileName)
        {
            string line;

            await _catalogueUnitOfWork.BulkImportRepository.RemoveAllRecords();

            // Read the file and import into the databse
            using (StreamReader streamReader = new StreamReader(fileName))
            {
                try
                {
                    while ((line = await streamReader.ReadLineAsync()) != null)
                    {
                        _catalogueUnitOfWork.BulkImportRepository.Add(new BulkImport()
                        {
                            Filename  = Path.GetFileName(fileName),
                            Data      = line,
                            CreatedOn = DateTime.UtcNow
                        });
                    }

                    await _catalogueUnitOfWork.CommitAsync();
                }
                finally
                {
                    streamReader.Close();
                }
            }
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _catalogueUnitOfWork.CategoryRepository.Add(Category);
            await _catalogueUnitOfWork.CommitAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                await LoadLookupsAsync();

                return(Page());
            }

            _catalogueUnitOfWork.ProductRepository.Add(Product);
            await _catalogueUnitOfWork.CommitAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public async Task <Category> AddCategory(string name)
        {
            _logger.LogInformation("Calling: CategoryRepository.AddAsync()");

            Category category = new Category()
            {
                CategoryName = name
            };

            _catalogueUnitOfWork.CategoryRepository.Add(category);
            await _catalogueUnitOfWork.CommitAsync();

            return(category);
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product = await _catalogueUnitOfWork.ProductRepository.FindAsync((int)id);

            if (Product != null)
            {
                _catalogueUnitOfWork.ProductRepository.Remove(Product);
                await _catalogueUnitOfWork.CommitAsync();
            }

            return(RedirectToPage("./Index"));
        }