Beispiel #1
0
        private void FillMetersForModel(TownUtilityBillSystemV2Entities context, ADDRESS addressDB)
        {
            var metersDB = context.METERs.Where(m => m.ADDRESS_ID == addressDB.ID).ToList();

            foreach (var m in metersDB)
            {
                var meterTypeDB = context.METER_TYPEs.Where(mt => mt.ID == m.METER_TYPE_ID).FirstOrDefault();

                var utilityDB = context.UTILITYs.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();

                var utility = new Utility()
                {
                    Id = utilityDB.ID, Name = utilityDB.NAME
                };

                var meterType = new MeterType()
                {
                    Id = meterTypeDB.ID, Name = meterTypeDB.NAME, Utility = utility
                };

                Meters.Add(new Meter()
                {
                    Id = m.ID, SerialNumber = m.SERIAL_NUMBER, ReleaseDate = m.RELEASE_DATE, VarificationDate = m.VARIFICATION_DATE, MeterType = meterType
                });
            }
        }
        internal void GetMeterForEdit(int meterId)
        {
            using (var context = new TownUtilityBillSystemV2Entities())
            {
                var meterDB = context.METERs.Find(meterId);

                if (meterDB != null)
                {
                    var meterTypeDB = context.METER_TYPEs.Where(mt => mt.ID == meterDB.METER_TYPE_ID).FirstOrDefault();
                    var utility     = context.UTILITYs.Where(u => u.ID == meterTypeDB.UTILITY_ID).Select(Utility.GetUtilityWithIdAndResourceName).FirstOrDefault();

                    var meterType = new MeterType()
                    {
                        Id = meterTypeDB.ID, Name = meterTypeDB.NAME, VarificationPeriod = meterTypeDB.VARIFICATION_PERIOD_YEARS, Utility = utility
                    };

                    Id               = meterDB.ID;
                    MeterType        = meterType;
                    SerialNumber     = meterDB.SERIAL_NUMBER;
                    ReleaseDate      = meterDB.RELEASE_DATE;
                    VarificationDate = meterDB.VARIFICATION_DATE;

                    MeterTypes = context.METER_TYPEs.Select(MeterType.Get).ToList();
                }
            }
        }
Beispiel #3
0
        internal MeterType GetMeterType(int meterTypeId)
        {
            using (var context = new TownUtilityBillSystemV2Entities())
            {
                MeterType meterType;
                var       meterTypeDB = context.METER_TYPEs.Find(meterTypeId);

                if (meterTypeDB != null)
                {
                    var utilityDB = context.UTILITYs.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();
                    var utility   = Utility.GetUtilityWithIdAndResourceName(utilityDB);

                    meterType         = MeterType.Get(meterTypeDB);
                    meterType.Utility = utility;

                    meterType.Utilities = context.UTILITYs.Select(Utility.GetUtilityWithIdAndResourceName).ToList();
                }
                else
                {
                    meterType = null;
                }

                return(meterType);
            }
        }
Beispiel #4
0
        private static void CreateMeterModelFromMeterList(TownUtilityBillSystemV2Entities context, MeterModel model, List <METER> rndMetersDB)
        {
            foreach (var m in rndMetersDB)
            {
                var meterTypeDB = context.METER_TYPEs.Where(mt => mt.ID == m.METER_TYPE_ID).FirstOrDefault();
                var utilityDB   = context.UTILITYs.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();
                var addressDB   = context.ADDRESSes.Where(a => a.ID == m.ADDRESS_ID).FirstOrDefault();
                var indexDB     = context.INDEXes.Where(i => i.ID == addressDB.INDEX_ID).FirstOrDefault();
                var townDB      = context.TOWNs.Where(t => t.ID == addressDB.TOWN_ID).FirstOrDefault();
                var streetDB    = context.STREETs.Where(s => s.ID == addressDB.STREET_ID).FirstOrDefault();
                var buildingDB  = context.BUILDINGs.Where(b => b.ID == addressDB.BUILDING_ID).FirstOrDefault();
                var flatPartDB  = context.FLAT_PARTs.Where(fp => fp.ID == addressDB.FLAT_PART_ID).FirstOrDefault();

                var utility = new Utility()
                {
                    Id = utilityDB.ID, Name = utilityDB.NAME, ResourceName = UtilityModel.GetResourceNameForUtility(utilityDB.NAME)
                };

                var meterType = new MeterType()
                {
                    Id = meterTypeDB.ID, Name = meterTypeDB.NAME, Utility = utility
                };

                var index = new Index()
                {
                    Id = indexDB.ID, Value = indexDB.VALUE
                };
                var town = new Town()
                {
                    Id = townDB.ID, Name = townDB.NAME
                };
                var street = new Street()
                {
                    Id = streetDB.ID, Name = streetDB.NAME
                };
                var building = new Building()
                {
                    Id = buildingDB.ID, Number = buildingDB.NUMBER
                };

                FlatPart flatPart = null;

                if (flatPartDB != null)
                {
                    flatPart = FlatPart.Get(flatPartDB);
                }

                var address = new Address()
                {
                    Id = addressDB.ID, Index = index, Town = town, Street = street, Building = building, FlatPart = flatPart
                };

                model.Meters.Add(new Meter()
                {
                    Id = m.ID, SerialNumber = m.SERIAL_NUMBER, ReleaseDate = m.RELEASE_DATE, VarificationDate = m.VARIFICATION_DATE, MeterType = meterType, Address = address
                });
            }
        }
