public IActionResult EditMongoDbGameEntry(MongoDBGame game) { try { //Get the database connection mongoDatabase = GetMongoDatabase(); //Build the where condition var filter = Builders <MongoDBGame> .Filter.Eq("GameId", game.GameId); //Build the update statement var updatestatement = Builders <MongoDBGame> .Update.Set("GameId", game.GameId); updatestatement = updatestatement.Set("Name", game.Name); updatestatement = updatestatement.Set("Author", game.Author); updatestatement = updatestatement.Set("Components", game.Components); updatestatement = updatestatement.Set("Capacity", game.Capacity); //fetch the details from CustomerDB based on id and pass into view var result = mongoDatabase.GetCollection <MongoDBGame>("Games").UpdateOne(filter, updatestatement); if (result.IsAcknowledged == false) { return(BadRequest("Unable to update Customer " + game.GameId)); } } catch (Exception ex) { throw; } return(RedirectToAction("Index")); }
public IActionResult DeleteMongoDbGameEntry(int?id) { if (id == null) { return(NotFound()); } //Get the database connection mongoDatabase = GetMongoDatabase(); //fetch the details from Games and pass into view MongoDBGame game = mongoDatabase.GetCollection <MongoDBGame>("Games").Find <MongoDBGame>(k => k.GameId == id).FirstOrDefault(); if (game == null) { return(NotFound()); } return(View(game)); }
public IActionResult DeleteMongoDbGameEntry(MongoDBGame game) { try { //Get the database connection mongoDatabase = GetMongoDatabase(); //Delete the game record var result = mongoDatabase.GetCollection <MongoDBGame>("Games").DeleteOne <MongoDBGame>(k => k.GameId == game.GameId); if (result.IsAcknowledged == false) { return(BadRequest("Unable to Delete Game " + game.GameId)); } } catch (Exception ex) { throw; } return(RedirectToAction("Index")); }
public IActionResult CreateMongoDbGameEntry(MongoDBGame game) { //TODO: Set the variables for game by requesting forms from the view and save it in the game object before inserting. //Might want to hide the forms away, atleast some of them. try { if (this._userManager.GetUserAsync(HttpContext.User) != null) { var user = this._userManager.GetUserAsync(HttpContext.User); if (user.Result != null) { mongoDatabase = GetMongoDatabase(); game.Id = MongoDB.Bson.ObjectId.GenerateNewId(); game.GameId = Guid.NewGuid().GetHashCode(); game.Author = user.Result.FirstName + " " + user.Result.LastName; game.Components = HttpContext.Request.Form["ContentsOfCanvas"].ToString(); mongoDatabase.GetCollection <MongoDBGame>("Games").InsertOne(game); Game g = new Game(); g.GameId = game.GameId; g.Name = game.Name; g.Author = game.Author; g.Components = game.Components; g.Capacity = game.Capacity; g.SaveDetails(); } } } catch (Exception e) { throw; } return(RedirectToAction("Index")); }