public ActionResult ShowAllUtilitiesPrices()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model       = new UtilityModel();
                var utilitiesDB = context.UTILITY.ToList();

                foreach (var item in utilitiesDB)
                {
                    var unitDB = context.UNIT.Where(u => u.ID == item.UNIT_ID).FirstOrDefault();
                    var unit   = new Unit()
                    {
                        Id = unitDB.ID, Name = unitDB.NAME
                    };

                    if (item.USAGEFORSTANDARTPRICE != null && item.BIGUSAGEPRICE != null)
                    {
                        model.Utilities.Add(new Utility {
                            Id = item.ID, Name = item.NAME, Price = item.PRICE, BigUsagePrice = (decimal)item.BIGUSAGEPRICE, UsageForStandartPrice = Math.Round((decimal)item.USAGEFORSTANDARTPRICE, 0), ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                        });
                    }

                    else
                    {
                        model.Utilities.Add(new Utility {
                            Id = item.ID, Name = item.NAME, Price = item.PRICE, ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                        });
                    }
                }
                return(View(model));
            }
        }
        public ActionResult ShowUtility(string utilityName)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var utilityDB   = context.UTILITY.Where(u => u.NAME == utilityName).FirstOrDefault();
                var unitDB      = context.UNIT.Find(utilityDB.UNIT_ID);
                var utilitiesDB = context.UTILITY.ToList();

                var model = new UtilityModel();
                model.Unit.Id   = unitDB.ID;
                model.Unit.Name = unitDB.NAME;

                model.Utility.Id            = utilityDB.ID;
                model.Utility.Name          = utilityDB.NAME;
                model.Utility.Price         = utilityDB.PRICE;
                model.Utility.ImageIconPath = CustomizedMethod.GetUtilityImage(utilityDB.ID);

                if (utilityDB.USAGEFORSTANDARTPRICE != null)
                {
                    model.Utility.UsageForStandartPrice = (decimal)utilityDB.USAGEFORSTANDARTPRICE;
                }
                if (utilityDB.BIGUSAGEPRICE != null)
                {
                    model.Utility.BigUsagePrice = (decimal)utilityDB.BIGUSAGEPRICE;
                }

                model.Utility.Unit = model.Unit;

                foreach (var u in utilitiesDB)
                {
                    if (u.NAME != model.Utility.Name)
                    {
                        model.Utilities.Add(new Utility()
                        {
                            Name = u.NAME
                        });
                    }
                }

                var           meterTypesDB  = context.METER_TYPE.Where(mt => mt.UTILITY_ID == model.Utility.Id).ToList();
                var           metersDB      = context.METER.ToList();
                HashSet <int> meterTypesIds = new HashSet <int>();

                foreach (var m in meterTypesDB)
                {
                    meterTypesIds.Add(m.ID);
                }

                foreach (var m in metersDB)
                {
                    if (meterTypesIds.Contains(m.METER_TYPE_ID))
                    {
                        model.MeterQty += 1;
                    }
                }

                var view = View("~/Views/Utility/ShowUtility.cshtml", model);
                return(view);
            }
        }
        public ActionResult EditUtility(Utility utility)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                if (ModelState.IsValid)
                {
                    var utilityDB = context.UTILITY.Find(utility.Id);

                    utilityDB.NAME  = utility.Name;
                    utilityDB.PRICE = utility.Price;
                    if (utilityDB.USAGEFORSTANDARTPRICE != null)
                    {
                        utilityDB.USAGEFORSTANDARTPRICE = utility.UsageForStandartPrice;
                    }
                    if (utilityDB.BIGUSAGEPRICE != null)
                    {
                        utilityDB.BIGUSAGEPRICE = utility.BigUsagePrice;
                    }

                    context.SaveChanges();
                    return(RedirectToAction("ShowUtility", "Utility", new { utilityName = utilityDB.NAME }));
                }
                return(View());
            }
        }
