Пример #1
0
        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));
        }
Пример #2
0
        protected override async Task OnInitializedAsync()
        {
            Products = await HttpClient.GetFromJsonAsync <MProduct[]>("api/seller/products");

            Users = await HttpClient.GetFromJsonAsync <UserInfo[]>("api/users");

            Model = DefaultModel;
        }
Пример #3
0
        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));
        }
Пример #4
0
        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)));
        }
Пример #5
0
 public void AddCustomer(MProductCustomer customer)
 {
     Customers.Add(customer);
 }
Пример #6
0
        private async Task DeleteCustomerAsync(MProductCustomer customer)
        {
            await HttpClient.DeleteAsync("api/products/customers/" + customer.Id);

            Customers.Remove(customer);
        }
Пример #7
0
 private async Task ShowDeleteCustomerAsync(MProductCustomer customer)
 {
     await DeleteConfirmModal.ShowAsync(customer);
 }