Esempio n. 1
0
        public Result <Game> GetById(int gameID)
        {
            Result <Game> retVal = null;

            try
            {
                Game         game     = Uow.Games.GetById(gameID);
                GameCategory category = Uow.GameCategories.GetById(game.GameCategoryID);

                if (!String.IsNullOrEmpty(game.PictureUrl))
                {
                    game.PictureUrl += String.Format("?nocache={0}", DateTime.Now.Ticks);
                }
                else if (!String.IsNullOrEmpty(category.PictureUrl))
                {
                    game.PictureUrl = String.Format("{0}?nocache={1}", category.PictureUrl, DateTime.Now.Ticks);
                }

                retVal = ResultHandler <Game> .Sucess(game);
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Error retreiving game. ID: {0}", gameID), ex);
                retVal = ResultHandler <Game> .Erorr("Error retreiving game");
            }
            return(retVal);
        }
Esempio n. 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newGame = new Game();

            if (selectedCategories != null)
            {
                newGame.GameCategories = new List <GameCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new GameCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newGame.GameCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Game>(
                    newGame,
                    "Game",
                    i => i.Name, i => i.Creator,
                    i => i.Price, i => i.ReleaseDate, i => i.PublisherID))
            {
                _context.Game.Add(newGame);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newGame);
            return(Page());
        }
Esempio n. 3
0
        public List <VmGame> SearchGame(VmGameSearch condition, out long total)
        {
            var          repository = base.UnitOfWork.Repository <Game>();
            GameCategory category   = (GameCategory)Convert.ToInt32(condition.Category);
            var          query      = from gameInfo in repository.Queryable()
                                      select gameInfo;

            if (category != GameCategory.All)
            {
                query = query.Where(m => m.Info.Category == category);
            }
            if (!string.IsNullOrEmpty(condition.Name))
            {
                query = query.Where(m => m.Info.Name.Contains(condition.Name));
            }
            total = query.Count();
            return(query.Select(m => new VmGame
            {
                Id = m.Id,
                Name = m.Info.Name,
                Description = m.Info.Description,
                Category = m.Info.Category,
                Rule = m.Info.Rule,
                Author = m.Info.Author.Name,
                AuthorId = m.Info.AuthorId
            }).ToList());
        }
        public Result <GameCategory> UpdateGameCategory(GameCategory gameCategory)
        {
            Result <GameCategory> retVal = null;

            try
            {
                if (CheckExisting(gameCategory))
                {
                    retVal = ResultHandler <GameCategory> .Erorr("Duplicate game category");
                }
                else
                {
                    Uow.GameCategories.Update(gameCategory, gameCategory.GameCategoryID);
                    Uow.Commit();
                    retVal = ResultHandler <GameCategory> .Sucess(gameCategory);
                }
            }
            catch (Exception ex)
            {
                log.Error("Error updating game category", ex);
                retVal = ResultHandler <GameCategory> .Erorr("Error updating game category");
            }

            return(retVal);
        }
