Exemplo n.º 1
0
        public async Task <IActionResult> Create(PersonSubmitModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var lastId = (await _context.People.LastOrDefaultAsync())?.Id ?? 0;

            var person = new Person
            {
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                Patronymic = model.Patronymic,
                BirthDate  = model.BirthDate,
                Gender     = model.Gender,
                PIN        = pinService.Generate(model.Gender, model.BirthDate, lastId + 1)
            };

            _context.Add(person);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }