Пример #1
0
        public static void SeedStrumenti(/*"@" in front of string before passing it as argument */ string excelPath, LabContext context)
        {
            if (context.Strumento.Count() == 0)
            {
                var      filePath = @"C:\Users\Alexa\Desktop\StrumentiProva.xlsx";
                FileInfo file     = new FileInfo(filePath);

                using (ExcelPackage package = new ExcelPackage(file))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault();
                    int            rowCount  = worksheet.Dimension.Rows;
                    for (int row = 2; row <= rowCount; row++)
                    {
                        var       PDFPath = "";
                        var       ImgPath = "";
                        Strumento s       = new Strumento();
                        s.PartId      = worksheet.Cells[row, 1].Value.ToString();
                        s.SerialId    = worksheet.Cells[row, 2].Value.ToString();
                        s.Nome        = worksheet.Cells[row, 3].Value.ToString();
                        s.Descrizione = worksheet.Cells[row, 4].Value.ToString();
                        s.Marca       = worksheet.Cells[row, 5].Value.ToString();
                        s.Modello     = worksheet.Cells[row, 6].Value.ToString();
                        s.Posizione   = worksheet.Cells[row, 7].Value.ToString();
                        if (worksheet.Cells[row, 8].Value != null)
                        {
                            PDFPath   = @worksheet.Cells[row, 8].Value.ToString();
                            s.PDFPath = DataSeeder.Upload(PDFPath);
                        }
                        if (worksheet.Cells[row, 9].Value != null)
                        {
                            ImgPath   = @worksheet.Cells[row, 9].Value.ToString();
                            s.ImgPath = DataSeeder.Upload(ImgPath);
                        }
                        var Date = DateTime.FromOADate((double)worksheet.Cells[row, 11].Value);
                        s.Nascita = Date;
                        var ttl = DateTime.FromOADate((double)worksheet.Cells[row, 10].Value);
                        s.TTL = ttl;
                        var delicato = worksheet.Cells[row, 12].Value.ToString();
                        if (delicato == "true")
                        {
                            s.Delicato = true;
                        }
                        else
                        {
                            s.Delicato = false;
                        }
                        s.Status = 1;
                        context.Strumento.Add(s);
                    }
                    context.SaveChanges();
                }
            }
        }
Пример #2
0
 public static void SeedData(UserManager <Utente> userManager, RoleManager <IdentityRole> roleManager, string excelPath, LabContext context, IEmailService emailService, string email)
 {
     SeedRoles(roleManager);
     SeedUsers(userManager);
     SeedStrumenti(excelPath, context);
     // TTLHelper.CheckTTL(context,email,emailService);
 }