public async Task SubmitAsync() { if (Customers.Exists(x => x.UserId == Model.UserId && x.ProductId == Model.ProductId)) { msg = $"{Model.User.Name} already has {Model.Product.Name}"; return; } else { msg = null; } isLoading = true; var response = await HttpClient.PostAsJsonAsync("api/products/customers", Model); var customer = await response.Content.ReadFromJsonAsync <MProductCustomer>(); customer.Product = Model.Product; customer.User = Model.User; await OnCustomerAdded.InvokeAsync(customer); isLoading = false; ResetSearches(); Model = DefaultModel; await JsRuntime.HideModalAsync(nameof(AddCustomerModal)); }
protected override async Task OnInitializedAsync() { Products = await HttpClient.GetFromJsonAsync <MProduct[]>("api/seller/products"); Users = await HttpClient.GetFromJsonAsync <UserInfo[]>("api/users"); Model = DefaultModel; }
public async Task <MProductCustomer> AddProductCustomerAsync(MProductCustomer customer) { const string sql = "INSERT INTO dbo.ProductCustomers (ProductId, UserId) " + "OUTPUT INSERTED.Id, INSERTED.ProductId, INSERTED.UserId, INSERTED.CreateDate " + "VALUES (@ProductId, @UserId);"; return(await connection.QuerySingleAsync <MProductCustomer>(sql, customer)); }
public async Task <IActionResult> PostProductCustomerAsync([FromBody] MProductCustomer customer) { if (!User.IsInRole(RoleConstants.AdminRoleId) && !await productsRepository.IsProductSellerAsync(customer.ProductId, int.Parse(User.Identity.Name))) { return(BadRequest()); } return(Ok(await productsRepository.AddProductCustomerAsync(customer))); }
public void AddCustomer(MProductCustomer customer) { Customers.Add(customer); }
private async Task DeleteCustomerAsync(MProductCustomer customer) { await HttpClient.DeleteAsync("api/products/customers/" + customer.Id); Customers.Remove(customer); }
private async Task ShowDeleteCustomerAsync(MProductCustomer customer) { await DeleteConfirmModal.ShowAsync(customer); }