コード例 #1
0
ファイル: PlayerController.cs プロジェクト: siyaonthedot/PTRT
        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);
        }
コード例 #2
0
ファイル: PlayerController.cs プロジェクト: siyaonthedot/PTRT
        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");
        }
コード例 #3
0
ファイル: PlayerController.cs プロジェクト: siyaonthedot/PTRT
        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");
        }