Beispiel #1
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));
            }
        }
Beispiel #2
0
        public JsonResult GetBillData(string billNumber)
        {
            var model      = new BillModel();
            int customerId = 0;
            var billDB     = contextDB.BILL.Where(b => b.NUMBER == billNumber).FirstOrDefault();

            if (billDB != null)
            {
                model.Bill.Id     = billDB.ID;
                model.Bill.Number = billDB.NUMBER;
                model.Bill.Sum    = billDB.SUM;
                model.Bill.Paid   = billDB.PAID;
                model.Bill.Period = CustomizedMethod.GetFullMonthName(billDB);

                customerId = billDB.CUSTOMER_ID;
                var customerDB = contextDB.CUSTOMER.Where(c => c.ID == customerId).FirstOrDefault();

                if (customerDB != null)
                {
                    model.CustomerModel.Customer.Surname = customerDB.SURNAME;
                    model.CustomerModel.Customer.Name    = customerDB.NAME;
                }
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ShowTemperatureChart()
        {
            GetTowns();
            ViewBag.ImageIconPath = CustomizedMethod.GetTemperatureIconImage();

            return(View());
        }
        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);
            }
        }
        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);
            }
        }
Beispiel #6
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 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);
            }
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        public ActionResult News()
        {
            var model = new NewsModel();

            using (var context = new TownUtilityBillSystemEntities())
            {
                var newsDB = context.NEWS.ToList();

                foreach (var n in newsDB)
                {
                    model.NewsList.Add(new News()
                    {
                        Id = n.ID, Date = n.DATE, Title = n.TITLE, ImagePath = CustomizedMethod.GetNewsImage(n.IMAGE_ID)
                    });
                }
            }
            return(View(model));
        }
Beispiel #10
0
        private void CreateBillModelFromBillList(TownUtilityBillSystemEntities context, BillModel model, List <BILL> billsDB)
        {
            foreach (var b in billsDB)
            {
                Customer customer = new Customer();

                var customerDB = context.CUSTOMER.Where(c => c.ID == b.CUSTOMER_ID).FirstOrDefault();

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

                customer.Id      = customerDB.ID;
                customer.Surname = customerDB.SURNAME;
                customer.Name    = customerDB.NAME;

                customer.Address = address;

                model.Bills.Add(new Bill()
                {
                    Id = b.ID, Number = b.NUMBER, Period = CustomizedMethod.GetFullMonthName(b), Date = b.DATE, Sum = b.SUM, Paid = b.PAID, Customer = customer
                });
            }
        }
Beispiel #11
0
        public ActionResult ShowBillPaidInfo(int bill_Id)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model  = new BillModel();
                var billDB = context.BILL.Find(bill_Id);

                if (billDB != null)
                {
                    model.Bill = new Bill()
                    {
                        Id = billDB.ID, Date = billDB.DATE, Number = billDB.NUMBER, Sum = billDB.SUM, Paid = billDB.PAID, Period = CustomizedMethod.GetFullMonthName(billDB)
                    };
                    var customerDB = context.CUSTOMER.Find(billDB.CUSTOMER_ID);

                    model.CustomerModel.Customer.Surname = customerDB.SURNAME;
                    model.CustomerModel.Customer.Name    = customerDB.NAME;
                }

                return(View(model));
            }
        }
Beispiel #12
0
        public ActionResult PaymentCardForm(int bill_Id)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model  = new PaymentCardModel();
                var billDB = context.BILL.Find(bill_Id);

                if (billDB != null)
                {
                    model.Bill = new Bill()
                    {
                        Id = billDB.ID, Number = billDB.NUMBER, Date = billDB.DATE, Period = CustomizedMethod.GetFullMonthName(billDB), Sum = billDB.SUM, Paid = billDB.PAID
                    }
                }
                ;

                return(View(model));
            }
        }
