Example #1
0
        public async Task <IActionResult> OnPostAsync(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return(RedirectToAction("Index"));
            }
            List <StatCode> StatCodes = new List <StatCode>();

            using (var memoryStream = new MemoryStream())
            {
                await file.CopyToAsync(memoryStream).ConfigureAwait(false);

                using (var package = new ExcelPackage(memoryStream))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; // Tip: To access the first worksheet, try index 1, not 0
                    int            totalRows = worksheet.Dimension.Rows;


                    for (int i = 0; i < totalRows; i++)
                    {
                        StatCodes.Add(new StatCode
                        {
                            Code  = ((object[, ])(worksheet.Cells.Value))[i, 0].ToString(),
                            Text  = ((object[, ])(worksheet.Cells.Value))[i, 1].ToString(),
                            CatId = StatCode.CatId
                        });
                    }
                }
            }

            _context.StatCode.AddRange(StatCodes);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Train).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TrainExists(Train.TrainId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.StatCode.Add(StatCode);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #4
0
        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            _context.Category.Add(Category);
            await _context.SaveChangesAsync();

            return RedirectToPage("./Index");
        }
Example #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Report = await _context.Report.FindAsync(id);

            if (Report != null)
            {
                _context.Report.Remove(Report);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Category = await _context.Category.FindAsync(id);

            if (Category != null)
            {
                _context.Category.Remove(Category);
                await _context.SaveChangesAsync();
            }

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