示例#4
0
        public ActionResult ShowAllBillsForCustomer(int customerId)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model      = new BillModel();
                var billsDB    = context.BILL.Where(b => b.CUSTOMER_ID == customerId).ToList();
                var customerDB = context.CUSTOMER.Find(customerId);

                if (customerDB != null)
                {
                    GetCustomerDataForView(context, model, customerDB);
                }
                else
                {
                    model.CustomerModel.Customer = null;
                }

                foreach (var b in billsDB)
                {
                    model.Bills.Add(new Bill()
                    {
                        Id = b.ID, Date = b.DATE, Number = b.NUMBER, Period = CustomizedMethod.GetFullMonthName(b), Sum = b.SUM, Paid = b.PAID
                    });
                }

                return(View(model));
            }
        }
        public ActionResult ShowAllMeterTypes()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model        = new MeterTypeModel();
                var meterTypesDB = context.METER_TYPE.ToList();

                foreach (var mt in meterTypesDB)
                {
                    var utilityDB = context.UTILITY.Where(u => u.ID == mt.UTILITY_ID).FirstOrDefault();
                    var utility   = new Utility()
                    {
                        Id = utilityDB.ID, Name = utilityDB.NAME, ImageIconPath = CustomizedMethod.GetUtilityImage(utilityDB.ID)
                    };

                    model.MeterTypes.Add(new MeterType()
                    {
                        Id = mt.ID, Name = mt.NAME, VarificationPeriod = mt.VARIFICATION_PERIOD_YEARS, Utility = utility
                    });
                }
                var view = View("~/Views/Meter/ShowAllMeterTypes.cshtml", model);

                return(view);
            }
        }
示例#6
0
        public static string GetUtilityImage(int utilityId)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                IMAGEUTILITY imageDB          = null;
                string       imageName        = "";
                string       imagePathForHtml = "";
                string       imagePathDB      = "";
                string       folderName       = "";

                var utilityDB = context.UTILITY.Where(b => b.ID == utilityId).FirstOrDefault();

                if (utilityDB != null)
                {
                    imageDB = context.IMAGEUTILITY.Where(i => i.ID == utilityDB.IMAGE_ID).FirstOrDefault();
                }

                if (imageDB != null)
                {
                    imagePathDB      = imageDB.PATH.ToString();
                    folderName       = Path.GetFileName(Path.GetDirectoryName(imagePathDB));
                    imageName        = Path.GetFileName(imagePathDB);
                    imagePathForHtml = "/Images/" + folderName + "/" + imageName;
                }
                return(imagePathForHtml);
            }
        }
示例#7
0
        public ActionResult ShowFoundCustomers(string searchString)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model = new CustomerModel();

                var customersDB = (from c in context.CUSTOMER
                                   where
                                   c.ACCOUNT.Contains(searchString) ||
                                   c.SURNAME.Contains(searchString) ||
                                   (c.SURNAME + " " + c.NAME).Contains(searchString) ||
                                   c.NAME.Contains(searchString) ||
                                   c.PHONE.Contains(searchString) ||
                                   c.EMAIL.Contains(searchString) ||
                                   c.CUSTOMER_TYPE.NAME.Contains(searchString) ||
                                   c.ADDRESS.STREET.NAME.Contains(searchString) ||
                                   c.ADDRESS.TOWN.NAME.Contains(searchString) ||
                                   c.ADDRESS.FLAT_PART.NAME.Contains(searchString) ||
                                   c.ADDRESS.INDEX.VALUE.ToString().Contains(searchString)
                                   select c
                                   ).ToList();
                CreateCustomerModelFromCustomerList(context, model, customersDB);

                ViewBag.SearchString = searchString;

                return(View(model));
            }
        }
        public ActionResult EditMeter(Meter meter)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                if (ModelState.IsValid)
                {
                    var meterDB = context.METER.Find(meter.Id);

                    meterDB.SERIAL_NUMBER     = meter.SerialNumber;
                    meterDB.RELEASE_DATE      = meter.ReleaseDate;
                    meterDB.VARIFICATION_DATE = meter.VarificationDate;
                    meterDB.METER_TYPE_ID     = meter.MeterType.Id;

                    context.SaveChanges();

                    return(RedirectToAction("ShowFoundMeters", "Meter", new { searchString = meter.SerialNumber }));
                }

                var meterTypesDB = context.METER_TYPE.ToList();
                meter.MeterTypes = new List <MeterType>();

                foreach (var ct in meterTypesDB)
                {
                    meter.MeterTypes.Add(new MeterType()
                    {
                        Id = ct.ID, Name = ct.NAME
                    });
                }

                return(View(meter));
            }
        }
