public MarketOffer AddOffer(AddMarketOfferParameters ps) { var offer = new MarketOffer() { Amount = ps.Amount, CompanyID = ps.CompanyID, CountryID = ps.CountryID, ProductID = (int)ps.ProductType, Price = (decimal)ps.Price, Quality = ps.Quality }; var company = companyRepository.GetById(ps.CompanyID); Country foreignCountry = null; if (ps.CountryID.HasValue) { foreignCountry = countryRepository.GetById(ps.CountryID.Value); } offer.CurrencyID = offer.CountryID.HasValue ? Persistent.Countries.GetById(foreignCountry.ID).CurrencyID : Persistent.Countries.GetById(company.Region.CountryID.Value).CurrencyID; marketOfferRepository.Add(offer); var equipment = equipmentRepository.First(e => e.Entities.FirstOrDefault().EntityID == ps.CompanyID); equipmentRepository.RemoveEquipmentItem(equipment.ID, (int)ps.ProductType, ps.Quality, ps.Amount); var cost = CalculateProductCost(ps.Amount, ps.Price, company.Region?.CountryID, ps.CountryID, ps.ProductType); MakeAddOfferTransactions(cost, company, foreignCountry); marketOfferRepository.SaveChanges(); return(offer); }