public async Task <ActionResult> MerchantRegister(MerchantRegisterViewModel model) { if (ModelState.IsValid) { try { var config = new MapperConfiguration(cfg => cfg.CreateMap <MerchantRegisterViewModel, Merchant>()); var mapper = config.CreateMapper(); Merchant mer = mapper.Map <Merchant>(model); string merchantId = merchantService.SaveMerchant(string.Empty, mer); if (!string.IsNullOrEmpty(merchantId)) { UserMerchant usrMer = new UserMerchant() { MerchantId = merchantId, UserId = _signInManager.GetVerifiedUserId() }; } } catch (Exception ex) { logger.Error("MerchantRegister", ex); } } return(View(model)); }
public async Task <ActionResult> MerchantRegister(MerchantRegisterViewModel model) { if (ModelState.IsValid) { var user = new User { UserName = model.Name, Email = model.Email, }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { this.service.RegisterMerchant(user.Id, model); this.UserManager.AddToRole(user.Id, "Merchant"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // 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>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public void RegisterMerchant(string id, MerchantRegisterViewModel model) { var merchant = this.mapper.Map <MerchantRegisterViewModel, Merchant>(model); merchant.AppUserId = id; this.db.Merchants.Add(merchant); this.db.SaveChanges(); }