Beispiel #1
0
 public void AddGameToCollection(GameCollectionUI gc)
 {
     using (var db = new GameCollectionDBContainer())
     {
         db.GameCollectionUIs.Add(gc);
         db.SaveChanges();
     }
 }
        public GameDetails MaakGameDetails(Game game)
        {
            User             user    = (User)Session["user"];
            GameCollectionUI gc      = service.GetGameCollection(user);
            GameDetails      details = new GameDetails();

            details.Title = game.Title;
            ConsoleSoort console = service.GetConsole(game.ConsoleSoort_Id);

            details.ConsoleNaam    = console.ConsoleName;
            details.Conditie       = gc.Condition;
            details.Version        = gc.Version;
            details.BoxArtLocation = game.BoxArtLocation;
            if (Session["toegevoegd"] != null)
            {
                Session.Remove("toegevoegd");
            }
            return(details);
        }
        public ActionResult addNewGame(NewGame form)
        {
            var user = (User)Session["user"];

            if (user != null)
            {
                Collection collection = service.GetCollectionFromUser(user);
                TempData.Remove("duplicaat");
                if (ViewData.ModelState.IsValid)
                {
                    Game nieuw = new Game();
                    if (!service.BestaatGame(form))
                    {
                        nieuw.Title           = form.GameTitle;
                        nieuw.ConsoleSoort_Id = form.Console;
                        service.VoegGameToe(nieuw);
                        nieuw = service.getNewlyAddedGame(nieuw);

                        GameCollectionUI gc = new GameCollectionUI();

                        gc.Games_Id      = nieuw.Id;
                        gc.Collection_id = collection.Id;
                        gc.Condition     = form.Conditie;
                        gc.Version       = form.Version.ToString();

                        service.AddGameToCollection(gc);
                    }
                    else
                    {
                        nieuw.Title           = form.GameTitle;
                        nieuw.ConsoleSoort_Id = form.Console;
                        nieuw = service.getNewlyAddedGame(nieuw);
                        //aanpassingen gebaseerd op de versie van een spel
                        var gameGevondenInCollection = service.BestaatGameInCollection(nieuw, user.Id);
                        if (gameGevondenInCollection == null)
                        {
                            GameCollectionUI gc_new = new GameCollectionUI();

                            gc_new.Games_Id      = nieuw.Id;
                            gc_new.Collection_id = collection.Id;
                            gc_new.Condition     = form.Conditie;
                            gc_new.Version       = form.Version.ToString();
                            service.AddGameToCollection(gc_new);
                        }
                        else
                        {
                            if (gameGevondenInCollection.Version != form.Version.ToString())
                            {
                                GameCollectionUI gc_new = new GameCollectionUI();

                                gc_new.Games_Id      = nieuw.Id;
                                gc_new.Collection_id = collection.Id;
                                gc_new.Condition     = form.Conditie;
                                gc_new.Version       = form.Version.ToString();
                                service.AddGameToCollection(gc_new);
                            }
                            else
                            {
                                TempData["duplicaat"] = "Je hebt deze game al in je collectie";
                                return(RedirectToAction("addNewGame", "Home"));
                            }
                        }
                        //////HIER GEEINDIGT gedachtegang over error als je al iets wil toevoegen dat al bestaat in je collectie
                    }
                    Session["toegevoegd"] = nieuw;

                    return(RedirectToAction("Details", "Home"));
                }
                else
                {
                    form.AlleConsoles = service.GetAllConsoles();
                    return(View(form));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
            //Collection collection = service.GetCollectionFromUser(user);
            //TempData.Remove("duplicaat");
            //if (ViewData.ModelState.IsValid)
            //{

            //    Game nieuw = new Game();
            //    if (!service.BestaatGame(form))
            //    {

            //        nieuw.Title = form.GameTitle;
            //        //ConsoleSoort console = (service.getConsoleId(Request.Form["myDropdown"]));
            //        nieuw.ConsoleSoort_Id = form.Console;

            //        //nieuw.Condition = form.Conditie;


            //        service.VoegGameToe(nieuw);
            //        nieuw = service.getNewlyAddedGame(nieuw);
            //       // Collection collection = service.GetCollectionFromUser(user);

            //        GameCollectionUI gc = new GameCollectionUI();

            //        gc.Games_Id = nieuw.Id;
            //        gc.Collection_id = collection.Id;
            //        gc.Condition = form.Conditie;


            //       service.AddGameToCollection(gc);
            //    }
            //    else
            //    {
            //        nieuw.Title = form.GameTitle;
            //        nieuw.ConsoleSoort_Id = form.Console;
            //        nieuw = service.getNewlyAddedGame(nieuw);
            //        if (!service.BestaatGameInCollection(nieuw,user.Id))
            //        {
            //            GameCollectionUI gc_new = new GameCollectionUI();

            //            gc_new.Games_Id = nieuw.Id;
            //            gc_new.Collection_id = collection.Id;
            //            gc_new.Condition = form.Conditie;
            //            service.AddGameToCollection(gc_new);
            //        }
            //        else
            //        {
            //             TempData["duplicaat"]= "Je hebt deze game al in je collectie";
            //             return RedirectToAction("addNewGame","Home");
            //        }
            //        //////HIER GEEINDIGT gedachtegang over error als je al iets wil toevoegen dat al bestaat in je collectie

            //    }
            //    Session["toegevoegd"] = nieuw;
            //    return RedirectToAction("Details", "Home");

            //}
            //else
            //{

            //    form.AlleConsoles = service.GetAllConsoles();
            //    return View(form);
            //}
        }