Пример #1
0
 public ActionResult Create(Location location, int country)
 {
     if (location != null)
     {
         Country item = _db.Countries.FirstOrDefault(x => x.Id == country);
         if (item != null)
         {
             location.Country = item;
             _db.Locations.Add(location);
             _db.SaveChanges();
             Success("Your information was saved!");
             return RedirectToAction("Index");
         }
     }
     Error("there were some errors in your form.");
     ViewData["Country"] = _db.Countries.ToArray();
     return View(location);
 }
Пример #2
0
        public ActionResult Edit(Location location, int country)
        {
            if (location != null)
            {
                _db.Entry(location).State = EntityState.Modified;
                _db.SaveChanges();

                Country item = _db.Countries.FirstOrDefault(x => x.Id == country);
                if (item != null)
                {
                    location = _db.Locations.First(x => x.Id == location.Id);
                    location.Country = item;
                    _db.SaveChanges();
                }
                Success("The model was updated!");
                return RedirectToAction("Index");
            }
            ViewData["Country"] = _db.Countries.ToArray();
            return View("Create", location);
        }