Example #1
0
        public async Task <IActionResult> OnGet()
        {
            foreach (var fileName in Directory.GetFiles(NomService.DossierVignettes))
            {
                var fi = new FileInfo(fileName);

                var newFileName = await _fichierService.CreateFile(fi);

                var nomSansExtension = fi.Name.Replace(fi.Extension, "");

                if (!_context.Images.Any(i => i.Nom == nomSansExtension))
                {
                    var image = new ImageTableau()
                    {
                        EstActif      = true,
                        MaxImpression = 50,
                        Nom           = nomSansExtension,
                        NomBase       = newFileName
                    };

                    _context.Images.Add(image);

                    await _context.SaveChangesAsync();
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (HttpContext.Request.Form.Files != null)
            {
                var file = HttpContext.Request.Form.Files.FirstOrDefault();

                var newFileName = await _fichierService.CreateFile(file);

                if (!string.IsNullOrWhiteSpace(newFileName))
                {
                    ImageTableau.NomBase  = newFileName;
                    ImageTableau.EstActif = true;

                    _context.Images.Add(ImageTableau);
                    await _context.SaveChangesAsync();
                }
            }
            return(RedirectToPage("./Index"));
        }