예제 #1
0
        public WaterValue AddWaterValueByHouseID(long id, WaterValue value)
        {
            var wm = this.FindWmByHouseID(id);

            if (wm == null)
            {
                return(null);
            }

            value.WaterMeter = wm;
            m_context.WaterValues.Add(value);
            m_context.SaveChanges();
            return(value);
        }
예제 #2
0
        public WaterValue AddWaterValueBySerialNum(string serialNum, WaterValue value)
        {
            var wm = this.FindWmBySerialNum(serialNum);

            if (wm == null)
            {
                return(null);
            }

            value.WaterMeter = wm;
            m_context.WaterValues.Add(value);
            m_context.SaveChanges();
            return(value);
        }
예제 #3
0
        public House GetMinConsumedHouse(DateTime startDate, DateTime endDate)
        {
            var result = m_context.WaterValues.Where(x => x.ValueDate >= startDate && x.ValueDate <= endDate)
                         .OrderBy(x => x.ValueDate);
            IEnumerable <IGrouping <WaterMeter, WaterValue> > query = result.GroupBy(x => x.WaterMeter, x => x);

            double minConsumption         = 0;
            bool   consumptionIntializied = false;
            var    actualHouse            = new House();

            actualHouse = null;

            foreach (IGrouping <WaterMeter, WaterValue> wmGroup in query)
            {
                WaterMeter wm = wmGroup.Key;
                // Iterate over each value in the
                // IGrouping and print the value.
                WaterValue wv1         = wmGroup.First();
                WaterValue wv2         = wmGroup.Last();
                double     consumption = wv2.Value - wv1.Value;

                if (wm.WMHouse != null)
                {
                    if (!consumptionIntializied)
                    {
                        minConsumption         = consumption;
                        actualHouse            = wm.WMHouse;
                        consumptionIntializied = true;
                    }
                    else if (consumption < minConsumption)
                    {
                        actualHouse    = wm.WMHouse;
                        minConsumption = consumption;
                    }
                }
            }

            return(actualHouse);
        }