Esempio n. 1
0
        public RedirectToActionResult Add(string title, string date, string developer)
        {
            Game game = new Game {
                Title = title, Date = DateTime.Parse(date)
            };

            if (developer != null)
            {
                game.Developers.Add(new Developer {
                    CompanyName = developer
                });
            }

            gameRepo.AddGame(game);

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 public void AddGame(Game game)
 {
     repo.AddGame(game);
 }
Esempio n. 3
0
        public IActionResult SaveAddedGame(AddGameModel data)
        {
            try
            {
                List <Genre>   genres   = data.Genres.Select(g => genresTable.GetGenreByUrlId(g) !).ToList();
                List <Feature> features = data.Features.Select(f => featuresTable.GetFeatureByUrlId(f) !).ToList();

                var gameFilter = new GameFilter {
                    Features = features,
                    Genres   = genres
                };

                var gameMedia = new GameMedia {
                    Screenshots = data.Screenshots,
                    Trailers    = data.Trailers
                };

                var gameSystemRequirements = new GameSystemRequirement {
                    MinCpu                  = data.MinCpu,
                    MaxCpu                  = data.MaxCpu,
                    MinRamMB                = data.MinRamMB,
                    MaxRamMB                = data.MaxRamMB,
                    MinGpu                  = data.MinGpu,
                    MaxGpu                  = data.MaxGpu,
                    DiskSpaceMB             = data.DiskSpaceMB,
                    DirectX                 = data.DirectX,
                    SupportedOses           = data.SupportedOses,
                    ExtraInfo               = data.ExtraInfo == null ? "" : data.ExtraInfo,
                    SupportedTextLanguages  = data.SupportedTextLanguages,
                    SupportedVoiceLanguages = data.SupportedVoiceLanguages
                };

                var discount = float.Parse(data.Discount.Replace('.', ','));

                DateTime discountEndDate = discount != 0 && !string.IsNullOrEmpty(data.DiscountEndDate)
                    ? Convert.ToDateTime(data.DiscountEndDate)
                    : DateTime.MinValue;

                var releaseDate = Convert.ToDateTime(data.ReleaseDate);

                var gameInfo = new GameInfo {
                    Cover               = data.Cover,
                    Price               = data.Price,
                    Discount            = discount,
                    DiscountEndDate     = discountEndDate,
                    ReleaseDate         = releaseDate,
                    Rating              = data.Rating,
                    ShortDescription    = data.ShortDescription,
                    DetailedDescription = data.DetailedDescription,
                    LegalInfo           = data.LegalInfo
                };

                var game = new Game {
                    Name      = data.Name,
                    Developer = data.Developer,
                    GameUrl   = data.GameUrl,
                    GameInfo  = gameInfo,
                    GameSystemRequirements = gameSystemRequirements,
                    GameMedia  = gameMedia,
                    GameFilter = gameFilter
                };

                var success = gamesTable.AddGame(game);

                if (!string.IsNullOrEmpty(success))
                {
                    return(Content(success));
                }
            }
            catch (Exception e)
            {
                return(Content($"{e.Message}\n{e.StackTrace}"));
            }

            return(Content(""));
        }