Beispiel #5
0
        internal void UpdateMeterType(MeterType meterType)
        {
            using (var context = new TownUtilityBillSystemV2Entities())
            {
                var meterTypeDB = context.METER_TYPEs.Find(meterType.Id);

                meterTypeDB.NAME       = meterType.Name;
                meterTypeDB.UTILITY_ID = meterType.Utility.Id;
                meterTypeDB.VARIFICATION_PERIOD_YEARS = meterType.VarificationPeriod;

                context.SaveChanges();
            }
        }
        private void InitializeMeterProperty(int meterId, TownUtilityBillSystemV2Entities context)
        {
            var meterDB     = context.METERs.Where(m => m.ID == meterId).FirstOrDefault();
            var meterTypeDB = context.METER_TYPEs.Where(mt => mt.ID == meterDB.METER_TYPE_ID).FirstOrDefault();
            var utilityDB   = context.UTILITYs.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();
            var addressDB   = context.ADDRESSes.Where(a => a.ID == meterDB.ADDRESS_ID).FirstOrDefault();
            var flatPartDB  = context.FLAT_PARTs.Where(fp => fp.ID == addressDB.FLAT_PART_ID).FirstOrDefault();

            var unit    = context.UNITs.Where(u => u.ID == utilityDB.UNIT_ID).Select(Unit.Get).FirstOrDefault();;
            var utility = new Utility()
            {
                Id = utilityDB.ID, Name = utilityDB.NAME, Unit = unit, ResourceName = UtilityModel.GetResourceNameForUtility(utilityDB.NAME)
            };
            var meterType = new MeterType()
            {
                Id = meterTypeDB.ID, Name = meterTypeDB.NAME, Utility = utility
            };

            var index    = context.INDEXes.Where(i => i.ID == addressDB.INDEX_ID).Select(Index.Get).FirstOrDefault();
            var town     = context.TOWNs.Where(t => t.ID == addressDB.TOWN_ID).Select(Town.Get).FirstOrDefault();
            var street   = context.STREETs.Where(s => s.ID == addressDB.STREET_ID).Select(Street.Get).FirstOrDefault();
            var building = context.BUILDINGs.Where(b => b.ID == addressDB.BUILDING_ID).Select(Building.Get).FirstOrDefault();

            FlatPart flatPart = null;

            if (flatPartDB != null)
            {
                flatPart = FlatPart.Get(flatPartDB);
            }


            var address = new Address()
            {
                Id = addressDB.ID, Index = index, Town = town, Street = street, Building = building, FlatPart = flatPart
            };

            Meter = new Meter()
            {
                Id = meterDB.ID, SerialNumber = meterDB.SERIAL_NUMBER, ReleaseDate = meterDB.RELEASE_DATE, VarificationDate = meterDB.VARIFICATION_DATE, MeterType = meterType, Address = address
            };
        }
Beispiel #7
0
 public MeterTypeModel()
 {
     MeterType  = new MeterType();
     MeterTypes = new List <MeterType>();
     Utility    = new Utility();
 }