public ActionResult Post(ProductsToCustomerViewModel productsToCustomer) { try { var customer = 0; var product = 0; if (!string.IsNullOrEmpty(productsToCustomer.CustomerName)) { customer = _CustomerService.GetByName(productsToCustomer.CustomerName).Result.Id; } if (!string.IsNullOrEmpty(productsToCustomer.ProductName)) { product = _productService.GetByName(productsToCustomer.ProductName).Result.Id; } var productToCustomer = new ProductsToCustomer { CustomerId = customer == 0 ? 0 : customer, ProductId = product == 0 ? 0 : product }; if (productToCustomer.CustomerId > 0 && productToCustomer.ProductId > 0) { _productsToCustomer.AddAsync(productToCustomer); } else { return(Ok(new { status = "Failed" })); } } catch (Exception) { return(BadRequest("Some Error while add Products To Customer")); } return(Ok(new { status = "Success" })); }
// DELETE ASYNC public async void DeleteAsync(ProductsToCustomer productsToCustomer) { await Task.Run(() => { _dal.ProductsToCustomers.DeleteAsync(productsToCustomer); }); }
// UPDATE ASYNC public async void UpdateAsync(ProductsToCustomer entity) { await Task.Run(() => { _dal.ProductsToCustomers.UpdateAsync(entity); }); }