public ActionResult Create(Room room) { try { if (ModelState.IsValid) { db.Rooms.Add(room); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.RoomTypeID = new SelectList(db.RoomTypes, "RoomTypeID", "RoomTypeName", room.RoomTypeID); ViewBag.DataCenterID = new SelectList(db.DataCenters, "DataCenterID", "DataCenterName", room.DataCenterID); return View(room); } catch (Exception ex) { throw new ApplicationException("Something wrong happened Data Cant be added :", ex); } }
public ActionResult Edit(Room room) { try { if (ModelState.IsValid) { db.Entry(room).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.RoomTypeID = new SelectList(db.RoomTypes, "RoomTypeID", "RoomTypeName", room.RoomTypeID); ViewBag.DataCenterID = new SelectList(db.DataCenters, "DataCenterID", "DataCenterName", room.DataCenterID); return View(room); } catch (Exception ex) { throw new ApplicationException("Something wrong While Editing :", ex); } }