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 ActionResult RegisterRestaurant(RegisterRestaurantViewModel restaurantModel) { if (!ModelState.IsValid) { return(View(restaurantModel)); } var userID = this.User.Identity.GetUserId(); var restauranName = restaurantModel.Name; var countOfTables = restaurantModel.CountOfTables; this.restaurantService.CreateRestaurant(userID, restauranName, countOfTables); return(this.RedirectToAction("ManageRestaurant")); }
public async Task <IActionResult> RegisterRestaurant(RegisterRestaurantViewModel model) { if (ModelState.IsValid) { Restaurant restaurant = new Restaurant() { RegistrationDate = DateTime.Now, }; //_context.Restaurants.Add(restaurant); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, AccountType = "Restaurant", RestaurantData = restaurant }; _applicationService.AddRestaurant(restaurant); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation(3, "User created a new restaurant account with password."); return(RedirectToAction(nameof(HomeController.Index), "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> RegisterRestaurant(RegisterRestaurantViewModel model, ICollection <IFormFile> logo, ICollection <IFormFile> files) { if (ModelState.IsValid) { var uploads = Path.Combine(_hostEnv.WebRootPath, "images\\logos\\"); string logoPath = "images/logos/logo.jpg"; foreach (var file in logo) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fnm = model.Email + ".png"; if (fileName.ToLower().EndsWith(".png") || fileName.ToLower().EndsWith(".jpg") || fileName.ToLower().EndsWith(".gif")) { var filePath = Path.Combine(uploads, fnm); var directory = new DirectoryInfo(uploads); if (directory.Exists == false) { directory.Create(); } await file.SaveAsAsync(filePath); logoPath = "images/logos/" + fnm; } } uploads = Path.Combine(_hostEnv.WebRootPath, "images\\interior\\"); List <Interior> interiors = new List <Interior>(); int x = 1; foreach (var file in files) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fnm = model.Email + x + ".png"; if (fileName.ToLower().EndsWith(".png") || fileName.ToLower().EndsWith(".jpg") || fileName.ToLower().EndsWith(".gif")) { var filePath = Path.Combine(uploads, fnm); var directory = new DirectoryInfo(uploads); if (directory.Exists == false) { directory.Create(); } await file.SaveAsAsync(filePath); Interior interior = new Interior() { InteriorPath = "images/interior/" + fnm }; interiors.Add(interior); x++; } } Restaurant restaurant = new Restaurant() { Email = model.Email, RegistrationDate = DateTime.Now, RestaurantName = model.RestaurantName, Address = model.Address, PhoneNumber = model.PhoneNumber, Website = model.Website, Description = model.Description, LogoPath = logoPath, Interiors = interiors }; //_context.Restaurants.Add(restaurant); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, //AccountType = "Restaurant", RestaurantData = restaurant }; //_applicationService.AddRestaurant(restaurant); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "Restaurant"); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation(3, "User created a new restaurant account with password."); return(RedirectToAction(nameof(HomeController.Index), "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }