//
        // GET: /Meter/Details/5
        public ActionResult Home(int meterId, int propertyId, string type)
        {
            if (type == "Electricity")
            {
                try
                {
                    ///get elec meter object from API
                    ElectricityMeter meter = ResponseReader.convertTo<ElectricityMeter>(emAPI.getMeter(meterId));
                    MeterViewModel model = new MeterViewModel(meter);
                    model.BelongsToProperty = propertyId;

                    model.Meter.Invoices = model.Meter.Invoices.OrderByDescending(inv => inv.BillDate).ToList();

                    ///forecast invoice if possible
                    Invoice nextInvoice = ResponseReader.convertTo<Invoice>(emAPI.forecastNextInvoice(meterId));
                    if (nextInvoice != null)
                    {
                        model.ForecastedInvoice = nextInvoice;
                    }

                    return View(model);
                }
                catch
                {
                    return View("Error");
                }
            }
            else if (type == "Gas")
            {

                try
                {
                    ///get gas meter from API
                    GasMeter meter = ResponseReader.convertTo<GasMeter>(emAPI.getMeter(meterId));
                    MeterViewModel model = new MeterViewModel(meter);
                    model.BelongsToProperty = propertyId;

                    model.Meter.Invoices = model.Meter.Invoices.OrderByDescending(inv => inv.BillDate).ToList();

                    ///forecast invoice if possible
                    Invoice nextInvoice = ResponseReader.convertTo<Invoice>(emAPI.forecastNextInvoice(meterId));
                    if (nextInvoice != null)
                    {
                        model.ForecastedInvoice = nextInvoice;
                    }

                    return View(model);
                }
                catch
                {
                    return View("Error");
                }

            }
            else
            {
                ///unrecognised meter type
                ///
                return View("Home", "User");
            }
        }
        //
        // GET: /Meter/Edit/5
        public ActionResult Edit(int meterId, int propertyId, string fuel)
        {
            try
            {
                Meter meter = ResponseReader.convertTo<Meter>(emAPI.getMeter(meterId));
                MeterViewModel model = new MeterViewModel(meter);
                model.BelongsToProperty = propertyId;
                model.Meter.Fuel = fuel;

                return PartialView(model);
            }
            catch
            {
                return View("Error");
            }
        }
        public ActionResult Edit(MeterViewModel model)
        {
            try
            {
                ///submit edits and check for success
                string meterJSON = JsonConvert.SerializeObject(model.Meter);
                EMResponse response = JsonConvert.DeserializeObject<EMResponse>(emAPI.editMeter(model.Meter.Id, meterJSON));

                if (response.status == EMResponse.OK)
                {
                    return RedirectToAction("Home", "Meter", new { meterId = model.Meter.Id, propertyId = model.BelongsToProperty, type = model.Meter.Fuel });
                }
                else
                {
                    return View("Error");
                }
            }
            catch
            {
                return View("Error");
            }
        }
 public ActionResult Delete(MeterViewModel model)
 {
     try
     {
         ///submit delete and check for success
         EMResponse response = JsonConvert.DeserializeObject<EMResponse>(emAPI.deleteMeter(model.Meter.Id, model.BelongsToProperty));
         if (response.status == EMResponse.OK)
         {
             return RedirectToAction("Home", "Property", new { id = model.BelongsToProperty });
         }
         else
         {
             return View("Error");
         }
     }
     catch
     {
         return View("Error");
     }
 }