Exemple #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new HosDbContext(serviceProvider.GetRequiredService <DbContextOptions <HosDbContext> >()))
            {
                if (context.Stuff.Any())
                {
                }
                else
                {
                    using (StreamReader r = new StreamReader("Models/stuff.json"))
                    {
                        string         json  = r.ReadToEnd();
                        IList <Stuff1> array = JsonConvert.DeserializeObject <IList <Stuff1> >(json);

                        foreach (var item in array)
                        {
                            context.Stuff.Add(new Stuff
                            {
                                Name       = item.Name,
                                Gender     = (Gender)Enum.Parse(typeof(Gender), item.Gender),
                                Title      = (Title)Enum.Parse <Title>(item.Title),
                                Department = (Department)Enum.Parse <Department>(item.Department),
                            });
                        }
                    }
                    using (StreamReader r = new StreamReader("Models/medicine.json"))
                    {
                        string            json  = r.ReadToEnd();
                        IList <Medicine1> array = JsonConvert.DeserializeObject <IList <Medicine1> >(json);

                        foreach (var item in array)
                        {
                            context.Medicine.Add(new Medicine
                            {
                                Code        = item.Code,
                                Name        = item.Name,
                                Type        = (MedicineType)Enum.Parse(typeof(MedicineType), item.Type),
                                ReleaseDate = DateTime.Parse(item.ProDate),
                                LeftMonths  = item.Exceed,
                                Factory     = item.Factory,
                            });
                        }
                    }
                    context.SaveChanges();
                }
            }
        }
Exemple #2
0
 public IndexModel(ILogger <IndexModel> logger, HosDbContext hosContext, RecDbContext recContext)
 {
     _logger     = logger;
     _hosContext = hosContext;
     _recContext = recContext;
 }
Exemple #3
0
 public CreateModel(RazorSecond.Data.RecDbContext context, HosDbContext hosContext)
 {
     _context    = context;
     _hosContext = hosContext;
 }
Exemple #4
0
 public IndexModel(RecDbContext context, HosDbContext hosContext)
 {
     _context    = context;
     _hosContext = hosContext;
 }