示例#9
0
        public ActionResult ShowLegalCustomers()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                List <Customer> customers      = new List <Customer>();
                var             model          = new CustomerModel();
                List <int>      privateTypeIds = GetPrivateCustomerTypeIds(context);
                var             customersDB    = context.CUSTOMER.ToList();

                foreach (var c in customersDB)
                {
                    if (!privateTypeIds.Contains(c.CUSTOMER_TYPE_ID))
                    {
                        var customerTypeDB = context.CUSTOMER_TYPE.Where(ct => ct.ID == c.CUSTOMER_TYPE_ID).FirstOrDefault();
                        var customerType   = new CustomerType()
                        {
                            Id = customerTypeDB.ID, Name = customerTypeDB.NAME
                        };

                        customers.Add(new Customer()
                        {
                            Id = c.ID, Account = c.ACCOUNT, Surname = c.SURNAME, Name = c.NAME, Email = c.EMAIL, Phone = c.PHONE, CustomerType = customerType
                        });
                    }
                }
                model.Customers = customers.OrderBy(c => c.Surname).ThenBy(c => c.Name).ToList();

                var view = View("~/Views/Customer/ShowLegalCustomers.cshtml", model);

                return(view);
            }
        }
        public ActionResult EditMeterType(MeterType meterType)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                if (ModelState.IsValid)
                {
                    var meterTypeDB = context.METER_TYPE.Find(meterType.Id);

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

                    context.SaveChanges();

                    return(RedirectToAction("ShowAllMeterTypes", "Meter"));
                }

                var utilitiesDB = context.UTILITY.ToList();
                meterType.Utilities = new List <Utility>();

                foreach (var u in utilitiesDB)
                {
                    meterType.Utilities.Add(new Utility()
                    {
                        Id = u.ID, Name = u.NAME
                    });
                }

                return(View());
            }
        }
示例#11
0
        public ActionResult ShowAllCustomers()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model = new CustomerModel();

                var customersDB = context.CUSTOMER.OrderBy(c => c.SURNAME).ThenBy(c => c.NAME).ToList();

                foreach (var c in customersDB)
                {
                    var customerTypeDB = context.CUSTOMER_TYPE.Where(ct => ct.ID == c.CUSTOMER_TYPE_ID).FirstOrDefault();
                    var customerType   = new CustomerType()
                    {
                        Id = customerTypeDB.ID, Name = customerTypeDB.NAME
                    };

                    model.Customers.Add(new Customer()
                    {
                        Id = c.ID, Account = c.ACCOUNT, Surname = c.SURNAME, Name = c.NAME, Email = c.EMAIL, Phone = c.PHONE, CustomerType = customerType
                    });
                }
                var view = View("~/Views/Customer/ShowAllCustomers.cshtml", model);

                return(view);
            }
        }
        public ActionResult ShowMeterData(int meterId)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model = new MeterItemModel();

                var meterItemsDB = from item in context.METER_ITEM.ToList()
                                   where item.METER_ID == meterId
                                   select item;

                CreateMeterModelWithOneMeter(meterId, context, model);

                foreach (var item in meterItemsDB)
                {
                    model.MeterItems.Add(new MeterItem()
                    {
                        Id = item.ID, Date = item.DATE, Meter = model.Meter, Value = item.VALUE
                    });
                }

                var view = View("~/Views/Meter/ShowMeterData.cshtml", model);

                return(view);
            }
        }
示例#13
0
        public string GetBuildingImage(int buildingId)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                IMAGEBUILDING imageDB          = null;
                string        imageName        = "";
                string        imagePathForHtml = "";
                string        imagePathDB      = "";
                string        folderName       = "";

                var buildingDB = context.BUILDING.Where(b => b.ID == buildingId).FirstOrDefault();

                if (buildingDB != null)
                {
                    imageDB = context.IMAGEBUILDING.Where(i => i.ID == buildingDB.IMAGE_ID).FirstOrDefault();
                }

                if (imageDB != null)
                {
                    imagePathDB      = imageDB.PATH.ToString();
                    folderName       = Path.GetFileName(Path.GetDirectoryName(imagePathDB));
                    imageName        = Path.GetFileName(imagePathDB);
                    imagePathForHtml = "/Images/" + folderName + "/" + imageName;
                }
                return(imagePathForHtml);
            }
        }
        private static CalculatorItemModel AddUtilitiesToModel(TownUtilityBillSystemEntities context)
        {
            var model       = new CalculatorItemModel();
            var utilitiesDB = context.UTILITY.ToList();

            foreach (var item in utilitiesDB)
            {
                var unitDB = context.UNIT.Where(u => u.ID == item.UNIT_ID).FirstOrDefault();
                var unit   = new Unit()
                {
                    Id = unitDB.ID, Name = unitDB.NAME
                };

                if (item.USAGEFORSTANDARTPRICE != null && item.BIGUSAGEPRICE != null)
                {
                    model.Utilities.Add(new Utility {
                        Id = item.ID, Name = item.NAME, Price = item.PRICE, BigUsagePrice = (decimal)item.BIGUSAGEPRICE, UsageForStandartPrice = Math.Round((decimal)item.USAGEFORSTANDARTPRICE, 0), ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                    });
                }

                else
                {
                    model.Utilities.Add(new Utility {
                        Id = item.ID, Name = item.NAME, Price = item.PRICE, ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                    });
                }
            }

            return(model);
        }
 public ActionResult ShowCalculatorOnLine()
 {
     using (var context = new TownUtilityBillSystemEntities())
     {
         CalculatorItemModel model = AddUtilitiesToModel(context);
         return(View(model));
     }
 }
