Exemplo n.º 1
0
        public IActionResult AddBossVet(int id)
        {
            var ins = _context.Institution.Where(p => p.IdInst == id).Single();

            var bossVet = new CreateBossVet
            {
                IdInst = ins.IdInst
            };

            ViewBag.idInst = bossVet.IdInst;


            return(View(bossVet));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddBossVet(int id, CreateBossVet bossVet)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser boss = new ApplicationUser
                {
                    Email = bossVet.Email,

                    UserName = bossVet.Email,
                    Surname  = bossVet.Surname,
                    IdInst   = id,

                    Education = bossVet.Education,

                    Address     = bossVet.Address,
                    Name        = bossVet.NameVet,
                    PhoneNumber = bossVet.PhoneNumber
                };

                var result = await _userManager.CreateAsync(boss, bossVet.Password);



                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(boss, "BossVet");

                    return(RedirectToAction("InstMain"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }

                    return(View());
                }
            }



            else
            {
                return(View());
            }
        }