public async Task <IActionResult> FindByProductAsync(string productBarCode) { Stock stock = await _stockRepository.FindByProductBarCodeAsync(productBarCode, _employeeLogin.GetEmployee().BusinessId); if (stock == null) { return(Json("Error")); } DiscountProductStock discount = await _discountProductStockRepository.FindByProdutDiscountAsync(stock.Id); ProductJsonConsultPurchase productJson = new ProductJsonConsultPurchase(); productJson.Id = stock.Id.ToString(); productJson.Name = stock.Product.Name; productJson.BarCode = stock.Product.BarCode; productJson.PriceSale = stock.SalesPrice; productJson.Discount = discount != null ? discount.DiscountProduct.DiscountAmount : 0; return(Json(productJson)); }
public async Task <Models.DiscountStock> FindByAsync(int id, int businessId) { try { DiscountProductStock discount = await _context.DiscountProductStock.Where(x => x.DiscountProductId == id && x.Stock.Product.RegisterEmployee.BusinessId == businessId).FirstOrDefaultAsync(); if (discount != null) { return(await _context.DiscountStock.Where(x => x.Id == id) .Include(x => x.DiscountProductStock) .FirstAsync()); } //TODO Implementar Exception Personalizada throw new Exception("Id Not Found"); } catch (Exception e) { throw new Exception(e.Message); } }