示例#16
0
        public ActionResult ShowCustomersDeleteMethod()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var customersDB = context.CUSTOMER.Include(c => c.ADDRESS).Include(m => m.CUSTOMER_TYPE);

                return(View(customersDB.ToList()));
            }
        }
        public ActionResult ShowAllMeters()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var metersDB = context.METER.Include(m => m.ADDRESS).Include(m => m.METER_TYPE);

                return(View(metersDB.ToList()));
            }
        }
示例#18
0
        private void GetCustomerDataForView(TownUtilityBillSystemEntities context, BillModel model, CUSTOMER customerDB)
        {
            CustomerType customerType;
            Address      address;

            GetAddressAndCustomerTypeForCustomer(context, customerDB, out customerType, out address);

            model.CustomerModel.Customer = new Customer()
            {
                Id = customerDB.ID, Account = customerDB.ACCOUNT, Surname = customerDB.SURNAME, Name = customerDB.NAME, Email = customerDB.EMAIL, Phone = customerDB.PHONE, CustomerType = customerType, Address = address
            };
        }
示例#19
0
        private static List <CustomerType> GetCustomerTypesList(TownUtilityBillSystemEntities context)
        {
            var customerTypesDB = context.CUSTOMER_TYPE.ToList();
            List <CustomerType> CustomerTypesList = new List <CustomerType>();

            foreach (var ct in customerTypesDB)
            {
                CustomerTypesList.Add(new CustomerType()
                {
                    Id = ct.ID, Name = ct.NAME
                });
            }
            return(CustomerTypesList);
        }
        public ActionResult ShowCalculatorOnLine(CalculatorItemModel inputModel)
        {
            var model = new CalculatorItemModel();

            using (var context = new TownUtilityBillSystemEntities())
            {
                model = AddUtilitiesToModel(context);

                if (ModelState.IsValid)
                {
                    if (inputModel.ElectricUsage == 0 && inputModel.WaterUsage == 0 && inputModel.HeatUsage == 0 && inputModel.GasUsage == 0)
                    {
                        ViewBag.ErrorMessage = "You must enter at least 1 utility usage";
                        return(View(model));
                    }

                    var elUtilityDB    = context.UTILITY.Find((int)Utilities.Electricity);
                    var waterUtilityDB = context.UTILITY.Find((int)Utilities.Water);
                    var heatUtilityDB  = context.UTILITY.Find((int)Utilities.Heating);
                    var gasUtilityDB   = context.UTILITY.Find((int)Utilities.Gas);

                    if (inputModel.ElectricUsage > (float)elUtilityDB.USAGEFORSTANDARTPRICE)
                    {
                        model.ElCharges = (float)elUtilityDB.USAGEFORSTANDARTPRICE * (float)elUtilityDB.PRICE + (inputModel.ElectricUsage - (float)elUtilityDB.USAGEFORSTANDARTPRICE) * (float)elUtilityDB.BIGUSAGEPRICE;
                    }
                    else
                    {
                        model.ElCharges = inputModel.ElectricUsage * (float)elUtilityDB.PRICE;
                    }

                    model.WaterCharges = inputModel.WaterUsage * (float)waterUtilityDB.PRICE;
                    model.HeatCharges  = inputModel.HeatUsage * (float)heatUtilityDB.PRICE;
                    model.GasCharges   = inputModel.GasUsage * (float)gasUtilityDB.PRICE;

                    model.ElectricUsage = inputModel.ElectricUsage;
                    model.WaterUsage    = inputModel.WaterUsage;
                    model.HeatUsage     = inputModel.HeatUsage;
                    model.GasUsage      = inputModel.GasUsage;

                    model.TotalCharges = model.ElCharges + model.WaterCharges + model.HeatCharges + model.GasCharges;

                    var view = View("~/Views/Calculator/ShowCharges.cshtml", model);

                    return(view);
                }

                return(View(model));
            }
        }
        public ActionResult EditMeter(int meterId)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model = new Meter();

                var meterDB = context.METER.Find(meterId);

                if (meterDB != null)
                {
                    var meterTypeDB = context.METER_TYPE.Where(mt => mt.ID == meterDB.METER_TYPE_ID).FirstOrDefault();
                    var utilityDB   = context.UTILITY.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();

                    var utility = new Utility()
                    {
                        Id = utilityDB.ID, Price = utilityDB.PRICE, Name = utilityDB.NAME, BigUsagePrice = utilityDB.BIGUSAGEPRICE ?? 0, UsageForStandartPrice = utilityDB.USAGEFORSTANDARTPRICE ?? 0
                    };
                    var meterType = new MeterType()
                    {
                        Id = meterTypeDB.ID, Name = meterTypeDB.NAME, VarificationPeriod = meterTypeDB.VARIFICATION_PERIOD_YEARS, Utility = utility
                    };

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

                    var meterTypesDB = context.METER_TYPE.ToList();
                    model.MeterTypes = new List <MeterType>();

                    foreach (var ct in meterTypesDB)
                    {
                        model.MeterTypes.Add(new MeterType()
                        {
                            Id = ct.ID, Name = ct.NAME, VarificationPeriod = ct.VARIFICATION_PERIOD_YEARS
                        });
                    }
                }
                else
                {
                    model = null;
                }

                var view = View("~/Views/Meter/EditMeter.cshtml", model);

                return(view);
            }
        }
