public async Task <IActionResult> CreateAsync(AdminListingCreateInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } 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 AdminHomeCreateServiceModel { Name = model.Name, Description = model.Description, Address = model.Address, Price = model.Price, City = model.City, Category = model.Category, Status = model.Status, Owner = model.Owner, Image = imageToWrite, }; bool isCreated = await this.adminListingService.CreateListingAsync(homeCreateServiceModel); if (!isCreated) { return(this.RedirectToAction("Index", "Dashboard", new { area = AdminArea }).WithWarning(string.Empty, CouldNotCreateRecord)); } var owner = await this.adminUserService.GetUserByUsername(model.Owner); if (!await this.userManager.IsInRoleAsync(owner, OwnerRoleName)) { await this.userManager.AddToRoleAsync(owner, OwnerRoleName); } await this.imageDbService.WriteToDatabasebAsync(imgUrl, imgPubId); return(this.RedirectToAction("Index", "Dashboard", new { area = AdminArea }) .WithSuccess(string.Empty, RecordCreatedSuccessfully)); }
// GET: Create public IActionResult Create() { var model = new AdminListingCreateInputModel(); return(this.View(model)); }