Esempio n. 1
0
        public ActionResult Creature(CreatureViewModel CreatureViewModel)
        {
            if (ConvertHelper.IsOfTypeCode(this.ControllerContext.RouteData.Values["species"], TypeCode.Int32) &&
                ConvertHelper.IsOfTypeCode(this.ControllerContext.RouteData.Values["stage"], TypeCode.Int32) &&
                ConvertHelper.IsOfTypeCode(this.ControllerContext.RouteData.Values["element"], TypeCode.Int32))
            {
                if (CreatureViewModel.Creatures == null)
                {
                    var CreatureRepository = new CreatureRepository();
                    CreatureViewModel.Creatures = CreatureRepository.GetCreatures();
                }

                foreach (var Creature in CreatureViewModel.Creatures)
                {
                    if (Creature.SpeciesId == Convert.ToInt32(this.ControllerContext.RouteData.Values["species"]) &&
                        Creature.EvolutionStage == Convert.ToInt32(this.ControllerContext.RouteData.Values["stage"]) &&
                        Creature.Element.Id == Convert.ToInt32(this.ControllerContext.RouteData.Values["element"]))
                    {
                        CreatureViewModel.Creature = Creature;
                    }
                }

                return(View(CreatureViewModel));
            }
            else
            {
                return(RedirectToAction("Creatures"));
            }
        }
Esempio n. 2
0
        public UnitOfWork(DatabaseContext context)
        {
            _context = context;

            AccountRepository = new AccountRepository(_context);
            ImageRepository   = new ImageRepository(_context);

            BracketRepository            = new BracketRepository(_context);
            CreatureSubmissionRepository = new CreatureSubmissionRepository(_context);
            UserBracketRepository        = new UserBracketRepository(_context);
            ChatMessageRepository        = new ChatMessageRepository(_context);
            RegistryRepository           = new RegistryRepository(_context);
            RoundRepository    = new RoundRepository(_context);
            MatchupRepository  = new MatchupRepository(_context);
            VoteRepository     = new VoteRepository(_context);
            CreatureRepository = new CreatureRepository(_context);
        }
Esempio n. 3
0
        public ActionResult Creatures(CreatureViewModel CreatureViewModel)
        {
            if (CreatureViewModel.Creatures == null)
            {
                var CreatureRepository = new CreatureRepository();
                CreatureViewModel.Creatures = CreatureRepository.GetCreatures();
            }

            var SortElements = CreatureViewModel.Elements.Where(E => E.Value == true).Select(E => E.Key).ToArray();
            var SortRoles    = CreatureViewModel.Roles.Where(R => R.Value == true).Select(R => R.Key).ToArray();

            CreatureViewModel.CreaturesFiltered = CreatureViewModel.Creatures
                                                  .Where(C => C.EvolutionId == 0)
                                                  .Where(C => SortElements.Contains(C.Element.Id.ToString()))
                                                  .Where(C => SortRoles.Contains(C.Role.Id.ToString()))
                                                  .ToList();

            return(View(CreatureViewModel));
        }
Esempio n. 4
0
 private void SaveCreature(object sender, GameObjectSaveEventArgs e)
 {
     using (CreatureRepository repo = new CreatureRepository())
     {
         repo.Upsert(e.ActiveCreature);
     }
 }