示例#22
0
        public ActionResult ShowBills()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model   = new BillModel();
                var billsDB = context.BILL.ToList();

                CustomizedMethod.Shuffle(billsDB);
                billsDB.RemoveRange(billCountToDisplay, billsDB.Count - billCountToDisplay);

                CreateBillModelFromBillList(context, model, billsDB);

                return(View(model));
            }
        }
        public ActionResult EditMeterData(MeterItem meterItem)
        {
            if (ModelState.IsValid)
            {
                using (var context = new TownUtilityBillSystemEntities())
                {
                    var meterItemDB = context.METER_ITEM.Find(meterItem.Id);

                    meterItemDB.VALUE = meterItem.Value;
                    context.SaveChanges();

                    return(RedirectToAction("ShowMeterData", "Meter", new { meterId = meterItemDB.METER_ID }));
                }
            }
            return(View());
        }
示例#24
0
        public ActionResult EditCustomer(Customer customer)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                if (ModelState.IsValid)
                {
                    var customerDB = context.CUSTOMER.Find(customer.Id);

                    customerDB.ACCOUNT = customer.Account;
                    if (customerDB.SURNAME != null)
                    {
                        customerDB.SURNAME = customer.Surname;
                    }
                    customerDB.NAME             = customer.Name;
                    customerDB.EMAIL            = customer.Email;
                    customerDB.PHONE            = customer.Phone;
                    customerDB.CUSTOMER_TYPE_ID = customer.CustomerType.Id;

                    context.SaveChanges();

                    List <int> privateTypeIds = GetPrivateCustomerTypeIds(context);

                    if (privateTypeIds.Contains(customer.CustomerType.Id))
                    {
                        return(RedirectToAction("ShowPrivateCustomers", "Customer"));
                    }
                    else
                    {
                        return(RedirectToAction("ShowLegalCustomers", "Customer"));
                    }
                }

                var customerTypesDB = context.CUSTOMER_TYPE.ToList();
                customer.CustomerTypes = new List <CustomerType>();

                foreach (var ct in customerTypesDB)
                {
                    customer.CustomerTypes.Add(new CustomerType()
                    {
                        Id = ct.ID, Name = ct.NAME
                    });
                }

                return(View());
            }
        }
        public ActionResult ShowUtilities()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model       = new UtilityModel();
                var utilitiesDB = context.UTILITY.ToList();

                foreach (var item in utilitiesDB)
                {
                    model.Utilities.Add(new Utility {
                        Id = item.ID, Name = item.NAME
                    });
                }

                return(View(model));
            }
        }
