public async Task <ActionResult> RegisterRestaurant(RegisterRestaurantViewModel model) { if (this.ModelState.IsValid) { var db = new PlacesToEatDbContext(); var categoryId = db.Categories.Where(x => x.Name == "All").Select(x => x.Id).FirstOrDefault(); var user = new RestaurantUser { UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber, Name = model.Name, Address = model.Address, Latitude = model.Latitude, Longitude = model.Longitude, CategoryId = categoryId }; var result = await this.UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await this.UserManager.AddToRoleAsync(user.Id, "Restaurant"); await this.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(this.RedirectToAction("Index", "Home")); } this.AddErrors(result); } // If we got this far, something failed, redisplay form return(this.View(model)); }
public async Task<ActionResult> RegisterRestaurant(RegisterRestaurantViewModel model) { if (this.ModelState.IsValid) { var db = new PlacesToEatDbContext(); var categoryId = db.Categories.Where(x => x.Name == "All").Select(x => x.Id).FirstOrDefault(); var user = new RestaurantUser { UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber, Name = model.Name, Address = model.Address, Latitude = model.Latitude, Longitude = model.Longitude, CategoryId = categoryId }; var result = await this.UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await this.UserManager.AddToRoleAsync(user.Id, "Restaurant"); await this.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 this.RedirectToAction("Index", "Home"); } this.AddErrors(result); } // If we got this far, something failed, redisplay form return this.View(model); }