A YouFood restaurant entity
コード例 #1
0
 public ActionResult Create(Restaurant restaurant)
 {
     if (ModelState.IsValid) {
         restaurantRepository.InsertOrUpdate(restaurant);
         restaurantRepository.Save();
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }
コード例 #2
0
 public void InsertOrUpdate(Restaurant restaurant)
 {
     if (restaurant.Id == default(System.Guid)) {
         // New entity
         restaurant.Id = Guid.NewGuid();
         context.Restaurants.Add(restaurant);
     } else {
         // Existing entity
         context.Entry(restaurant).State = EntityState.Modified;
     }
 }