public async Task <IActionResult> GetProductTypes() { return(await productTypes.FetchProductTypes(0, 2000) .Ensure(p => p.HasValue, "Product types were found") .OnBoth(p => p.IsFailure ? StatusCode(404, "") : StatusCode(200, p.Value.Value)) .ConfigureAwait(false)); }
private async Task <bool> FetchData(int venueId) { Employee = await userManager.GetUserAsync(User).ConfigureAwait(false); Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false); ProductTypes = await productTypes.FetchProductTypes(0, int.MaxValue) .Ensure(t => t.HasValue, "Product Types were found") .OnSuccess(t => t.Value) .OnBoth(t => t.IsSuccess ? t.Value : new List <ProductType>()) .ConfigureAwait(false); if (Role.CanAdministerSystem) { return(true); } var venue = await venues.FetchVenue(venueId) .Ensure(t => t.HasValue, "Venue was found") .OnSuccess(t => t.Value) .ConfigureAwait(false); if (!venue.IsSuccess) { return(false); } if (!Role.CanAdministerVenue || Employee.CompanyId != venue.Value.CompanyId) { return(false); } return(true); }
private async Task <bool> FetchData(int productId) { Employee = await userManager.GetUserAsync(User).ConfigureAwait(false); Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false); if (!Role.CanAdministerVenue) { return(false); } ProductTypes = await productTypes.FetchProductTypes(0, int.MaxValue) .Ensure(t => t.HasValue, "Product Types were found") .OnSuccess(t => t.Value) .OnBoth(t => t.IsSuccess ? t.Value : new List <ProductType>()) .ConfigureAwait(false); var product = (await products.FetchProduct(productId).ConfigureAwait(false)) .Ensure(e => e.HasValue, "Product found") .OnSuccess(e => e.Value); if (product.IsFailure) { return(false); } var venue = await venues.FetchVenue(product.Value.VenueId) .Ensure(t => t.HasValue, "Venue was found") .OnSuccess(t => t.Value) .ConfigureAwait(false); if (!venue.IsSuccess) { return(false); } if (!Role.CanAdministerSystem && Employee.CompanyId != venue.Value.CompanyId) { return(false); } Title = product.Value.ProductName; Input ??= new InputModel { ProductName = product.Value.ProductName, ProductTypeId = product.Value.ProductType.ToString(), ProductDescription = product.Value.ProductDescription, Price = product.Value.Price, AgeRestricted = product.Value.AgeRestricted, }; return(true); }