Beispiel #1
0
 public Tariffs GetTariff(int tariffId)
 {
     using (var context = new PaymentWFEntities())
     {
         return context.Tariffs.Where(x => x.Id == tariffId).ToList().LastOrDefault();
     }
 }
Beispiel #2
0
 public Tariffs GetCurrentTariff(int serviceId)
 {
     using (var context = new PaymentWFEntities())
     {
         return context.Tariffs.Where(x => x.ServiceId == serviceId).ToList().LastOrDefault();
     }
 }
Beispiel #3
0
 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();
     }
 }
Beispiel #4
0
 public int GetServiceId(string serviceName)
 {
     using (var context = new PaymentWFEntities())
     {
         return (context.Services.Where(q => q.Name == serviceName).Select(q => q.Id)).FirstOrDefault();
     }
 }
Beispiel #5
0
 public string GetServiceName(int serviceId)
 {
     using (var context = new PaymentWFEntities())
     {
         return context.Services.FirstOrDefault(x => x.Id == serviceId).Name;
     }
 }
Beispiel #6
0
 public IList<Month> GetMonth()
 {
     using (var context = new PaymentWFEntities())
     {
         return (from q in context.Month
                 select q).ToList();
     }
 }
Beispiel #7
0
 public Month GetMonth(int monthId)
 {
     using (var context = new PaymentWFEntities())
     {
         return (from q in context.Month
                 where q.Id == monthId
                 select q).FirstOrDefault();
     }
 }
Beispiel #8
0
        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();
            }
        }
Beispiel #9
0
        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();
            }
        }
Beispiel #10
0
 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();
     }
 }
Beispiel #11
0
        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();
                }
            }
        }
Beispiel #12
0
 public IList<Services> GetServices(PaymentWFEntities context)
 {
     return context.Services.ToList();
 }
Beispiel #13
0
 public Locales GetLocale(string locale, PaymentWFEntities context)
 {
     return context.Locales.FirstOrDefault(x => x.Locale == locale);
 }
Beispiel #14
0
 static bool IsHaveData(int year, int monthId, PaymentWFEntities context)
 {
     return (context.Pays.Where(q => q.MonthNumber == monthId).Where(q => q.Year == year)).Any();
 }
Beispiel #15
0
 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();
 }