示例#1
0
 // GET: Telog/Create
 public ActionResult Create(int?number)
 {
     Models.Telog telog = new Models.Telog {
         SiteID = (int)number
     };
     return(View("Create", telog));
 }
示例#2
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));
        }