internal void GetMeterDetailsForCustomer(int customerId) { using (var context = new TownUtilityBillSystemV2Entities()) { var customerDB = context.CUSTOMERs.Find(customerId); if (customerDB != null) { var customerTypeDB = context.CUSTOMER_TYPEs.Where(mt => mt.ID == customerDB.CUSTOMER_TYPE_ID).FirstOrDefault(); var addressDB = context.ADDRESSes.Where(a => a.ID == customerDB.ADDRESS_ID).FirstOrDefault(); 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.GetWithSquareAndImagePath).FirstOrDefault(); var flatPartDB = context.FLAT_PARTs.Where(fp => fp.ID == addressDB.FLAT_PART_ID).FirstOrDefault(); 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 utility = context.UTILITYs.Where(u => u.ID == meterTypeDB.UTILITY_ID).Select(Utility.GetUtilityWithIdAndResourceName).FirstOrDefault(); 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 }); } FlatPart flatPart = null; if (flatPartDB != null) { flatPart = FlatPart.Get(flatPartDB); } var customerType = new CustomerType() { Id = customerTypeDB.ID, Name = customerTypeDB.NAME, ResourceName = CustomerType.GetResourceName(customerTypeDB.NAME) }; var account = context.ACCOUNTs.Where(a => a.ID == customerDB.ACCOUNT_ID).Select(Account.Get).FirstOrDefault(); var address = new Address() { Id = addressDB.ID, Index = index, Town = town, Street = street, Building = building, FlatPart = flatPart }; Customer = new Customer() { Id = customerDB.ID, Account = account, Surname = customerDB.SURNAME, Name = customerDB.NAME, Email = customerDB.EMAIL, Phone = customerDB.PHONE, CustomerType = customerType, Address = address }; } else { Customer = null; } } }
internal void GetAllUtilityDataForCustomer(int customerId) { using (var context = new TownUtilityBillSystemV2Entities()) { var customerDB = context.CUSTOMERs.Find(customerId); if (customerDB != null) { var customerTypeDB = context.CUSTOMER_TYPEs.Where(mt => mt.ID == customerDB.CUSTOMER_TYPE_ID).FirstOrDefault(); var addressDB = context.ADDRESSes.Where(a => a.ID == customerDB.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 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 }); } var customerType = new CustomerType() { Id = customerTypeDB.ID, ResourceName = CustomerType.GetResourceName(customerTypeDB.NAME) }; 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, Square = (float)buildingDB.SQUARE }; 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 }; var accountDB = context.ACCOUNTs.Where(a => a.ID == customerDB.ACCOUNT_ID).FirstOrDefault(); Account account = Account.Get(accountDB); Customer = new Customer() { Id = customerDB.ID, Account = account, Surname = customerDB.SURNAME, Name = customerDB.NAME, Email = customerDB.EMAIL, Phone = customerDB.PHONE, CustomerType = customerType, Address = address }; } else { Customer = null; } } #endregion }