public Tariffs GetTariff(int tariffId) { using (var context = new PaymentWFEntities()) { return context.Tariffs.Where(x => x.Id == tariffId).ToList().LastOrDefault(); } }
public Tariffs GetCurrentTariff(int serviceId) { using (var context = new PaymentWFEntities()) { return context.Tariffs.Where(x => x.ServiceId == serviceId).ToList().LastOrDefault(); } }
public IEnumerable<Pays> GetData(int year, int monthId) { using (var context = new PaymentWFEntities()) { return context.Pays.Where(x => x.Year == year).Where(x => x.MonthNumber == monthId).ToList(); } }
public int GetServiceId(string serviceName) { using (var context = new PaymentWFEntities()) { return (context.Services.Where(q => q.Name == serviceName).Select(q => q.Id)).FirstOrDefault(); } }
public string GetServiceName(int serviceId) { using (var context = new PaymentWFEntities()) { return context.Services.FirstOrDefault(x => x.Id == serviceId).Name; } }
public IList<Month> GetMonth() { using (var context = new PaymentWFEntities()) { return (from q in context.Month select q).ToList(); } }
public Month GetMonth(int monthId) { using (var context = new PaymentWFEntities()) { return (from q in context.Month where q.Id == monthId select q).FirstOrDefault(); } }
public IList<Month> GetMonths(string locale) { using (var context = new PaymentWFEntities()) { var currentLocale = new LocalesManager().GetLocale(locale, context); return (from q in context.Month where q.LocaleId == currentLocale.Id select q).ToList(); } }
public IList<Tariffs> GetCurrentTariffs() { using (var context = new PaymentWFEntities()) { var services = new ServiceManager().GetServices(context); if(services.Count == 0) throw new InvalidOperationException("не найден коммунальный платеж"); return services.Select(item => GetCurrentTariff(item.Id)).Where(res => res != null).ToList(); } }
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(); } }
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 IList<Services> GetServices(PaymentWFEntities context) { return context.Services.ToList(); }
public Locales GetLocale(string locale, PaymentWFEntities context) { return context.Locales.FirstOrDefault(x => x.Locale == locale); }
static bool IsHaveData(int year, int monthId, PaymentWFEntities context) { return (context.Pays.Where(q => q.MonthNumber == monthId).Where(q => q.Year == year)).Any(); }
static Pays GetPaymentItem(int year, int monthId, int? idService, PaymentWFEntities context) { return (context.Pays.Where(x => x.Year == year).Where(x => x.MonthNumber == monthId).Where( x => x.IdService == idService)).FirstOrDefault(); }