public PartialViewResult ViewDropsFrom(int id) { PartialViewResult response = new PartialViewResult(); //try to connect to the database via multiple DAO's try { //creating and populating a list, describing Enemy and Item Relationship based on a JunctionTable List <EnemyItemDO> doList = linkDAO.ViewByItemID(id); //gathering selected items information for View Model ItemDO tempItem = iDAO.ViewItemSingle(id); ItemPO viewItem = Mapper.Mapper.ItemDOtoPO(tempItem); //gathering enemy information using the EnemyID's found in out Enemy Item Relationship list List <EnemyDO> tempEnemyList = new List <EnemyDO>(); foreach (EnemyItemDO item in doList) { //adding each Enemy to our EnemyDO list tempEnemyList.Add(eDAO.ViewSingleEnemy(item.EnemyID)); } //converting our EnemyDO List to an EnemyPO List List <EnemyPO> enemyList = Mapper.Mapper.EnemyDOListToPO(tempEnemyList); //instantiatin our View Model ItemDropsVM itemVM = new ItemDropsVM(); //settingg View Model values to our collected information //---Item information //---EnemyPO List itemVM.item = viewItem; itemVM.enemies = enemyList; //setting our response to our target Partial View, passing in our View Model response = PartialView("_ViewDropsFrom", itemVM); } //catch and log any unlogged sqlExceptions catch (SqlException sqlEx) { if (!((bool)sqlEx.Data["Logged"] == true) || !sqlEx.Data.Contains("Logged")) { Logger.LogSqlException(sqlEx); } } catch (Exception ex) { if (!ex.Data.Contains("Logged") || (bool)ex.Data["Logged"] == false) { Logger.LogException(ex); } } return(response); }
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); }