예제 #1
0
        public IActionResult Detail(FiberLocation location)
        {
            if (location == null)
            {
                ModelState.AddModelError("", "Location Was Null");
            }
            else
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrWhiteSpace(location.Address))
                    {
                        ModelState.AddModelError("", "Please Enter Address!");
                    }

                    if (string.IsNullOrWhiteSpace(location.City))
                    {
                        ModelState.AddModelError("", "Please Enter City!");
                    }

                    if (string.IsNullOrWhiteSpace(location.State))
                    {
                        ModelState.AddModelError("", "Please Enter State!");
                    }

                    if (string.IsNullOrWhiteSpace(location.Zip))
                    {
                        ModelState.AddModelError("", "Please Enter Zip!");
                    }

                    if (Math.Abs(location.Latitude) < 0)
                    {
                        ModelState.AddModelError("", "Latitude Not Entered");
                    }

                    if (Math.Abs(location.Longitude) < 0)
                    {
                        ModelState.AddModelError("", "Longitude Not Entered");
                    }

                    using (var db = new FiberMapWeb.Database.FiberMapContext())
                    {
                        if (location.LocationId == 0 && db.FiberLocations.Where(x => x.Address == location.Address && x.City == location.City && x.State == location.State).Any())
                        {
                            ModelState.AddModelError("", "Address Has Already Been Added");
                        }
                    }

                    if (ModelState.IsValid)
                    {
                        SaveLocation(location);
                        Response.Redirect(Url.Action("List", "Admin"));
                    }
                }
            }

            return(View(location));
        }
예제 #2
0
        private void SaveLocation(FiberLocation location)
        {
            using (var db = new FiberMapWeb.Database.FiberMapContext())
            {
                if (location.LocationId == 0)
                {
                    db.Add(location);
                }
                else
                {
                    db.Update(location);
                }

                db.SaveChanges();
            }
        }
예제 #3
0
 public IActionResult Detail(int?id)
 {
     if (!id.HasValue)
     {
         // New Entry
         return(View(new FiberLocation()
         {
             LocationId = 0, Latitude = 0, Longitude = 0
         }));
     }
     else
     {
         // lookup entry
         using (var db = new FiberMapContext()) {
             var findRec = db.Find(typeof(FiberLocation), new object[] { id.Value });
             if (findRec != null)
             {
                 FiberLocation editRec = (FiberMapWeb.Database.FiberLocation)findRec;
                 return(View(editRec));
             }
         }
     }
     return(View());
 }