Exemple #1
0
        public void AddBanter(string message, int gameId, int userTeamId, string who)
        {
            string name = Context.User.Identity.Name;

            foreach (var connectionId in _connections.GetConnections(who))
            {
                Clients.Client(connectionId).testAdd(name + ": " + message, gameId);
            }

            try
            {
                _service.AddBanter(gameId, userTeamId, message);
                var        _updatedBanter = _service.GetGameBanter(1);
                BantersDto _bantersDto    = new BantersDto()
                {
                    Banter = _updatedBanter, CurrentGameId = gameId, CurrentUserTeamId = userTeamId
                };

                // this method i create a dummy controller that can return a partialview to the page - thus i can actually get ALL the banter and refresh the entire view instead of appending bits...
                //http://stackoverflow.com/questions/22098233/partialview-to-html-string
                var bogusController = ViewRenderer.CreateController <HomeController>();

                // var partialViewGuts = ViewRenderer.RenderPartialViewToString(bogusController.ControllerContext, "view", model);
                var partialViewGuts = ViewRenderer.RenderPartialView("~/Views/ViewPlayers/banterlist.cshtml", _bantersDto, bogusController.ControllerContext);
                Clients.All.addNewBanterToPage(partialViewGuts);
            }
            catch (Exception ex)
            {
                Clients.All.addNewBanterToPage("There has been a problem getting the banter");
            }
        }