Exemplo n.º 1
0
        //DETAILS Action Method, shows the manhole, flow meters and sites associated to the site
        public ActionResult SiteDetails(int?id)
        {
            //gets the details of the site and displays it on the screen, view provides a way to make edits to the equipment.
            if (id != null)
            {
                //make queries to db
                IEnumerable <Models.FlowMeter> _flowmeters = database.flowMeters.Where(m => m.SiteId == id);
                IEnumerable <Models.Sensor>    _sensors    = database.Sensors.Where(m => m.SiteID == id);
                IEnumerable <Models.Telog>     _telogs     = database.telogs.Where(m => m.SiteID == id);
                Models.Manhole manhole = database.manholes.Where(m => m.SiteID == id).FirstOrDefault();

                string _sitename = database.sites.Where(m => m.SiteID == id).FirstOrDefault().SiteDisplayName;

                var _site = new Models.SiteView
                {
                    //find the flow meters associated to the site.
                    SiteID          = (int)id,
                    SiteFlowMeters  = _flowmeters,
                    SiteSensors     = _sensors,
                    SiteTelogs      = _telogs,
                    SiteManhole     = manhole,
                    SiteDisplayName = _sitename
                };

                ViewBag.SiteName = _sitename;

                return(View("SiteEquipment", _site));
            }
            else
            {
                //return error view. need to make error view
                return(View("Error"));
            }
        }
Exemplo n.º 2
0
 // GET: Manhole/Create
 public ActionResult Create(int?number)
 {
     //passing a manhole with the site for association.
     Models.Manhole manhole = new Models.Manhole {
         SiteID = (int)number
     };
     return(View("Create", manhole));
 }
Exemplo n.º 3
0
        public ActionResult Delete(Models.Site site)
        {
            if (ModelState.IsValid)
            {
                //removed the site from the db
                Models.Site _site = database.sites.Find((int)site.SiteID);
                database.sites.Remove(_site);
                database.SaveChanges();

                //also remove equipment that has this assigned.
                IEnumerable <Models.FlowMeter> _flowmeters = database.flowMeters.Where(m => m.SiteId == site.SiteID);
                IEnumerable <Models.Sensor>    _sensors    = database.Sensors.Where(m => m.SiteID == site.SiteID);
                IEnumerable <Models.Telog>     _telogs     = database.telogs.Where(m => m.SiteID == site.SiteID);
                Models.Manhole manhole = database.manholes.Where(m => m.SiteID == site.SiteID).FirstOrDefault();

                foreach (var f in _flowmeters)
                {
                    Models.FlowMeter flowMeter = database.flowMeters.Find(f.ID);
                    database.flowMeters.Remove(flowMeter);
                }
                database.SaveChanges();

                foreach (var s in _sensors)
                {
                    Models.Sensor sensor = database.Sensors.Find(s.ID);
                    database.Sensors.Remove(sensor);
                }
                database.SaveChanges();

                foreach (var t in _telogs)
                {
                    Models.Telog telog = database.telogs.Find(t.TelogID);
                    database.telogs.Remove(telog);
                }
                database.SaveChanges();

                Models.Manhole mh = database.manholes.Find(manhole.ManholeID);
                database.manholes.Remove(mh);
                database.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View("Delete", site));
        }