Пример #1
0
 public HomeController()
 {
     this.connectionString = ConfigurationManager.ConnectionStrings["dataSource"].ConnectionString;
     this.logPath          = Path.Combine(Path.GetDirectoryName(System.Web.HttpContext.Current.Server.MapPath("~")), ConfigurationManager.AppSettings["relative"]);
     linkDAO = new EnemyItemDAO(connectionString, logPath);
     iDAO    = new ItemDAO(connectionString, logPath);
 }
Пример #2
0
 public StatsController()
 {
     this.connectionString = ConfigurationManager.ConnectionStrings["dataSource"].ConnectionString;
     this.logPath          = ConfigurationManager.AppSettings["relative"];
     linkDAO = new EnemyItemDAO(connectionString, logPath);
     iDAO    = new ItemDAO(connectionString, logPath);
     eDAO    = new EnemyDAO(connectionString, logPath);
 }
Пример #3
0
        public PartialViewResult ViewEnemyDrops(int id)
        {
            //instantiating our response
            PartialViewResult response;

            try
            {
                //instantiate a enemy_itemDAO and fill a list with item id's based on enemy id
                EnemyItemDAO       linkDAO       = new EnemyItemDAO(connectionString, logPath);
                List <EnemyItemDO> enemyDropList = linkDAO.ViewByEnemyID(id);

                //instantiate itemdao and populte an item List using itemID's found in enemyDropList
                List <ItemDO> dropListDO = new List <ItemDO>();
                ItemDAO       iDAO       = new ItemDAO(connectionString, logPath);
                foreach (EnemyItemDO item in enemyDropList)
                {
                    dropListDO.Add(iDAO.ViewItemSingle(item.ItemID));
                }

                //mapping DO droplist to PO
                List <ItemPO> dropList = Mapper.Mapper.ItemDOListToPO(dropListDO);

                //create enemy drops vm and assign enemy information and PO dropList to it
                EnemyDropsVM enemyVM = new EnemyDropsVM();
                enemyVM.Items   = dropList;
                enemyVM.enemyID = id;

                //set response PartialView to target the correct partial view, and provide EnemyDropVM
                response = PartialView("_ViewEnemyDrops", enemyVM);
            }
            //Catch any sql exceptions encountered
            catch (SqlException sqlEx)
            {
                //check to see if the exception has already been logged. If not, then log it
                if (!sqlEx.Data.Contains("Logged") || (bool)sqlEx.Data["Logged"] == false)
                {
                    Logger.LogSqlException(sqlEx);
                }
                //set response to a blank partialview();
                response = PartialView();
            }
            //catch any non-sqlexception encountered
            catch (Exception ex)
            {
                //check to see if the exception has been logged. If not, then log it
                if (!ex.Data.Contains("Logged)") || (bool)ex.Data["Logged"] == false)
                {
                    Logger.LogException(ex);
                }
                //set response to a partialview();
                response = PartialView();
            }

            return(response);
        }
Пример #4
0
        public ActionResult UpdateEnemy(int id)
        {
            ActionResult  response;
            EnemyUpdateVM enemy = new EnemyUpdateVM();

            try
            {
                //mapping an enemypo to our VM
                enemy.Enemy = Mapper.Mapper.EnemyDOtoPO(eDAO.ViewSingleEnemy(id));

                //instantiating an enemy_itemDAO
                EnemyItemDAO linkDAO = new EnemyItemDAO(connectionString, logPath);

                //collecting item id's linked to the enemy id
                List <EnemyItemDO> itemDrops = linkDAO.ViewByEnemyID(id);

                //assigning items 1 and 2 based on what was returned from the enemy_itemDAO
                if (itemDrops.Count >= 1)
                {
                    //sets Item1 to the itemid from the link table in the database
                    enemy.Item1 = itemDrops[0].ItemID;
                    //checks to see if there was a second item linked to the enemy
                    if (itemDrops.Count == 2)
                    {
                        //sets Item2 to the second items id
                        enemy.Item2 = itemDrops[1].ItemID;
                    }
                }
                //setting default values to 0 if no items where linked to enemy
                else
                {
                    enemy.Item1 = 0;
                    enemy.Item2 = 0;
                }


                //creating and adding default item "none" to drop down list
                ItemPO @default = new ItemPO
                {
                    Name        = "None",
                    ItemID      = 0,
                    Description = ""
                };

                enemy.itemList.Add(@default);

                //adds list to existing list, does not delete old information.
                enemy.itemList.AddRange(Mapper.Mapper.ItemDOListToPO(iDAO.ViewAllItems()));

                response = View(enemy);
            }
            //catches any slqexceptions that occur during our DAO call
            catch (SqlException sqlEx)
            {
                //logs the exception IF it has not already been marked as logged
                if (!sqlEx.Data.Contains("Logged") || (bool)sqlEx.Data["Logged"] == false)
                {
                    Logger.LogSqlException(sqlEx);
                }
                //redirects to the index page of the enemy controller. The page containing the full list of enemies.
                response = RedirectToAction("Index", "Enemy");
            }
            //catches any non-sqlexceptions that may occure during mapping or otherwise
            catch (Exception ex)
            {
                //logs the exception if it has not already been marked as logged
                if (!ex.Data.Contains("Logged") || (bool)ex.Data["Logged"] == false)
                {
                    Logger.LogException(ex);
                }
                //redirects to the index page of the enemy controller. The page containing the full list of enemies.
                response = RedirectToAction("Index", "Enemy");
            }
            //passing enemy view model to view
            return(response);
        }