Esempio n. 5
0
        public void LoadImages(List <Game> games)
        {
            try
            {
                int gmaeCategoryID = games.FirstOrDefault().GameCategoryID;

                GameCategory category = Uow.GameCategories.GetById(gmaeCategoryID);

                string gameCategoryPictureUrl = !String.IsNullOrEmpty(category.PictureUrl) ?
                                                category.PictureUrl + String.Format("?nocache={0}", DateTime.Now.Ticks) :
                                                String.Empty;

                foreach (Game game in games)
                {
                    if (!String.IsNullOrEmpty(game.PictureUrl))
                    {
                        game.PictureUrl += String.Format("?nocache={0}", DateTime.Now.Ticks);
                    }
                    else
                    {
                        game.PictureUrl = gameCategoryPictureUrl;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Error loading images for games", ex);
            }
        }
Esempio n. 6
0
        public HttpResponseMessage SearchPlayers([FromUri] AdvancedSearchArgs args)
        {
            if (args.Search == null)
            {
                args.Search = String.Empty;
            }
            User         currentUser  = userBusiness.GetUserByExternalId(User.Identity.GetUserId()).Data;
            GameCategory gameCategory = gameCategoryBusiness.GetByCompetitorId(args.ID);
            List <long>  playerIDs    = competitorBusiness.GetPlayerIdsForTeam(args.ID);

            Result <PagedResult <Player> > res = competitorBusiness.SearchPlayersForGameCategory(args.Page,
                                                                                                 args.Count,
                                                                                                 currentUser.UserID,
                                                                                                 gameCategory.GameCategoryID,
                                                                                                 playerIDs,
                                                                                                 args.Search);

            if (res.Success)
            {
                competitorBusiness.LoadUsers(res.Data.Items);
            }

            HttpResponseMessage response = res.Success ?
                                           Request.CreateResponse(HttpStatusCode.OK, res.Data) :
                                           Request.CreateResponse(HttpStatusCode.InternalServerError, res.Message);

            return(response);
        }
 public InternalImmutableLoadOrderLinkCache(
     IEnumerable <IModGetter> loadOrder,
     GameCategory gameCategory,
     bool hasAny,
     bool simple,
     LinkCachePreferences?prefs)
 {
     prefs ??= LinkCachePreferences.Default;
     _listedOrder   = loadOrder.ToList();
     _priorityOrder = _listedOrder.Reverse().ToList();
     _formKeyCache  = new ImmutableLoadOrderLinkCacheCategory <FormKey>(
         gameCategory,
         hasAny: hasAny,
         simple: simple,
         listedOrder: _listedOrder,
         m => TryGet <FormKey> .Succeed(m.FormKey),
         f => f.IsNull);
     this._editorIdCache = new ImmutableLoadOrderLinkCacheCategory <string>(
         gameCategory,
         hasAny: hasAny,
         simple: simple,
         listedOrder: _listedOrder,
         m =>
     {
         var edid = m.EditorID;
         return(TryGet <string> .Create(successful: !string.IsNullOrWhiteSpace(edid), edid !));
     },
Esempio n. 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,GameCategoryName")] GameCategory gameCategory)
        {
            if (id != gameCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gameCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GameCategoryExists(gameCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(gameCategory));
        }
Esempio n. 9
0
        public void RemoveElectedCategory()
        {
            var category = new Category {
                Id = 1, Description = "Category 1"
            };
            var categories = new List <Category> {
                category
            };
            var game = new Game {
                Id = 1, Name = "Game 1"
            };
            var games = new List <Game> {
                game
            };
            var electedCategory = new GameCategory {
                GameId = game.Id, CategoryId = category.Id
            };
            var electedCategories = new List <GameCategory> {
                electedCategory
            };

            var context = _fixture.Context
                          .CategoriesContain(categories)
                          .GamesContain(games)
                          .GameCategoriesContain(electedCategories);
            var gameRepository = new GameRepository(context);

            gameRepository.RemoveElectedCategory(game.Id, category.Id);

            var result = gameRepository.GetAllCategoriesBy(category.Id);

            Assert.False(result.Any());
        }
Esempio n. 10
0
        public Participant AddParticipant(Guid gameId, Guid categoryId, Enums.TurnType turnType, string userId)
        {
            try
            {
                var duplicateParticipants = _context.Participants.Where(x => x.GameId == gameId && x.UserId == userId && x.Deleted == null);
                if (duplicateParticipants.Any())
                {
                    throw new DataException("User is already participating in this game.");
                }

                var participant = new Participant()
                {
                    UserId   = userId,
                    GameId   = gameId,
                    TurnType = turnType
                };

                var addedparticipant = _context.Add(participant).Entity;

                var gameCategory = new GameCategory()
                {
                    CategoryId    = categoryId,
                    GameId        = gameId,
                    ParticipantId = addedparticipant.Id
                };
                _context.Add(gameCategory);

                _context.SaveChanges();
                return(addedparticipant);
            }
            catch (Exception e)
            {
                throw new DataException("Could not add new participant", e);
            }
        }
Esempio n. 11
0
 public static bool HasFormVersion(this GameCategory release)
 {
     return(release switch
     {
         GameCategory.Oblivion => false,
         GameCategory.Skyrim => true,
         _ => throw new NotImplementedException(),
     });
 /// <summary>
 /// Creates a CategoryPlayerAnswer instance based on data given.
 /// </summary>
 /// <param name="id">Identifier</param>
 /// <param name="player">Player who wrote the answer</param>
 /// <param name="gameCategory">GameCategory where the answer belongs to</param>
 /// <param name="answer">Answer written by the Player</param>
 /// <param name="round">Round where the answer was written</param>
 public CategoryPlayerAnswer(int id, Player player, GameCategory gameCategory, string answer, int round)
 {
     this.id           = id;
     this.player       = player;
     this.gameCategory = gameCategory;
     this.answer       = answer;
     this.round        = round;
 }
Esempio n. 13
0
 public static ILoquiRegistration ToModRegistration(this GameCategory category)
 {
     return(category switch
     {
         GameCategory.Oblivion => OblivionMod_Registration.Instance,
         GameCategory.Skyrim => SkyrimMod_Registration.Instance,
         _ => throw new NotImplementedException(),
     });
Esempio n. 14
0
        private bool CheckExisting(GameCategory gameCategory)
        {
            bool retVal = Uow.GameCategories
                          .GetAll()
                          .FirstOrDefault(gc => gc.Title == gameCategory.Title &&
                                          gc.GameCategoryID != gameCategory.GameCategoryID) != null;

            return(retVal);
        }
Esempio n. 15
0
        public GameCategoryModel(
            GameCategory gameCategory,
            IResourceService resourceService
            )
        {
            GameCategory = gameCategory;
            var imageUrl = gameCategory.ToString();

            ImageId = resourceService.GetDrawableId(imageUrl);
        }
Esempio n. 16
0
        public void TestPexParsing(string file, GameCategory gameCategory)
        {
            var path = Path.Combine("Pex", "files", file);

            Assert.True(File.Exists(path));

            var pex = PexFile.CreateFromFile(path, gameCategory);

            Assert.NotNull(pex);
        }
        public static FilePath?GetListingsPath(GameCategory category, DirectoryPath dataPath)
        {
            var categoryInject = new GameCategoryInjection(category);

            return(new CreationClubListingsPathProvider(
                       categoryInject,
                       new CreationClubEnabledProvider(
                           categoryInject),
                       new GameDirectoryInjection(dataPath.Directory !.Value)).Path);
        }
Esempio n. 18
0
        public static PexFile CreateFromFile(string file, GameCategory gameCategory)
        {
            if (!File.Exists(file))
            {
                throw new ArgumentException($"Input file does not exist {file}!", nameof(file));
            }

            using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
            return(CreateFromStream(fs, gameCategory));
        }
Esempio n. 19
0
        public async Task <IActionResult> Create([Bind("Id,GameCategoryName")] GameCategory gameCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gameCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gameCategory));
        }
Esempio n. 20
0
        public bool TryGetConfiguration(string mimeType, string extension, out EmulatorConfiguration configuration)
        {
            var configurations = Load().Where(c => c.Platforms.Any(p => GameCategory.CategoryNameToMimeType(p) == mimeType));

            configuration = configurations.FirstOrDefault(c => c.FileExtensions.Contains(extension));
            if (configuration == null)
            {
                configuration = configurations.FirstOrDefault(c => c.FileExtensions.Count == 0);
            }
            return(configuration != null);
        }
Esempio n. 21
0
        public GameCategory GetByCompetitorId(long competitorID)
        {
            GameCategory retVal = Uow.Competitors
                                  .GetAll()
                                  .Where(c => c.CompetitorID == competitorID)
                                  .SelectMany(c => c.Games)
                                  .Select(g => g.Game.Category)
                                  .FirstOrDefault();

            return(retVal);
        }
        public HttpResponseMessage AddGameCategory(GameCategory gameCategory)
        {
            Result <GameCategory> res =
                gameCategoryBusiness.AddGameCategory(gameCategory);

            HttpResponseMessage response = res.Success ?
                                           Request.CreateResponse(HttpStatusCode.Created, res.Data) :
                                           Request.CreateResponse(HttpStatusCode.InternalServerError, res.Message);

            return(response);
        }
Esempio n. 23
0
        public ActionResult Update(Game game, HttpPostedFileBase picture, int categoryId)
        {
            try
            {
                GameDao         gameDao         = new GameDao();
                GameCategoryDao gameCategoryDao = new GameCategoryDao();

                GameCategory gameCategory = gameCategoryDao.GetById(categoryId);

                game.Category = gameCategory;

                if (picture != null)
                {
                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image = Image.FromStream(picture.InputStream);

                        Guid   guid      = Guid.NewGuid();
                        string imageName = guid.ToString() + ".jpg";

                        if (image.Height > 200 || image.Width > 200)
                        {
                            Image  smallImage = Class.ImageHelper.ScaleImage(image, 200, 200);
                            Bitmap b          = new Bitmap(smallImage);



                            b.Save(Server.MapPath("~/uploads/game/" + imageName), ImageFormat.Jpeg);

                            smallImage.Dispose();
                            b.Dispose();
                        }
                        else
                        {
                            picture.SaveAs(Server.MapPath("~/uploads/game/" + picture.FileName));
                        }


                        game.ImageName = imageName;
                    }
                }

                gameDao.Update(game);

                TempData["message-success"] = "Hra" + game.Name + "byla upravena";
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("Index", "Games"));
        }
Esempio n. 24
0
        public static IEnumerable <LoadOrderListing> GetListings(GameCategory category, DirectoryPath dataPath)
        {
            var path = GetListingsPath(category, dataPath);

            if (!path.Exists)
            {
                return(Enumerable.Empty <LoadOrderListing>());
            }
            return(ListingsFromPath(
                       path,
                       dataPath));
        }
        /// <summary>
        /// Constructs a LoadOrderLinkCache around a target load order
        /// </summary>
        /// <param name="loadOrder">LoadOrder to resolve against when linking</param>
        public ImmutableLoadOrderLinkCache(IEnumerable <TModGetter> loadOrder)
        {
            this._listedOrder   = loadOrder.ToList();
            this._priorityOrder = _listedOrder.Reverse().ToList();
            var firstMod = _listedOrder.FirstOrDefault();

            this._hasAny = firstMod != null;
            // ToDo
            // Upgrade to bounce off ModInstantiator systems
            this._gameCategory   = firstMod?.GameRelease.ToCategory() ?? GameCategory.Oblivion;
            this._linkInterfaces = LinkInterfaceMapping.InterfaceToObjectTypes(_gameCategory);
        }
Esempio n. 26
0
        public static IEnumerable <IModListingGetter> GetListings(GameCategory category, DirectoryPath dataPath)
        {
            var path = GetListingsPath(category, dataPath);

            if (path == null || !path.Value.Exists)
            {
                return(Enumerable.Empty <IModListingGetter>());
            }
            return(ListingsFromPath(
                       path.Value,
                       dataPath));
        }
Esempio n. 27
0
        public static FilePath GetListingsPath(GameCategory category, DirectoryPath dataPath)
        {
            switch (category)
            {
            case GameCategory.Oblivion:
                throw new ArgumentException();

            case GameCategory.Skyrim:
                return(Path.Combine(Path.GetDirectoryName(dataPath.Path) !, $"{category}.ccc"));

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 28
0
        public ActionResult Add(Game game, HttpPostedFileBase picture, int categoryId)
        {
            if (ModelState.IsValid)
            {
                if (picture != null)
                {
                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image = Image.FromStream(picture.InputStream);
                        if (image.Height > 200 || image.Width > 200)
                        {
                            Image  smallImage = Class.ImageHelper.ScaleImage(image, 200, 200);
                            Bitmap b          = new Bitmap(smallImage);

                            Guid   guid      = Guid.NewGuid();
                            string imageName = guid.ToString() + ".jpg";

                            b.Save(Server.MapPath("~/uploads/game/" + imageName), ImageFormat.Jpeg);

                            smallImage.Dispose();
                            b.Dispose();

                            game.ImageName = imageName;
                        }
                        else
                        {
                            picture.SaveAs(Server.MapPath("~/uploads/game/" + picture.FileName));
                        }
                    }
                }

                GameCategoryDao gameCategoryDao = new GameCategoryDao();
                GameCategory    gameCategory    = gameCategoryDao.GetById(categoryId);

                game.Category = gameCategory;

                GameDao gameDao = new GameDao();
                gameDao.Create(game);

                TempData["message-success"] = "Hra byla úspěšně vytvořena";
            }
            else
            {
                return(View("Create", game));
            }



            return(RedirectToAction("Index"));
        }
Esempio n. 29
0
        /// <summary>
        /// Returns whether given game needs timestamp alignment for its load order
        /// </summary>
        /// <param name="game">Game to check</param>
        /// <returns>True if file located</returns>
        public static bool NeedsTimestampAlignment(GameCategory game)
        {
            switch (game)
            {
            case GameCategory.Oblivion:
                return(true);

            case GameCategory.Skyrim:
                return(false);

            default:
                throw new NotImplementedException();
            }
        }
        public static IEnumerable <IModListingGetter> GetListings(GameCategory category, DirectoryPath dataPath)
        {
            var gameCategoryInjection  = new GameCategoryInjection(category);
            var dataDirectoryInjection = new DataDirectoryInjection(dataPath);

            return(new CreationClubListingsProvider(
                       IFileSystemExt.DefaultFilesystem,
                       dataDirectoryInjection,
                       new CreationClubListingsPathProvider(
                           gameCategoryInjection,
                           new CreationClubEnabledProvider(
                               gameCategoryInjection),
                           new GameDirectoryInjection(dataPath.Directory !.Value)),
                       new CreationClubRawListingsReader()).Get());
        }
Esempio n. 31
0
 public IGameEvaluationResult Success(GameCategory category, IEnumerable<Card> usedCards)
 {
     return new SuccessGameEvaluationResult(category, usedCards);
 }
 public GameEvaluationResultBase(GameCategory category, IEnumerable<Card> usedCards)
 {
     Category = category;
     UsedCards = usedCards;
 }
 public SuccessGameEvaluationResult(GameCategory category, IEnumerable<Card> usedCards)
     : base(category, usedCards)
 {
 }