public ActionResult Add()
        {
            var genres = this.Data.Genres.All()
                .Select(g => new
                {
                    Id = g.Id,
                    Name = g.Name
                });

            var list = new List<SelectListItem>();
            foreach (var genre in genres)
            {
                list.Add(new SelectListItem
                {
                    Value = genre.Id.ToString(), Text = genre.Name
                });
            }

            var model = new AddGameViewModel
            {
                Genre = new SelectList(list, "Value", "Text")
            };

            return View(model);
        }
示例#2
0
        public ActionResult AddGamePost(AddGameViewModel model)
        {
            //model.Date = DateTime.Now + new TimeSpan(1, 10, 0);
            if (model.GuestTeam == null || model.HostTeam == null || model.HostTeam == model.GuestTeam)
            {
                var allTeams = this.teams.GetAll().ToList();

                model.Teams = new List <SelectListItem>();
                foreach (var team in allTeams)
                {
                    model.Teams.Add(new SelectListItem
                    {
                        Text  = team.Name,
                        Value = team.Name
                    });
                }

                return(this.View(model));
            }

            var dataModel = AutoMapper.Mapper.Map <AddGameViewModel, LesGamblers.Models.Game>(model);

            this.games.Add(dataModel);

            this.TempData["Notification"] = model.HostTeam + " - " + model.GuestTeam + " was added successfully!";
            return(RedirectToAction("AddGame", "Games"));
        }
