public async Task <IActionResult> CreateVenue([FromBody] NewVenue venue) { var newVenue = new Venue { CompanyId = venue.CompanyId, VenueName = venue.VenueName, VenueCode = venue.VenueCode, VenueAddress = venue.VenueAddress, VenuePostCode = venue.VenuePostCode, VenueContact = venue.VenueContact, VenueDescription = venue.VenueDescription, VenueNotes = venue.VenueNotes, VenueLatitude = venue.VenueLatitude, VenueLongitude = venue.VenueLongitude, ImageId = venue.ImageId, VenuePhone = venue.VenuePhone, }; return(await venues.CreateVenue(newVenue) .Ensure(v => v.HasValue, "Venue created successfully") .OnBoth(v => v.IsFailure ? StatusCode(500) : StatusCode(201)) .ConfigureAwait(false)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { ViewData["HideNavigation"] = true; returnUrl ??= Url.Content("~/"); if (!ModelState.IsValid) { return(Page()); } var company = await companies.CreateCompany(new Company { CompanyName = Input.CompanyName, CompanyPhone = Input.CompanyPhone, CompanyPostcode = Input.CompanyPostcode, CompanyContact = Input.CompanyContact, CompanyEmail = Input.CompanyEmail, CompanyAddress = Input.CompanyAddress }).Ensure(c => c.HasValue, "Company created") .OnSuccess(c => c.Value) .ConfigureAwait(false); if (company.IsFailure) { ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup."); return(Page()); } var venue = await venues.CreateVenue(new Venue { CompanyId = company.Value, VenueCode = "", VenueName = Input.VenueName, VenueAddress = "", VenuePostCode = "", VenuePhone = "", VenueContact = "", VenueDescription = "", VenueNotes = "Created via onboarding", }).Ensure(c => c.HasValue, "Venue created") .OnSuccess(c => c.Value) .ConfigureAwait(false); if (venue.IsFailure) { ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup."); return(Page()); } var user = new Employee { Username = Input.EmployeeEmail, EmployeeName = Input.EmployeeName, CompanyId = company.Value, VenueId = venue.Value, RoleId = 5 }; var result = await _userManager.CreateAsync(user, Input.EmployeePassword).ConfigureAwait(false); if (result.Succeeded) { result = await _userManager.UpdateSecurityStampAsync(user).ConfigureAwait(false); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user).ConfigureAwait(false); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); _logger.LogInformation("User created a new account with password."); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.EmployeeId, code, returnUrl }, protocol: Request.Scheme ); await _emailSender.SendEmailAsync(Input.EmployeeEmail, "Welcome to Koasta!", $@" <p>Thanks for choosing Koasta. You're on your way to accepting digital payments with ease.</p> <p>Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>. After confirming, you'll have access to your Koasta dashboard and can begin your onboarding process.</p> <p>Further information about how to get started with Koasta can be found <a href='https://support.koasta.com'>here</a>.</p> ").ConfigureAwait(false); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.EmployeeEmail, returnUrl })); } else { await _signInManager.SignInAsync(user, isPersistent : false).ConfigureAwait(false); return(LocalRedirect(returnUrl)); } } } try { await venues.DropVenue(venue.Value).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex.ToString()); } try { await companies.DropCompany(company.Value).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex.ToString()); } if (!result.Errors.Any(e => e.Code.Equals("TOOCOMMON", StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup."); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> OnPostAsync(int?companyId) { if (!await FetchData(companyId).ConfigureAwait(false)) { return(RedirectToPage("/Index")); } if (!ModelState.IsValid) { return(this.TurboPage()); } var selectedCompanyId = 0; if (Role.CanAdministerSystem) { if (string.IsNullOrWhiteSpace(Input.CompanyId)) { return(this.TurboPage()); } selectedCompanyId = int.Parse(Input.CompanyId); } else { selectedCompanyId = companyId.Value; } var coords = await coordinates.GetCoordinates(Input.VenuePostCode ?? "").ConfigureAwait(false); string latitude = null; string longitude = null; if (coords.HasValue) { latitude = coords.Value.Latitude.ToString(); longitude = coords.Value.Longitude.ToString(); } int?selectedImageId = null; if (Input.ImageId != null) { int.Parse(Input.ImageId); } var realImage = Images.Find(i => i.ImageId == selectedImageId); if (realImage == null || realImage.CompanyId != selectedCompanyId) { selectedImageId = null; } var result = coords.HasValue ? await venues.CreateVenueWithCoordinates(new Venue { CompanyId = selectedCompanyId, VenueName = Input.VenueName, VenueCode = "", VenueAddress = Input.VenueAddress, VenueAddress2 = Input.VenueAddress2, VenueAddress3 = Input.VenueAddress3, VenueCounty = Input.VenueCounty, VenuePostCode = Input.VenuePostCode, VenueContact = Input.VenueContact, VenuePhone = Input.VenuePhone, VenueDescription = Input.VenueDescription, VenueNotes = "", VenueLatitude = latitude, VenueLongitude = longitude, ImageId = selectedImageId, ReferenceCode = Guid.NewGuid().ToString() }).Ensure(c => c.HasValue, "Venue was created") .OnSuccess(c => c.Value) .ConfigureAwait(false) : await venues.CreateVenue(new Venue { CompanyId = selectedCompanyId, VenueName = Input.VenueName, VenueCode = "", VenueAddress = Input.VenueAddress, VenueAddress2 = Input.VenueAddress2, VenueAddress3 = Input.VenueAddress3, VenueCounty = Input.VenueCounty, VenuePostCode = Input.VenuePostCode, VenueContact = Input.VenueContact, VenuePhone = Input.VenuePhone, VenueDescription = Input.VenueDescription, VenueNotes = "", VenueLatitude = latitude, VenueLongitude = longitude, ImageId = selectedImageId, ReferenceCode = Guid.NewGuid().ToString() }).Ensure(c => c.HasValue, "Venue was created") .OnSuccess(c => c.Value) .ConfigureAwait(false); if (!result.IsSuccess) { return(this.Page()); } await AddVenuesWithExternalPaymentProvider(selectedCompanyId).ConfigureAwait(false); var selectedDocumentIds = new List <VenueDocument>(); if (Input.DocumentIds?.Count > 0) { selectedDocumentIds = Input.DocumentIds .GetRange(0, Math.Min(Input.DocumentIds.Count, 100)) .Select(id => int.Parse(id)) .Where(id => DocumentLookup.ContainsKey(id) && DocumentLookup[id].CompanyId == selectedCompanyId) .Select(id => new VenueDocument { VenueId = result.Value, DocumentId = id }) .ToList(); } return((await venueDocuments.CreateVenueDocuments(selectedDocumentIds) .OnSuccess(() => this.RedirectToPage("/Venue", new { venueId = result.Value })) .OnFailure(() => this.Page()) .ConfigureAwait(false)).Value); }