Exemple #1
0
        public static EnemyItemDO DetailsPOtoDO(EnemyItemIDLink from)
        {
            EnemyItemDO to = new EnemyItemDO();

            to.LinkID  = from.LinkID;
            to.EnemyID = from.EnemyID;
            to.ItemID  = from.ItemID;

            return(to);
        }
Exemple #2
0
        public static EnemyItemIDLink DetailsDOtoPO(EnemyItemDO from)
        {
            EnemyItemIDLink to = new EnemyItemIDLink();

            to.LinkID  = from.LinkID;
            to.EnemyID = from.EnemyID;
            to.ItemID  = from.ItemID;

            return(to);
        }
Exemple #3
0
        public static List <EnemyItemIDLink> DetailsDOtoPO(List <EnemyItemDO> from)
        {
            List <EnemyItemIDLink> to = new List <EnemyItemIDLink>();

            foreach (EnemyItemDO enemy in from)
            {
                EnemyItemIDLink temp = new EnemyItemIDLink();
                temp.LinkID  = enemy.LinkID;
                temp.EnemyID = enemy.EnemyID;
                temp.ItemID  = enemy.ItemID;
                to.Add(temp);
            }

            return(to);
        }
Exemple #4
0
        public ActionResult UpdateEnemy(EnemyUpdateVM form)
        {
            ActionResult response;

            //checks to make sure that all required fields are filled out
            if (ModelState.IsValid)
            {
                //if all fields are filled out, try to connect to the server
                try
                {
                    //if a file was submited, update the image of the enemy to the given file, and rename the file to the
                    //enemies name
                    if (form.File != null && form.File.ContentLength > 0)
                    {
                        //if the enemy already has an image, delete that image
                        if (System.IO.File.Exists(Server.MapPath(form.Enemy.ImagePath)))
                        {
                            System.IO.File.Delete(Server.MapPath(form.Enemy.ImagePath));
                        }
                        //find the filepath for the enemies image
                        string path = Server.MapPath(form.Enemy.ImagePath);
                        //saves the new image to the enemies image filepath
                        form.File.SaveAs(path);
                    }

                    //map the new enemy information to an EnemyDO
                    EnemyDO enemy = Mapper.Mapper.EnemyPOtoDO(form.Enemy);

                    //sending enemydo object to enemy dao, passing in the EnemyDo object
                    eDAO.UpdateEnemy(enemy);

                    //instantiate enemy_itemDAO

                    //collecting old item drop information and deleting it
                    List <EnemyItemIDLink> dropList = Mapper.Mapper.DetailsDOtoPO(linkDAO.ViewByEnemyID(form.Enemy.EnemyID));

                    //for every item linked to the enemy, delete that link. Destroys old enemy drop information
                    foreach (EnemyItemIDLink item in dropList)
                    {
                        linkDAO.DeleteEnemyItems(item.LinkID);
                    }

                    //if item1 = item2, default item2 to 0. prevents enemy from having 2 links to 1 item.
                    if (form.Item1 == form.Item2)
                    {
                        form.Item2 = 0;
                    }

                    //instantiats a new EnemyItemIDLink (object holds the information about which item drops form the enemy)
                    EnemyItemIDLink newLink = new EnemyItemIDLink();
                    //sets the newLinks enemyid to the id of the id of the enemy being updated
                    newLink.EnemyID = form.Enemy.EnemyID;

                    //creating new links for item 1 if one was selected. if the item does not exist, no link is made
                    if (form.Item1 != 0)
                    {
                        //sets the newLinks item id to the new item id found in Item1
                        newLink.ItemID = form.Item1;
                        //creates a new link between the enemy and the item. Enemy will now display the item as a drop
                        linkDAO.CreateEnemyDetails(Mapper.Mapper.DetailsPOtoDO(newLink));
                    }

                    //creating new links for item 2 if one was selected. if the item does not exist, no link is made
                    if (form.Item2 != 0)
                    {
                        //sets the newLink item id to the id found in Item2
                        newLink.ItemID = form.Item2;
                        //creates a new link between the enemy and item. Enemy will now display the item as a drop
                        linkDAO.CreateEnemyDetails(Mapper.Mapper.DetailsPOtoDO(newLink));
                    }

                    //set response to redirect to enemies homepage
                    response = RedirectToAction("Index", "Enemy");
                }
                //log any sql exceptions encountered
                catch (SqlException sqlEx)
                {
                    //checks to see if the exception has been logged, and logs it if it hasn't been
                    if (!sqlEx.Data.Contains("Logged") || (bool)sqlEx.Data["Logged"] == false)
                    {
                        Logger.LogSqlException(sqlEx);
                    }
                    //redirects to the enemy list page
                    response = RedirectToAction("Index", "Enemy");
                }
                //catches any exceptions that occure due to mapping or otherwise
                catch (Exception ex)
                {
                    //checks to see if the exception has been logged, and logs it if it hasn't been
                    if (!ex.Data.Contains("Logged") || (bool)ex.Data["Logged"] == false)
                    {
                        Logger.LogException(ex);
                    }
                    //redirects to the enemy list page
                    response = RedirectToAction("Index", "Enemy");
                }
            }
            //if modelstate is false
            else
            {
                //refills the item list for the drop down menus
                form.itemList = Mapper.Mapper.ItemDOListToPO(iDAO.ViewAllItems());

                //adds teh default item of "None" to the list in case the enemy doesn't drop an itme
                ItemPO @default = new ItemPO
                {
                    Name        = "None",
                    ItemID      = 0,
                    Description = ""
                };
                form.itemList.Add(@default);

                //creates a modelstate error stating that the form is missing information
                ModelState.AddModelError("Validated", "Missing information. Please fill in all fields.");
                //sets response to the View() and passes in the old form information including the newly populated item list
                response = View(form);
            }

            return(response);
        }