public async Task <IActionResult> Create() { var cities = await this.cityService.AllCitiesAsync(); var countries = await this.countryService.AllCountriesAsync(); var userId = this.userManager.GetUserId(this.User); var user = await this.userManager.FindByIdAsync(userId); var userStripeAccount = user.StripeConnectedAccountId; bool?hasStripe = true; if (string.IsNullOrWhiteSpace(userStripeAccount)) { hasStripe = false; } var viewModel = new OwnerListingCreateInputModel { UserHasStripeAccount = hasStripe, Cities = cities, Countries = countries, }; return(this.View(viewModel)); }
public async Task <IActionResult> CreatePostAsync(OwnerListingCreateInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var userId = this.userManager.GetUserId(this.User); var user = await this.userManager.FindByIdAsync(userId); // Upload the Image var imgResult = await this.imageService .UploadImageAsync(model.Image); string imgUrl = imgResult.SecureUri.AbsoluteUri; string imgPubId = imgResult.PublicId; var imageToWrite = new CloudImage { PictureUrl = imgUrl, PicturePublicId = imgPubId, }; var homeCreateServiceModel = new OwnerCreateListingServiceModel { Name = model.Name, Description = model.Description, Address = model.Address, Price = model.Price, CityId = model.CityId, Category = model.Category, Status = model.Status, Owner = user, Image = imageToWrite, }; // Create Listing bool isCreated = await this.ownerListingService.CreateListingAsync(homeCreateServiceModel); if (!isCreated) { return(this.RedirectToAction("Index", "Dashboard", new { area = string.Empty }) .WithWarning(string.Empty, CouldNotCreateRecord)); } // Add To Role await this.userManager.AddToRoleAsync(user, OwnerRoleName); // Referesh authorization since redirect requires the new role auth await this.signInManager.RefreshSignInAsync(user); // Write Image to DB await this.imageDbService.WriteToDatabasebAsync(imgUrl, imgPubId); return(this.RedirectToAction("Index", "Dashboard", new { area = ManagementArea }) .WithSuccess(string.Empty, RecordCreatedSuccessfully)); }