Esempio n. 1
0
        //
        // GET: /PlayerSetting/EditSetting/5

        public ActionResult EditSetting(string id)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                {
                    return(RedirectToAction("Validate", "Login"));
                }
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                {
                    ViewData["txtIsAdmin"] = "true";
                }
                else
                {
                    ViewData["txtIsAdmin"] = "false";
                }

                bool isid = true;
                try
                {
                    int x = Convert.ToInt32(id);
                }
                catch { isid = false; }

                PlayerSetting playersetting = new PlayerSetting();
                IPlayerSettingSystemDefaultRepository  systemdefaultrep  = new EntityPlayerSettingSystemDefaultRepository();
                IPlayerSettingAccountDefaultRepository accountdefaultrep = new EntityPlayerSettingAccountDefaultRepository();

                if (isid)
                {
                    IPlayerSettingRepository playersettingrep = new EntityPlayerSettingRepository();
                    playersetting = playersettingrep.GetByPlayerSettingID(Convert.ToInt32(id));
                }
                else
                {
                    // Get the system default values
                    PlayerSettingSystemDefault systemdefault = systemdefaultrep.GetByPlayerSettingName(id);
                    if (systemdefault != null)
                    {
                        playersetting.PlayerSettingID     = 0;
                        playersetting.PlayerID            = Convert.ToInt32(Session["ConfigurePlayerID"]);
                        playersetting.PlayerSettingName   = systemdefault.PlayerSettingName;
                        playersetting.PlayerSettingTypeID = systemdefault.PlayerSettingTypeID;
                        playersetting.PlayerSettingValue  = systemdefault.PlayerSettingSystemDefaultValue;
                    }

                    // Override with any existing account defaults
                    PlayerSettingAccountDefault accountdefault = accountdefaultrep.GetByPlayerSettingName(Convert.ToInt32(Session["UserAccountID"]), id);
                    if (accountdefault != null)
                    {
                        playersetting.PlayerSettingID     = 0;
                        playersetting.PlayerID            = Convert.ToInt32(Session["ConfigurePlayerID"]);
                        playersetting.PlayerSettingName   = accountdefault.PlayerSettingName;
                        playersetting.PlayerSettingTypeID = accountdefault.PlayerSettingTypeID;
                        playersetting.PlayerSettingValue  = accountdefault.PlayerSettingAccountDefaultValue;
                    }
                }

                IPlayerSettingTypeRepository typerep = new EntityPlayerSettingTypeRepository();
                ViewData["PlayerSettingTypeName"]    = typerep.GetPlayerSettingType(playersetting.PlayerSettingTypeID).PlayerSettingTypeName;
                ViewData["PlayerSettingDescription"] = systemdefaultrep.GetByPlayerSettingName(playersetting.PlayerSettingName).PlayerSettingDescription;
                IPlayerRepository playerrep = new EntityPlayerRepository();
                Player            player    = playerrep.GetPlayer(Convert.ToInt32(Session["ConfigurePlayerID"]));
                ViewData["PlayerID"]          = player.PlayerID;
                ViewData["PlayerName"]        = player.PlayerName;
                ViewData["ValidationMessage"] = String.Empty;

                return(View(playersetting));
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("PlayerSetting", "EditSetting", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }
        //
        // GET: /PlayerSettingAccountDefault/

        public ActionResult Index()
        {
            try
            {
                if (Session["UserAccountID"] == null)
                {
                    return(RedirectToAction("Validate", "Login"));
                }
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                {
                    ViewData["txtIsAdmin"] = "true";
                }
                else
                {
                    ViewData["txtIsAdmin"] = "false";
                }

                // Get the account id
                int accountid = 0;
                if (Session["UserAccountID"] != null)
                {
                    accountid = Convert.ToInt32(Session["UserAccountID"]);
                }

                // This is the list we are building to display
                List <PlayerSettingAccountDefaultView> accountdefaultviews = new List <PlayerSettingAccountDefaultView>();

                // First, get all the default system settings - this is the master list and has all the master setting names and default values
                IPlayerSettingSystemDefaultRepository    systemdefaultrep = new EntityPlayerSettingSystemDefaultRepository();
                IEnumerable <PlayerSettingSystemDefault> systemdefaults   = systemdefaultrep.GetAllPlayerSettingSystemDefaults();

                // Add an account default view for each system default
                IPlayerSettingTypeRepository typerepository = new EntityPlayerSettingTypeRepository();
                foreach (PlayerSettingSystemDefault systemdefault in systemdefaults)
                {
                    PlayerSettingAccountDefaultView accountdefaultview = new PlayerSettingAccountDefaultView();
                    accountdefaultview.PlayerSettingAccountDefaultID = 0;
                    accountdefaultview.AccountID           = accountid;
                    accountdefaultview.PlayerSettingName   = systemdefault.PlayerSettingName;
                    accountdefaultview.PlayerSettingTypeID = systemdefault.PlayerSettingTypeID;
                    accountdefaultview.PlayerSettingAccountDefaultValue = systemdefault.PlayerSettingSystemDefaultValue;
                    accountdefaultview.PlayerSettingDescription         = systemdefault.PlayerSettingDescription;

                    // Add the player setting type name
                    PlayerSettingType type = typerepository.GetPlayerSettingType(systemdefault.PlayerSettingTypeID);
                    accountdefaultview.PlayerSettingTypeName = type.PlayerSettingTypeName;
                    accountdefaultviews.Add(accountdefaultview);
                }

                // If any account player setting defaults exist - update the settings
                IPlayerSettingAccountDefaultRepository accountdefaultrep = new EntityPlayerSettingAccountDefaultRepository();
                foreach (PlayerSettingAccountDefaultView accountdefaultview in accountdefaultviews)
                {
                    PlayerSettingAccountDefault accountdefault = accountdefaultrep.GetByPlayerSettingName(accountid, accountdefaultview.PlayerSettingName);
                    if (accountdefault != null)
                    {
                        accountdefaultview.PlayerSettingAccountDefaultID    = accountdefault.PlayerSettingAccountDefaultID;
                        accountdefaultview.PlayerSettingAccountDefaultValue = accountdefault.PlayerSettingAccountDefaultValue;
                    }
                }

                accountdefaultviews.Sort();
                ViewResult result = View(accountdefaultviews);
                result.ViewName = "Index";
                return(result);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("PlayerSettingAccountDefault", "Index", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }
Esempio n. 3
0
        //
        // GET: /Player/ID

        public ActionResult Configure(int id)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                {
                    return(RedirectToAction("Validate", "Login"));
                }
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                {
                    ViewData["txtIsAdmin"] = "true";
                }
                else
                {
                    ViewData["txtIsAdmin"] = "false";
                }

                // Get the player info
                IPlayerRepository playerrep  = new EntityPlayerRepository();
                string            playername = playerrep.GetPlayer(id).PlayerName;

                // This is the list we are building to display
                List <PlayerSettingView> settingviews = new List <PlayerSettingView>();

                // First, get all the default system settings - this is the master list and has all the master setting names and default values
                IPlayerSettingSystemDefaultRepository    systemdefaultrep = new EntityPlayerSettingSystemDefaultRepository();
                IEnumerable <PlayerSettingSystemDefault> systemdefaults   = systemdefaultrep.GetAllPlayerSettingSystemDefaults();

                // Add a player setting view for each system default
                IPlayerSettingTypeRepository typerepository = new EntityPlayerSettingTypeRepository();
                foreach (PlayerSettingSystemDefault systemdefault in systemdefaults)
                {
                    PlayerSettingView settingview = new PlayerSettingView();
                    settingview.PlayerID                 = id;
                    settingview.PlayerName               = playername;
                    settingview.PlayerSettingName        = systemdefault.PlayerSettingName;
                    settingview.PlayerSettingTypeID      = systemdefault.PlayerSettingTypeID;
                    settingview.PlayerSettingTypeName    = typerepository.GetPlayerSettingType(systemdefault.PlayerSettingTypeID).PlayerSettingTypeName;
                    settingview.PlayerSettingValue       = systemdefault.PlayerSettingSystemDefaultValue;
                    settingview.PlayerSettingDescription = systemdefault.PlayerSettingDescription;
                    settingviews.Add(settingview);
                }

                // If any account player setting defaults exist - update the player settings
                IPlayerSettingAccountDefaultRepository accountdefaultrep = new EntityPlayerSettingAccountDefaultRepository();
                foreach (PlayerSettingView settingview in settingviews)
                {
                    PlayerSettingAccountDefault accountdefault = accountdefaultrep.GetByPlayerSettingName(Convert.ToInt32(Session["UserAccountID"]), settingview.PlayerSettingName);
                    if (accountdefault != null)
                    {
                        settingview.PlayerSettingValue = accountdefault.PlayerSettingAccountDefaultValue;
                    }
                }

                // See if a player setting exists
                IPlayerSettingRepository playersettingrep = new EntityPlayerSettingRepository();
                foreach (PlayerSettingView settingview in settingviews)
                {
                    PlayerSetting playersetting = playersettingrep.GetByPlayerSettingName(id, settingview.PlayerSettingName);
                    if (playersetting != null)
                    {
                        settingview.PlayerSettingID    = playersetting.PlayerSettingID;
                        settingview.PlayerSettingValue = playersetting.PlayerSettingValue;
                    }
                }

                // Save the current playerid in session so we can come back to this page
                Session["ConfigurePlayerID"] = id;

                settingviews.Sort();
                ViewResult result = View(settingviews);
                result.ViewName = "Configure";
                return(result);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Player", "Index", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }