public async Task <IActionResult> OnPostAsync(int productId) { if (!ModelState.IsValid) { await FetchData(productId).ConfigureAwait(false); return(this.TurboPage()); } if (!await FetchData(productId).ConfigureAwait(false)) { return(this.TurboPage()); } var selectedTypeId = int.Parse(Input.ProductTypeId); var selectedType = ProductTypes.Find(r => r.ProductTypeId == selectedTypeId); if (selectedType == null) { return(this.TurboPage()); } return((await products.UpdateProduct(new ProductPatch { ResourceId = productId, ProductType = new PatchOperation <int> { Operation = OperationKind.Update, Value = selectedTypeId }, ProductName = new PatchOperation <string> { Operation = OperationKind.Update, Value = Input.ProductName }, ProductDescription = new PatchOperation <string> { Operation = OperationKind.Update, Value = Input.ProductDescription }, Price = new PatchOperation <decimal> { Operation = OperationKind.Update, Value = Input.Price }, AgeRestricted = new PatchOperation <bool> { Operation = OperationKind.Update, Value = Input.AgeRestricted } }) .OnSuccess(() => this.RedirectToPage("/Product", new { productId })) .OnFailure(() => this.Page()) .ConfigureAwait(false)).Value); }
public async Task <IActionResult> OnPostAsync(int venueId) { if (!ModelState.IsValid) { await FetchData(venueId).ConfigureAwait(false); return(this.TurboPage()); } if (!await FetchData(venueId).ConfigureAwait(false)) { return(RedirectToPage("/Index")); } var selectedTypeId = int.Parse(Input.ProductTypeId); var selectedType = ProductTypes.Find(r => r.ProductTypeId == selectedTypeId); if (selectedType == null) { return(this.TurboPage()); } return((await products.CreateProduct(new Product { ProductType = selectedTypeId, ProductName = Input.ProductName, ProductDescription = Input.ProductDescription, Price = Input.Price, AgeRestricted = Input.AgeRestricted, VenueId = venueId, }) .Ensure(c => c.HasValue, "Product was created") .OnSuccess(c => this.RedirectToPage("/Product", new { productId = c.Value })) .OnFailure(() => this.Page()) .ConfigureAwait(false)).Value); }