Beispiel #13
0
        public ActionResult ShowBill(int bill_Id)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model = new BillModel();

                int   customerId         = 0;
                float consumedMonthValue = 0;
                float utilityCharges     = 0;

                var billDB = context.BILL.Find(bill_Id);

                if (billDB != null)
                {
                    model.Bill = new Bill()
                    {
                        Id = billDB.ID, Number = billDB.NUMBER, Date = billDB.DATE, Period = CustomizedMethod.GetFullMonthName(billDB), Sum = billDB.SUM, Paid = billDB.PAID
                    };
                    customerId = billDB.CUSTOMER_ID;
                }

                DateTime startDate          = new DateTime();
                DateTime finishDate         = new DateTime();
                DateTime startDateForChart  = new DateTime();
                DateTime finishDateForChart = new DateTime();

                startDate  = Convert.ToDateTime(model.Bill.Period + "-01");
                finishDate = startDate.AddMonths(1);

                int monthDifferenceBillPeriodAndStartUsageChart = 1;
                int presChartYear  = startDate.Year;
                int startChartDay  = 1;
                int prevChartYear  = presChartYear - 1;
                int presChartMonth = startDate.Month;

                float  valueDifference;
                string monthName;

                var customerDB = context.CUSTOMER.Where(c => c.ID == customerId).FirstOrDefault();

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

                var metersDB = context.METER.Where(m => m.ADDRESS_ID == model.CustomerModel.Customer.Address.Id).ToList();

                List <MeterItem> meterListDB = new List <MeterItem>();

                foreach (var m in metersDB)
                {
                    List <ChartData> chartData = new List <ChartData>();
                    meterListDB.Clear();

                    startDateForChart  = new DateTime(prevChartYear, presChartMonth + monthDifferenceBillPeriodAndStartUsageChart, startChartDay);
                    finishDateForChart = startDate.AddMonths(1);

                    var meterTypeDB = context.METER_TYPE.Where(mt => mt.ID == m.METER_TYPE_ID).FirstOrDefault();
                    var utilityDB   = context.UTILITY.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();
                    var unitDB      = context.UNIT.Where(u => u.ID == utilityDB.UNIT_ID).FirstOrDefault();

                    var unit = new Unit()
                    {
                        Id = unitDB.ID, Name = unitDB.NAME
                    };
                    var utility = new Utility()
                    {
                        Id = utilityDB.ID, Name = utilityDB.NAME, Unit = unit, Price = utilityDB.PRICE, ImageIconPath = CustomizedMethod.GetUtilityImage(utilityDB.ID)
                    };

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

                    if (utility.Id == (int)Utilities.Heating)
                    {
                        GetTemperatureHistory(context, model, m);
                    }

                    var meterItemsDB = (from mi in context.METER_ITEM
                                        where mi.METER_ID == m.ID
                                        select mi).ToList();

                    foreach (var i in meterItemsDB)
                    {
                        meterListDB.Add(new MeterItem()
                        {
                            Id = i.ID, Date = i.DATE, Value = i.VALUE
                        });
                    }

                    if (meterItemsDB.Count != 0)
                    {
                        for (; startDateForChart <= finishDateForChart; startDateForChart = startDateForChart.AddMonths(1))
                        {
                            var startElValue  = meterListDB.Where(ml => ml.Date == startDateForChart.AddMonths(-1)).FirstOrDefault().Value;
                            var finishElValue = meterListDB.Where(ml => ml.Date == startDateForChart).FirstOrDefault().Value;
                            valueDifference = (float)Math.Round(finishElValue - startElValue, 2);

                            if (startDateForChart.Month != 1)
                            {
                                Months month = (Months)(startDateForChart.Month - 1);
                                monthName = month.ToString() + " " + startDateForChart.Year;
                            }
                            else
                            {
                                Months month = Months.December;
                                monthName = month.ToString() + " " + startDateForChart.AddYears(-1).Year;
                            }

                            chartData.Add(new ChartData()
                            {
                                MonthName = monthName, Value = valueDifference
                            });
                        }
                    }

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

                    var startMeterItem = (from item in context.METER_ITEM
                                          where item.METER_ID == m.ID && item.DATE == startDate
                                          select item).FirstOrDefault();

                    var finishMeterItem = (from item in context.METER_ITEM
                                           where item.METER_ID == m.ID && item.DATE == finishDate
                                           select item).FirstOrDefault();

                    consumedMonthValue = finishMeterItem.VALUE - startMeterItem.VALUE;

                    if (m.METER_TYPE.UTILITY_ID == (int)Utilities.Electricity && consumedMonthValue > (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE)
                    {
                        utilityCharges = (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE * (float)m.METER_TYPE.UTILITY.PRICE + (consumedMonthValue - (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE) * (float)m.METER_TYPE.UTILITY.BIGUSAGEPRICE;
                    }

                    else
                    {
                        utilityCharges = consumedMonthValue * (float)m.METER_TYPE.UTILITY.PRICE;
                    }

                    model.UtilityChargesChartData.Add(new ChartData()
                    {
                        UtilityCharges = (float)Math.Round(utilityCharges, 2)
                    });

                    model.CustomerModel.Meters.Add(
                        new Meter()
                    {
                        Id                 = m.ID,
                        SerialNumber       = m.SERIAL_NUMBER,
                        ReleaseDate        = m.RELEASE_DATE,
                        VarificationDate   = m.VARIFICATION_DATE,
                        MeterType          = meterType,
                        ConsumedMonthValue = consumedMonthValue,
                        ChartData          = chartData
                    });
                }
                return(View(model));
            }
        }
        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 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));
            }
        }