示例#26
0
        private static void GetTemperatureHistory(TownUtilityBillSystemEntities context, BillModel model, METER m)
        {
            List <Temperature> temperaturesDB        = new List <Temperature>();
            DateTime           temperatureStartDate  = new DateTime();
            DateTime           temperatureFinishDate = new DateTime();
            int    temperatureYearsHistory           = 2;
            float  valueSum = 0;
            float  averageValue;
            string fullMonthName = "";

            temperatureStartDate  = Convert.ToDateTime(model.Bill.Period + "-01");
            temperatureStartDate  = temperatureStartDate.AddYears(-1);
            temperatureFinishDate = temperatureStartDate.AddMonths(1);

            var temperatureItemsDB = context.TEMPERATURE.Where(t => t.TOWN_ID == m.ADDRESS.TOWN_ID).ToList();

            foreach (var d in temperatureItemsDB)
            {
                temperaturesDB.Add(new Temperature()
                {
                    Id = d.ID, Date = d.DATE, MinValue = d.MINVALUE, MaxValue = d.MAXVALUE
                });
            }

            for (int j = 0; j < temperatureYearsHistory; j++)
            {
                for (; temperatureStartDate < temperatureFinishDate; temperatureStartDate = temperatureStartDate.AddDays(1))
                {
                    valueSum += (float)(temperaturesDB.Where(t => t.Date == temperatureStartDate).FirstOrDefault().MinValue + temperaturesDB.Where(t => t.Date == temperatureStartDate).FirstOrDefault().MaxValue) / 2;
                }

                temperatureStartDate = temperatureStartDate.AddMonths(-1);
                fullMonthName        = temperatureStartDate.ToString("MMMM yyyy");
                averageValue         = valueSum / System.DateTime.DaysInMonth(temperatureStartDate.Year, temperatureStartDate.Month);

                model.Temperatures.Add(new TemperatureModel()
                {
                    AverageValue = (float)Math.Round(averageValue, 1), MonthName = fullMonthName
                });

                temperatureStartDate  = temperatureStartDate.AddYears(1);
                temperatureFinishDate = temperatureStartDate.AddMonths(1);
                valueSum = 0;
            }
        }
示例#27
0
        private static List <int> GetPrivateCustomerTypeIds(TownUtilityBillSystemEntities context)
        {
            var privateTypesDB = (from ct in context.CUSTOMER_TYPE
                                  where
                                  ct.NAME.Contains("Apartment") ||
                                  ct.NAME.Contains("House")

                                  select ct
                                  ).ToList();

            List <int> privateTypeIds = new List <int>();

            foreach (var t in privateTypesDB)
            {
                privateTypeIds.Add(t.ID);
            }
            return(privateTypeIds);
        }
示例#28
0
        public ActionResult FindCustomerBy()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model       = new CustomerModel();
                var customersDB = context.CUSTOMER.ToList();

                model.TotalCount = customersDB.Count;

                CustomizedMethod.Shuffle(customersDB);
                customersDB.RemoveRange(customerCountToDisplay, customersDB.Count - customerCountToDisplay);
                CreateCustomerModelFromCustomerList(context, model, customersDB);

                var view = View("~/Views/Customer/FindCustomerBy.cshtml", model);

                return(view);
            }
        }
        public ActionResult ShowRandomMeters()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model    = new MeterModel();
                var metersDB = context.METER.ToList();

                model.TotalCount = metersDB.Count;
                CustomizedMethod.Shuffle(metersDB);
                metersDB.RemoveRange(meterCountToDisplay, metersDB.Count - meterCountToDisplay);

                CreateMeterModelFromMeterList(context, model, metersDB);

                var view = View("~/Views/Meter/ShowRandomMeters.cshtml", model);

                return(view);
            }
        }
        private void GetTowns()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                List <Town> TownList = new List <Town>();

                var townsDB = context.TOWN.ToList();

                foreach (var t in townsDB)
                {
                    TownList.Add(new Town {
                        Id = t.ID, Name = t.NAME
                    });
                }

                ViewBag.TownList = new SelectList(TownList, "Id", "Name");
            }
        }