Esempio n. 5
0
 public void UpsertInDatabase(GameObjectBase gameObject, string connectionString = "")
 {
     if (gameObject.GameObjectType == GameObjectTypeEnum.Area)
     {
         using (AreaRepository repo = new AreaRepository(connectionString))
         {
             repo.Upsert(gameObject as Area);
         }
     }
     else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation)
     {
         using (ConversationRepository repo = new ConversationRepository(connectionString))
         {
             repo.Upsert(gameObject as Conversation);
         }
     }
     else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature)
     {
         using (CreatureRepository repo = new CreatureRepository(connectionString))
         {
             repo.Upsert(gameObject as Creature);
         }
     }
     else if (gameObject.GameObjectType == GameObjectTypeEnum.Item)
     {
         using (ItemRepository repo = new ItemRepository(connectionString))
         {
             repo.Upsert(gameObject as Item);
         }
     }
     else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable)
     {
         using (PlaceableRepository repo = new PlaceableRepository(connectionString))
         {
             repo.Upsert(gameObject as Placeable);
         }
     }
     else if (gameObject.GameObjectType == GameObjectTypeEnum.Script)
     {
         using (ScriptRepository repo = new ScriptRepository(connectionString))
         {
             repo.Upsert(gameObject as Script);
         }
     }
     else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset)
     {
         using (TilesetRepository repo = new TilesetRepository(connectionString))
         {
             repo.Upsert(gameObject as Tileset);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Esempio n. 6
0
 public GameObjectBase GetFromDatabaseByID(int resourceID, GameObjectTypeEnum gameResourceType)
 {
     if (gameResourceType == GameObjectTypeEnum.Area)
     {
         using (AreaRepository repo = new AreaRepository())
         {
             return repo.GetByID(resourceID);
         }
     }
     else if (gameResourceType == GameObjectTypeEnum.Conversation)
     {
         using (ConversationRepository repo = new ConversationRepository())
         {
             return repo.GetByID(resourceID);
         }
     }
     else if (gameResourceType == GameObjectTypeEnum.Creature)
     {
         using (CreatureRepository repo = new CreatureRepository())
         {
             return repo.GetByID(resourceID);
         }
     }
     else if (gameResourceType == GameObjectTypeEnum.Item)
     {
         using (ItemRepository repo = new ItemRepository())
         {
             return repo.GetByID(resourceID);
         }
     }
     else if (gameResourceType == GameObjectTypeEnum.Placeable)
     {
         using (PlaceableRepository repo = new PlaceableRepository())
         {
             return repo.GetByID(resourceID);
         }
     }
     else if (gameResourceType == GameObjectTypeEnum.Script)
     {
         using (ScriptRepository repo = new ScriptRepository())
         {
             return repo.GetByID(resourceID);
         }
     }
     else if (gameResourceType == GameObjectTypeEnum.Tileset)
     {
         using (TilesetRepository repo = new TilesetRepository())
         {
             return repo.GetByID(resourceID);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Returns all objects from the database that have a matching resource category.
        /// </summary>
        /// <param name="resourceCategory">The resource category all return values must match</param>
        /// <param name="resourceType">The type of resource to look for.</param>
        /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
        /// <returns></returns>
        public List<GameObjectBase> GetAllFromDatabaseByResourceCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "")
        {
            List<GameObjectBase> retList = new List<GameObjectBase>();

            if (resourceType == GameObjectTypeEnum.Area)
            {
                using (AreaRepository repo = new AreaRepository(connectionString))
                {
                    return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Conversation)
            {
                using (ConversationRepository repo = new ConversationRepository(connectionString))
                {
                    return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Creature)
            {
                using (CreatureRepository repo = new CreatureRepository(connectionString))
                {
                    return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Item)
            {
                using (ItemRepository repo = new ItemRepository(connectionString))
                {
                    return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Placeable)
            {
                using (PlaceableRepository repo = new PlaceableRepository(connectionString))
                {
                    return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Script)
            {
                using (ScriptRepository repo = new ScriptRepository(connectionString))
                {
                    return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Tileset)
            {
                using (TilesetRepository repo = new TilesetRepository(connectionString))
                {
                    return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x);
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Returns True if an object exists in the database.
 /// Returns False if an object does not exist in the database.
 /// </summary>
 /// <param name="resref">The resource reference to search for.</param>
 /// <param name="resourceType">The resource type to look for.</param>
 /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
 /// <returns></returns>
 public bool DoesObjectExistInDatabase(string resref, GameObjectTypeEnum resourceType, string connectionString = "")
 {
     if (resourceType == GameObjectTypeEnum.Area)
     {
         using (AreaRepository repo = new AreaRepository(connectionString))
         {
             return repo.Exists(resref);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Conversation)
     {
         using (ConversationRepository repo = new ConversationRepository(connectionString))
         {
             return repo.Exists(resref);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Creature)
     {
         using (CreatureRepository repo = new CreatureRepository(connectionString))
         {
             return repo.Exists(resref);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Item)
     {
         using (ItemRepository repo = new ItemRepository(connectionString))
         {
             return repo.Exists(resref);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Placeable)
     {
         using (PlaceableRepository repo = new PlaceableRepository(connectionString))
         {
             return repo.Exists(resref);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Script)
     {
         using (ScriptRepository repo = new ScriptRepository(connectionString))
         {
             return repo.Exists(resref);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Tileset)
     {
         using (TilesetRepository repo = new TilesetRepository(connectionString))
         {
             return repo.Exists(resref);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Delete all objects from database that match a specified resource category.
        /// </summary>
        /// <param name="resourceCategory">The resource category to remove all objects from.</param>
        /// <param name="resourceType">The type of resource to look for.</param>
        /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
        public void DeleteFromDatabaseByCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "")
        {
            if (resourceType == GameObjectTypeEnum.Area)
            {
                using (AreaRepository repo = new AreaRepository(connectionString))
                {
                    repo.DeleteAllByCategory(resourceCategory);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Conversation)
            {
                using (ConversationRepository repo = new ConversationRepository(connectionString))
                {
                    repo.DeleteAllByCategory(resourceCategory);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Creature)
            {
                using (CreatureRepository repo = new CreatureRepository(connectionString))
                {
                    repo.DeleteAllByCategory(resourceCategory);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Item)
            {
                using (ItemRepository repo = new ItemRepository(connectionString))
                {
                    repo.DeleteAllByCategory(resourceCategory);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Placeable)
            {
                using (PlaceableRepository repo = new PlaceableRepository(connectionString))
                {
                    repo.DeleteAllByCategory(resourceCategory);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Script)
            {
                using (ScriptRepository repo = new ScriptRepository(connectionString))
                {
                    repo.DeleteAllByCategory(resourceCategory);
                }
            }
            else if (resourceType == GameObjectTypeEnum.Tileset)
            {
                using (TilesetRepository repo = new TilesetRepository(connectionString))
                {
                    repo.DeleteAllByCategory(resourceCategory);
                }
            }
            else
            {
                throw new NotSupportedException();
            }

            // Now remove the category itself.
            using (CategoryRepository repo = new CategoryRepository())
            {
                Category dbCategory = repo.GetByID(resourceCategory.ResourceID);
                repo.Delete(dbCategory);
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Deletes an object with the specified resref from the database.
 /// </summary>
 /// <param name="resref">The resource reference to search for.</param>
 /// <param name="resourceType">The type of resource to remove.</param>
 /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
 public void DeleteFromDatabase(int resourceID, GameObjectTypeEnum resourceType, string connectionString = "")
 {
     if (resourceType == GameObjectTypeEnum.Area)
     {
         using (AreaRepository repo = new AreaRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Conversation)
     {
         using (ConversationRepository repo = new ConversationRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Creature)
     {
         using (CreatureRepository repo = new CreatureRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Item)
     {
         using (ItemRepository repo = new ItemRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Placeable)
     {
         using (PlaceableRepository repo = new PlaceableRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Script)
     {
         using (ScriptRepository repo = new ScriptRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Tileset)
     {
         using (TilesetRepository repo = new TilesetRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.GameModule)
     {
         using (GameModuleRepository repo = new GameModuleRepository())
         {
             repo.Delete(resourceID);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Adds a game object to the database.
        /// </summary>
        /// <param name="gameObject">The game object to add to the database. This will be type-converted and added to the correct table when run.</param>
        /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
        public GameObjectBase AddToDatabase(GameObjectBase gameObject, string connectionString = "")
        {
            GameObjectBase resultGameObject;
            try
            {
                if (gameObject.GameObjectType == GameObjectTypeEnum.Area)
                {
                    using (AreaRepository repo = new AreaRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Area);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation)
                {
                    using (ConversationRepository repo = new ConversationRepository())
                    {
                        resultGameObject = repo.Add(gameObject as Conversation);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature)
                {
                    using (CreatureRepository repo = new CreatureRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Creature);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Item)
                {
                    using (ItemRepository repo = new ItemRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Item);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable)
                {
                    using (PlaceableRepository repo = new PlaceableRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Placeable);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Script)
                {
                    using (ScriptRepository repo = new ScriptRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Script);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset)
                {
                    using (TilesetRepository repo = new TilesetRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Tileset);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule)
                {
                    using (GameModuleRepository repo = new GameModuleRepository())
                    {
                        resultGameObject = repo.Add(gameObject as GameModule);
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            catch
            {
                throw;
            }

            return resultGameObject;
        }
 public CreaturesController()
 {
     _creatureRepository   = new CreatureRepository();
     _conferenceRepository = new ConferenceRepository();
 }
Esempio n. 13
0
        private void LoadTreeViewData(object sender, JavascriptMethodEventArgs e)
        {
            try
            {
                JSTreeNode areaRootNode;
                JSTreeNode creatureRootNode;
                JSTreeNode itemRootNode;
                JSTreeNode placeableRootNode;
                JSTreeNode conversationRootNode;
                JSTreeNode scriptRootNode;
                JSTreeNode tilesetRootNode;

                // Get each category's children for each object type
                using (AreaRepository repo = new AreaRepository())
                {
                    areaRootNode = repo.GenerateJSTreeHierarchy();
                }
                using (CreatureRepository repo = new CreatureRepository())
                {
                    creatureRootNode = repo.GenerateJSTreeHierarchy();
                }
                using (ItemRepository repo = new ItemRepository())
                {
                    itemRootNode = repo.GenerateJSTreeHierarchy();
                }
                using (PlaceableRepository repo = new PlaceableRepository())
                {
                    placeableRootNode = repo.GenerateJSTreeHierarchy();
                }
                using (ConversationRepository repo = new ConversationRepository())
                {
                    conversationRootNode = repo.GenerateJSTreeHierarchy();
                }
                using (ScriptRepository repo = new ScriptRepository())
                {
                    scriptRootNode = repo.GenerateJSTreeHierarchy();
                }
                using (TilesetRepository repo = new TilesetRepository())
                {
                    tilesetRootNode = repo.GenerateJSTreeHierarchy();
                }
                
                AsyncJavascriptCallback("LoadTreeViews_Callback",
                    JsonConvert.SerializeObject(areaRootNode),
                    JsonConvert.SerializeObject(creatureRootNode),
                    JsonConvert.SerializeObject(itemRootNode),
                    JsonConvert.SerializeObject(placeableRootNode),
                    JsonConvert.SerializeObject(conversationRootNode),
                    JsonConvert.SerializeObject(scriptRootNode),
                    JsonConvert.SerializeObject(tilesetRootNode));
            }
            catch
            {
                throw;
            }
        }