Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult CriarUsuario(Usuario model)
- {
- if (ModelState.IsValid)
- {
- ApplicationUser identityUser = new ApplicationUser
- {
- UserName = model.LOGIN,
- LOGIN = model.LOGIN,
- };
- using (GPSdEntitiesIdentity IdentityContext = new GPSdEntitiesIdentity())
- {
- using (var transaction = IdentityContext.Database.BeginTransaction())
- {
- var userStore = new UserStore<ApplicationUser>(IdentityContext);
- var userManager = new UserManager<ApplicationUser>(userStore);
- IdentityResult resultado = userManager.Create(identityUser, model.SENHA);
- if (resultado.Succeeded)
- {
- resultado = userManager.AddToRole(identityUser.Id, model.Perfil);
- if (resultado.Succeeded)
- {
- if (GravarNaTabelausuario(identityUser.Id, model))
- {
- transaction.Commit();
- return RedirectToAction("Index", "Home");
- }
- }
- }
- transaction.Rollback();
- ModelState.AddModelError("ErroIdentity", resultado.Errors.FirstOrDefault());
- }
- }
- }
- ViewBag.ReadOnly = false;
- return View(model);
- }
- public bool GravarNaTabelausuario(string IdUsuario, Usuario model)
- {
- UsuarioEnt UsuarioEnt = new UsuarioEnt()
- {
- IdAspNetUsers = IdUsuario,
- IdPessoa = model.UsuarioEnt.IdPessoa,
- IdStatusRegistro = model.UsuarioEnt.IdStatusRegistro,
- IdUnidade = model.UsuarioEnt.IdUnidade,
- };
- UsuarioNeg UsuarioApp = new UsuarioApp(null);
- if (UsuarioNeg.RecebeRegistro(UsuarioEnt))
- {
- if(UsuarioNeg.ValidaRegistro())
- {
- if (UsuarioNeg.GravaRegistro(UsuarioEnt))
- {
- return true;
- }
- }
- }
- return false;
- }
Add Comment
Please, Sign In to add comment