public async Task <object> AddOrUpdateCompanyPrice(CompanyPriceModel data) { try { var foundCompany = await _marketContext.MarketPrices.FirstOrDefaultAsync(x => x.Company.Id == data.CompanyId && x.Market.Id == data.MarketId); if (foundCompany != null) { foundCompany.Price = data.Price; foundCompany.DateUpdated = DateTime.Now; _marketContext.Attach(foundCompany); _marketContext.Entry(foundCompany).Property(p => p.Price).IsModified = true; _marketContext.Entry(foundCompany).Property(p => p.DateUpdated).IsModified = true; await _marketContext.SaveChangesAsync(); } else { await _marketContext.MarketPrices.AddAsync(new MarketPrice { CompanyId = data.CompanyId, MarketId = data.MarketId, Price = data.Price, DateUpdated = DateTime.Now }); await _marketContext.SaveChangesAsync(); } return(new { Status = true }); } catch (Exception ex) { return(new { Status = false, Message = $"error message - {ex.Message}" }); } }