public ActionResult Index() { Player o = new Player(); //string name = o. // Get all users by sorting by createdate var players = MongoHelper.GetDatabase(). GetCollection("players"). FindAll(). SetSortOrder(SortBy.Descending("createdate")); return View(players); }
public ActionResult New(string id, Player palyerToEdit) { // Get user collection reference var players = MongoHelper.GetDatabase().GetCollection("players"); // Create BsonDocument object for new player var player = new BsonDocument(); player["firstname"] = palyerToEdit.FirstName; player["lastname"] = palyerToEdit.LastName; player["age"] = palyerToEdit.Age; player["createdate"] = DateTime.Now; // Insert new Player object to collection players.Insert(player); return RedirectToAction("Index"); }
public ActionResult Edit(string id, Player playerToEdit) { // Get user collection reference var players = MongoHelper.GetDatabase().GetCollection("players"); // Update palyer by id var player = players.FindOneById(ObjectId.Parse(id)); player["firstname"] = playerToEdit.FirstName; player["lastname"] = playerToEdit.LastName; player["age"] = playerToEdit.Age; // Update player object players.Save(player); return RedirectToAction("Index"); }