public bool BuyProduct(PurchaseDetails purchase) { var products = _productRepo.GetAllProducts().ToList(); var customers = _customerRepo.GetAllCustomers().ToList(); if (!_purchaseservice.IsProductExists(products, purchase)) { return(false); // return "Selected Product not existed"; } else if (!_purchaseservice.IsCustomerExists(customers, purchase)) { return(false); // return "Selected CUstomer not existed"; } else if (!_purchaseservice.IsProductQuantityAvilable(products, purchase)) { return(false); // return "Selected producted already sold out"; } _purchaseservice.CalculatePrice(customers, products, purchase); _purchaseRepo.Addpurchase(purchase); var product = products.Find(p => p.Id == purchase.ProductId); product.Quantity = product.Quantity - purchase.Quantity; _productRepo.Update(product); return(true); }