Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CreateViewModel createPerson)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int intGroupId;
                    if (!int.TryParse(createPerson.SelectedGroupId, out intGroupId))
                    {
                        return(View(createPerson));
                    }

                    //create person from person view model
                    var person = new Entities.Models.Person
                    {
                        Name      = createPerson.PersonName,
                        DateAdded = createPerson.DateAdded,
                        Group     = new Entities.Models.Group
                        {
                            Id = intGroupId
                        }
                    };
                    await _personRepository.AddPerson(person);

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(createPerson));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error whilst creating new person - {createPerson.PersonName}");
                throw;
            }
        }
Ejemplo n.º 2
0
        public static IWebHost MigrateDb(this IWebHost host)
        {
            using (IServiceScope scope = host.Services.CreateScope())
            {
                // Create database if required and ensure it is at a new enough version
                scope.ServiceProvider.GetRequiredService <RepositoryContext>().Database.Migrate();


                // seed excel data
                var context = scope.ServiceProvider.GetRequiredService <RepositoryContext>();
                //esa
                var person = new Entities.Models.Person
                {
                    Name = "Esa Kukkamäki",
                    Age  = 38
                };
                excelLoader.ExcelHandler.SeedDbForExcelData(context, "ESAYHT_hiihto.xls", person);
                //eero
                person = new Entities.Models.Person
                {
                    Name = "Eero Kukkamäki",
                    Age  = 69
                };
                excelLoader.ExcelHandler.SeedDbForExcelData(context, "EEROYHT.xls", person);
            };

            return(host);
        }