示例#3
0
        public bool Edit(int id, AddGameViewModel viewModel)
        {
            try
            {
                using (var db = new GamestoreAppDbContext())
                {
                    var game = db.Games.Find(id);

                    if (game == null)
                    {
                        return(false);
                    }

                    game.Price         = decimal.Parse(viewModel.Price);
                    game.Description   = viewModel.Description;
                    game.ImageTumbnail = viewModel.ImageTumbnail;
                    game.ReleaseDate   = DateTime.Parse(viewModel.ReleaseDate);
                    game.Size          = double.Parse(viewModel.Size);
                    game.Title         = viewModel.Title;
                    game.TrailerId     = viewModel.TrailerId;

                    db.Update(game);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
        public void ShowWindow(BaseViewModel viewModel, bool showAsDialog = false)
        {
            Window window = viewModel switch
            {
                // Wenn viewModel null ist -> ArgumentNullException
                null => throw new ArgumentNullException(nameof(viewModel)),

                      MainViewModel _ => new MainWindow(),
                      AddGameViewModel _ => new AddGameWindow(),

                      // default -> InvalidOperationException
                      _ => throw new InvalidOperationException($"Unbekanntes ViewModel '{viewModel}'"),
            };

            _windows[viewModel] = window;

            window.DataContext = viewModel;

            if (showAsDialog)
            {
                window.ShowDialog();
            }
            else
            {
                window.Show();
            }
        }
示例#5
0
        public IHttpResponse AddGame(IHttpSession session, AddGameViewModel model)
        {
            if (!AdminAccess(session))
            {
                return(new BadRequestResponse());
            }

            string error = this.ValidateModel(model);

            if (error != null)
            {
                return(this.ErrorMessageResponse(error, FilePaths.GameAdd));
            }

            this.GameService.Create(
                model.Title,
                model.Price,
                model.Size,
                model.Trailer,
                model.ThumbnailUrl,
                model.Description,
                model.ReleaseDate);

            return(new RedirectResponse(UrlPaths.GameAdminList));
        }
示例#6
0
        public ActionResult Add(AddGameViewModel model)
        {
            //EF添加
            if (ModelState.IsValid)
            {
                var efModle = new Game()
                {
                    id     = model.id,
                    gName  = model.gName,
                    gTid   = model.gTid,
                    gSId   = model.gSid,
                    gPrice = model.gPrice,
                    gState = model.gState
                };

                using (var db = new StudentEntiy())
                {
                    db.Entry <Game>(efModle).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() > 0)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "添加失败");
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "信息有误,请核对信息完整性!");
            }
            return(View());
        }
示例#7
0
        public IActionResult ProcessAddGameForm(AddGameViewModel addGameViewModel, string[] selectedGenres)
        {
            if (ModelState.IsValid)
            {
                Developer developer = context.Developers.Find(addGameViewModel.DeveloperId);
                Game      game      = new Game
                {
                    Name        = addGameViewModel.Name,
                    Description = addGameViewModel.Description,
                    Cover       = addGameViewModel.Cover,
                    ReleaseDate = addGameViewModel.ReleaseDate,
                    Developer   = developer
                };

                foreach (string genre in selectedGenres)
                {
                    GameGenre gameGenre = new GameGenre
                    {
                        Game    = game,
                        GameId  = game.Id,
                        GenreId = int.Parse(genre)
                    };
                    context.GameGenres.Add(gameGenre);
                }
                context.Games.Add(game);
                context.SaveChanges();

                return(Redirect("Index"));
            }
            return(View("AddGame", addGameViewModel));
        }
示例#8
0
        public IActionResult AddGame()
        {
            List <Developer> developers       = context.Developers.ToList();
            List <Genre>     genres           = context.Genres.ToList();
            AddGameViewModel addGameViewModel = new AddGameViewModel(developers, genres);

            return(View(addGameViewModel));
        }
示例#9
0
        public IActionResult AddGame()
        {
            AddGameViewModel model = new AddGameViewModel();

            if (HttpContext.Session.GetString("_IsAdmin") != "1")
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }
示例#10
0
        public IActionResult AddGame()
        {
            AddGameViewModel addGameViewModel = new AddGameViewModel
            {
                Spots   = SpotService.GetAllSpots(),
                Rewards = RewardService.GetAllRewards(),
            };

            return(View(addGameViewModel));
        }
示例#11
0
 private void PopulateFormWithDbData(AddGameViewModel model)
 {
     this.ViewData["nameValue"]        = model.Title;
     this.ViewData["descriptionValue"] = model.Description;
     this.ViewData["urlValue"]         = model.ImageThumbnail;
     this.ViewData["priceValue"]       = model.Price.ToString();
     this.ViewData["sizeValue"]        = model.Size.ToString();
     this.ViewData["youtubeValue"]     = model.TrailerId;
     this.ViewData["dateValue"]        = String.Format("{0:yyyy-MM-dd}", model.ReleaseDate);
 }
示例#12
0
        //TODO: implement genre


        public Game(AddGameViewModel viewModel)
        {
            Title         = viewModel.Title;
            PlatformId    = viewModel.PlatformId;
            Value         = viewModel.Value;
            Year          = viewModel.Year;
            Description   = viewModel.Description;
            ConditionId   = viewModel.ConditionId;
            UserId        = viewModel.UserId;
            DesignationId = viewModel.DesignationId;
        }
示例#13
0
        public IActionResult CompleteAdd(AddGameViewModel model)
        {
            var userId = _userManager.GetUserId(HttpContext.User);

            if (model != null && model.ChosenCategoryGuid != Guid.Empty)
            {
                _gameRepository.AddGame(model.GameName, model.ChosenCategoryGuid, userId);
            }

            return(RedirectToAction("Game", "Home"));
        }
示例#14
0
        public IActionResult AddGame(AddGameViewModel addGameViewModel, IFormCollection form)
        {
            GameModel gameModel = addGameViewModel.GameModel;

            gameModel.Id = Guid.NewGuid();
            GameService.AddGame(gameModel);
            LinkGameToSpots(form.Keys, gameModel);
            LinkGameToRewards(form.Keys, gameModel);

            return(RedirectToAction(nameof(Index)));
        }
示例#15
0
 public Game(AddGameViewModel addGameViewModel)
 {
     DbId             = addGameViewModel.DbId;
     Name             = addGameViewModel.Name;
     Slug             = addGameViewModel.Slug;
     Summary          = addGameViewModel.Summary;
     FirstReleaseDate = addGameViewModel.FirstReleaseDate;
     Storyline        = addGameViewModel.Storyline;
     //Esrb = addGameViewModel.Esrb.RatingId;
     //Pegi = addGameViewModel.Pegi.RatingId;
 }
示例#16
0
        public IActionResult Add()
        {
            ViewData["Title"] = "Start nyt spil";

            var userId = _userManager.GetUserId(HttpContext.User);
            var model  = new AddGameViewModel()
            {
                CategoryList = _categoryRepository.GetCategoriesByUserId(userId)
            };

            return(PartialView(model));
        }
示例#17
0
        public IHttpResponse Add(AddGameViewModel model)
        {
            var error = ValidateModel(model);

            if (error != null)
            {
                this.AddError(error);
            }

            var success = this.gameService.AddGame(model.Title, model.ImageThumbnail, model.Size, model.Price,
                                                   model.YouTubeVideoId, model.Description, model.ReleaseDate);

            return(this.FileViewResponse(ListGamesPath));
        }
示例#18
0
        public IActionResult AddGames(AddGameViewModel model)
        {
            Game game = new Game
            {
                Name        = model.GameName,
                Price       = model.Price,
                GameTag     = model.GameTag,
                Description = model.Description,
                ReleaseDate = model.ReleaseDate
            };

            Logic.AddGame(game);
            return(RedirectToAction("Index", "Home"));
        }
示例#19
0
        public IHttpResponse AddGame(AddGameViewModel model)
        {
            if (!Authentication.IsAdmin)
            {
                return(this.RedirectResponse(HomePath));
            }

            if (!this.ValidateModel(model))
            {
                return(this.AddGame());
            }

            this.games.Create(model.Title, model.Description, model.Image, model.TrailerId, model.Size, model.Price, model.ReleaseDate.Value);

            return(this.RedirectResponse("/"));
        }
示例#20
0
        public ActionResult AddGame(AddGameViewModel model)
        {
            var allTeams = this.teams.GetAll().ToList();

            model.Teams = new List <SelectListItem>();
            foreach (var team in allTeams)
            {
                model.Teams.Add(new SelectListItem
                {
                    Text  = team.Name,
                    Value = team.Name
                });
            }

            return(this.View(model));
        }
示例#21
0
        public IHttpResponse AddGame(AddGameViewModel model)
        {
            if (!this.Authentication.IsAdmin)
            {
                return(new RedirectResponse(HomePath));
            }

            if (string.IsNullOrWhiteSpace(model.RealeaseDate))
            {
                this.AddError(RequiredDate);
                return(this.AddGame());
            }

            this.games.Create(model.Title, model.Description, model.Image, model.Price, model.Size, model.VideoId, DateTime.Parse(model.RealeaseDate));

            return(new RedirectResponse(ListGamesPath));
        }
示例#22
0
        public IHttpResponse Add(AddGameViewModel model)
        {
            if (!this.ValidateModel(model))
            {
                return(this.FileViewResponse(AddGamePath));
            }

            this.gameService.Create(
                model.Title,
                model.TrailerId,
                model.ImageThumbnail,
                model.Size,
                model.Price,
                model.Description,
                model.ReleaseDate.Value);

            return(new RedirectResponse("/admin/games"));
        }
示例#23
0
        public IActionResult Add(AddGameViewModel addGameViewModel)
        {
            if (ModelState.IsValid)
            {
                GameType newGameType = context.Types.Single(g => g.ID == addGameViewModel.TypeID);
                //add the new game to my existing games
                Game newGame = new Game
                {
                    Title       = addGameViewModel.Title,
                    Description = addGameViewModel.Description,
                    Type        = newGameType
                };
                context.Games.Add(newGame);
                context.SaveChanges();

                return(Redirect("/Game"));
            }

            return(View(addGameViewModel));
        }
示例#24
0
        public IActionResult Add(AddGameViewModel addGameViewModel)
        {
            if (ModelState.IsValid)
            {
                Game newGame = new Game(addGameViewModel);
                newGame.UserId = Models.Extensions.GetUserID(User);
                context.Games.Add(newGame);
                context.SaveChanges();
                string genres = addGameViewModel.GenreNames;
                int    gameId = newGame.GameId;
                Models.Extensions.AddGenres(context, gameId, genres);

                return(Redirect("/List?m=Game Successfully Added"));
            }

            string           genreIds            = addGameViewModel.GenreIds;
            AddGameViewModel newAddGameViewModel = new AddGameViewModel(context, genreIds);

            return(View(newAddGameViewModel));
        }
示例#25
0
        public async Task <IActionResult> Add(AddGameViewModel addGameViewModel)
        {
            RunAsync().GetAwaiter().GetResult();

            if (ModelState.IsValid)
            {
                var response = await GetGameAsync("/games/?search=" + addGameViewModel.Name + "&fields=name");

                if (response == null)
                {
                    TempData["NoResults"] = "NoResults";
                }
                else
                {
                    TempData["response"] = response;
                }
            }

            return(View(addGameViewModel));
        }
示例#26
0
        public IHttpResponse EditGame(AddGameViewModel model)
        {
            if (!Authentication.IsAdmin)
            {
                return(this.RedirectResponse(HomePath));
            }

            if (!this.ValidateModel(model))
            {
                this.SetDefaultData();

                return(this.FileViewResponse(EditGameView));
            }

            var gameId = int.Parse(this.Request.UrlParameters["id"]);

            this.games.Update(gameId, model.Title, model.Description, model.Image, model.TrailerId, model.Size, model.Price, model.ReleaseDate.Value);

            return(this.RedirectResponse(AllGamesPath));
        }
示例#27
0
        private async void PopulateRelationships(AddGameViewModel addGameViewModel, int gameId)
        {
            if (addGameViewModel.Cover != null)
            {
                GameImage newCover = addGameViewModel.Cover;
                newCover.Type   = "cover";
                newCover.GameID = gameId;
                context.GameImages.Add(newCover);
            }

            if (addGameViewModel.Artworks != null)
            {
                foreach (GameImage img in addGameViewModel.Artworks)
                {
                    GameImage newArtwork = img;
                    newArtwork.Type   = "artwork";
                    newArtwork.GameID = gameId;
                    context.GameImages.Add(newArtwork);
                }
            }

            if (addGameViewModel.Screenshots != null)
            {
                foreach (GameImage img in addGameViewModel.Screenshots)
                {
                    GameImage newScreenshot = img;
                    newScreenshot.Type   = "screenshot";
                    newScreenshot.GameID = gameId;
                    context.GameImages.Add(newScreenshot);
                }
            }

            //TODO: Create Platforms, PlatformGames, Publishers, PublisherGames, Genres, GenreGames, Developers, DeveloperGames, and add them to the dbcontext

            if (addGameViewModel.Platforms != null)
            {
                //TODO: Check if the platforms exist in the platforms table, if not, MakeRequest for the platform, populate it, and add it to the context
            }

            context.SaveChanges();
        }
        //POST
        public IHttpResponse AddGame(AddGameViewModel viewModel)
        {
            if (!this.Authentication.IsAdmin)
            {
                return(new RedirectResponse(@"/"));
            }

            if (!Validator.Title(viewModel.Title) && !Validator.Price(viewModel.Price) && !Validator.Size(viewModel.Size) &&
                !Validator.Trailer(viewModel.TrailerId) && !Validator.Description(viewModel.Description))
            {
                this.ViewData["showError"]    = "block";
                this.ViewData["errorMessage"] = "Please fill out all fields correctly.";

                return(this.FileViewResponse(AddGamePath));
            }

            var date = DateTime.ParseExact(viewModel.ReleaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);

            var success = this.gameService.Create(
                viewModel.Title,
                viewModel.Description,
                viewModel.ImageTumbnail,
                decimal.Parse(viewModel.Price),
                double.Parse(viewModel.Size),
                viewModel.TrailerId,
                date);

            if (!success)
            {
                this.ViewData["showError"]    = "block";
                this.ViewData["errorMessage"] = "Please fill out all fields correctly.";

                return(this.FileViewResponse(AddGamePath));
            }

            return(new RedirectResponse(@"/"));
        }
示例#29
0
        public IHttpResponse AddGame(AddGameViewModel model)
        {
            var isAdmin = this.Authentication.IsAdmin;

            if (!isAdmin)
            {
                return(this.RedirectResponse("/"));
            }

            var isValid = this.ValidateModel(model);

            if (!isValid)
            {
                return(this.FileViewResponse(AddGameView));
            }

            var title       = model.Title;
            var description = model.Description;
            var image       = model.Image;
            var price       = model.Price;
            var size        = model.Size;
            var videoId     = model.VideoId;
            var releaseDate = model.ReleaseDate;

            var success = this.games.Create(title, description, image, price, size, videoId, releaseDate.Value);

            if (success)
            {
                return(this.RedirectResponse(@"/admin/games/list"));
            }
            else
            {
                this.ShowError("Game already exists.");

                return(this.FileViewResponse(AddGameView));
            }
        }
示例#30
0
        public IActionResult Add()
        {
            AddGameViewModel addGameViewModel = new AddGameViewModel(context);

            return(View(addGameViewModel));
        }
示例#31
0
 public AddGameView(AddGameViewModel vm)
 {
     DataContext = vm;
     InitializeComponent();
 }