public async Task <ActionResult> UsersCreate(RegisterCustomerUserViewModel model) { if ((ModelState.IsValid) && model.CustomerID > 0) { CustomerUser user = (CustomerUser)model.GetUser(); user.CustomerID = model.CustomerID; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var resultRole = userManager.AddToRole(user.Id, "CustomerRole"); userManager.AddToRole(user.Id, "CustomerAdminRole"); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link //string code = await userManager.GenerateEmailConfirmationTokenAsync(user.Id); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await userManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); await workflowMessageService.SendUserRegistrationMessageAsync(userManager, user.Id, Request.Url.Scheme, Url); return(RedirectToAction("Users", "Customers", new { id = model.CustomerID })); } else { var errors = string.Join(",", result.Errors); ModelState.AddModelError(string.Empty, errors); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult UsersCreate(int customerID) { RegisterCustomerUserViewModel model = new RegisterCustomerUserViewModel(); model.CustomerID = customerID; return(View(model)); }
public ActionResult UsersCreate(int customerID) { RegisterCustomerUserViewModel model = new RegisterCustomerUserViewModel(); model.CustomerID = customerID; var salesChannles = salesChannelRepository.FindSalesChannels().ConvertAll(x => new SalesChannelSingleViewModel(x)); ViewBag.SalesChannelID = new SelectList(salesChannles as IEnumerable <SalesChannelSingleViewModel>, "SalesChannelID", "FullName"); return(View(model)); }
public ActionResult UsersCreate(RegisterCustomerUserViewModel model) { if (ModelState.IsValid) { CustomerUser user = (CustomerUser)model.GetUser(); user.CustomerID = model.CustomerID; user.UserName = model.Email; user.FirstName = model.FirstName; user.LastName = model.LastName; user.IsCustomerAdmin = model.IsCustomerAdmin; user.JobPosition = model.JobPosition; user.Initials = model.Initials; try { var result = userManager.Create(user, model.Password); if (result.Succeeded) { //NO SE ESTA USANDO //if (model.IsCustomerAdmin) //{ // userManager.AddToRole(user.Id, "CustomerAdminUser"); //} //else //{ // userManager.AddToRole(user.Id, "CustomerUser"); //} //Se crea el Usuario userManager.AddToRole(user.Id, "CustomerUser"); //Se envian mail de Activacion var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("Sample"); userManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider <CustomerUser>(provider.Create("EmailConfirmation")); string code = userManager.GenerateEmailConfirmationToken(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); workflowMessageService.SendConfirmEmail(user.Email, "Confirme su cuenta de acceso", "Por favor confirme su cuenta haciendo click <a href=\"" + callbackUrl + "\">aqui</a>"); //Se asigna el Canal de Venta AssignSalesChannel(user.Id, model.SalesChannelID); //Se redireccion al Listado de Usuarios return(RedirectToAction("Users", "Customer", new { id = model.CustomerID })); } else { var errors = string.Join(",", result.Errors); ModelState.AddModelError(string.Empty, errors); } } catch (DbEntityValidationException e) { var errors = string.Join("; ", e.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage)); ModelState.AddModelError(string.Empty, errors); } catch (Exception e) { ModelState.AddModelError("", e); } } // If we got this far, something failed, redisplay form return(View(model)); }