public ActionResult Agregar() { RegistrarVendViewModel registrarse = new RegistrarVendViewModel(); //string clave = Seguridad.ClaveAleatoria(); //registrarse.Password = clave; //registrarse.ConfirmPassword = clave; ListRelations(); return(View(registrarse)); }
public async Task <ActionResult> Agregar(RegistrarVendViewModel model) { model.Estado = true; if (ModelState.IsValid) { string pathimage = "~/Content/img/doctor.png"; Vendedor user = new Vendedor { UserName = model.Email, Email = model.Email, Nombre = model.Nombre, ApellidoMaterno = model.ApellidoMaterno, ApellidoPaterno = model.ApellidoPaterno, Estado = model.Estado, PhoneNumber = model.TelefonoCelular, TelefonoCelular = model.TelefonoCelular, TelefonoFijo = model.TelefonoFijo, TelefonoLaboral = model.TelefonoLaboral, TelefonoResidencia = model.TelefonoResidencia, Altura = model.Altura, Block = model.Block, Calle = model.Calle, CBU = model.CBU, CBU_2 = model.CBU_2, CBU_3 = model.CBU_3, CUIT_CUIL = model.CUIT_CUIL, Departamento = model.Departamento, IdEstadoCivil = model.IdEstadoCivil, IdLocalidad = model.IdLocalidad, IdSexo = model.IdSexo, IdTipoDocumento = model.IdTipoDocumento, FechaDeNacimiento = model.FechaDeNacimiento, LugarDeTrabajo = model.LugarDeTrabajo, NumeroDocumento = model.NumeroDocumento, Observaciones = model.Observaciones, IdOrganizador = model.IdOrganizador, Imagen = pathimage }; var result = await UserManager.CreateAsync(user, model.Password); GrupoManager groupManager = new GrupoManager(); var group = db.ApplicationGroups.Where(x => x.Name == "Vendedores").FirstOrDefault(); groupManager.SetUserGroups(user.Id, group.Id); if (result.Succeeded) { ViewBag.Resultado = "Se registro correctamente un Vendedor"; //await this.groupManager.SetUserGroups(user.Id, "Vendedores"); var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmarEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirmar su cuenta", "Por favor para confirmar su cuenta haga click en el siguiente enlace: <a href=\"" + callbackUrl + "\">link</a>"); //ViewBag.Link = callbackUrl; return(View("~/Views/Account/DisplayEmail.cshtml")); } AddErrors(result); } ListRelations(); // If we got this far, something failed, redisplay form return(View(model)); }