public void SaveData(IEnumerable<Pays> data, int year, int monthId) { using (var context = new PaymentWFEntities()) { using (var transaction = new TransactionScope()) { if (IsHaveData(year, monthId, context)) { foreach (var item in data) { var currentItem = GetPaymentItem(year, monthId, item.IdService, context); currentItem.CounterFirst = item.CounterFirst; currentItem.CounterSecond = item.CounterSecond; currentItem.Difference = item.Difference; currentItem.Sum = item.Sum; currentItem.IdTariff = item.IdTariff; context.SaveChanges(); } } else { foreach (var newItem in data.Select(item => new Pays { Year = year, MonthNumber = monthId, IdService = item.IdService, CounterFirst = item.CounterFirst, CounterSecond = item.CounterSecond, Difference = item.Difference, Sum = item.Sum, IdTariff = item.IdTariff })) { context.Pays.Add(newItem); context.SaveChanges(); } } transaction.Complete(); } } }
public void SaveTariff(Tariffs tariff) { using (var context = new PaymentWFEntities()) { //var data = new Tariffs // { // ServiceId = tariff.ServiceId, // Price = tariff.Price, // Overexpenditure = tariff.Overexpenditure, // DateSet = DateTime.Now // }; context.Tariffs.Add(tariff); context.SaveChanges(); } }