public ActionResult Rooms_Destroy([DataSourceRequest]DataSourceRequest request, Room room) { room.DeletedOn = DateTime.Now; room.CreatedOn = DateTime.Now; this.rooms.Delete(room); this.rooms.SaveChanges(); return Json(new[] { room }.ToDataSourceResult(request, ModelState)); }
public ActionResult Rooms_Update([DataSourceRequest]DataSourceRequest request, Room room) { if (ModelState.IsValid) { var entity = new Room { Id = room.Id, Name = room.Name, Capacity = room.Capacity, CreatedOn = room.CreatedOn }; db.Rooms.Attach(entity); db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } return Json(new[] { room }.ToDataSourceResult(request, ModelState)); }
public ActionResult Rooms_Create([DataSourceRequest]DataSourceRequest request, RoomInputModel room) { var newId = 0; if (ModelState.IsValid) { var entity = new Room { Name = room.Name, Capacity = room.Capacity }; entity.CreatedOn = DateTime.Now; this.rooms.Add(entity); this.rooms.SaveChanges(); newId = entity.Id; } var roomToDisplay = this.rooms.All().Project() .To<RoomViewModel>() .FirstOrDefault(x => x.Id == newId); return Json(new[] { roomToDisplay }.ToDataSourceResult(request, ModelState)); }