// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            _context.OrderedItems.Add(OrderedItem);
            var foodItem = await _context.FoodItems.FirstOrDefaultAsync(x => x.FoodItemId == OrderedItem.FoodItemId);

            var person = await _context.Persons.FindAsync(OrderedItem.PersonId);

            person.SumOfItems += foodItem.Price * OrderedItem.Quantity;
            _context.Persons.Update(person);

            var order = await _context.Orders.FindAsync(person.OrderId);

            order.OrderTotal += foodItem.Price * OrderedItem.Quantity;
            _context.Orders.Update(order);

            await _context.SaveChangesAsync();

            return(RedirectToPage("../Persons/Details", new{ id = OrderedItem.PersonId }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(string?personName)
        {
            if (personName == null)
            {
                return(Page());
            }

            PersonName = personName;


            var found = _context.Persons.Any(x => x.Name == PersonName);

            if (!found)
            {
                var person = new Person();
                person.Name = PersonName;
                _context.Persons.Add(person);
                await _context.SaveChangesAsync();
            }

            var foundPerson = _context.Persons.FirstOrDefault(x => x.Name == PersonName);

            if (foundPerson != null)
            {
                return(RedirectToPage("/Quizzes/Index", new { personId = foundPerson.PersonId }));
            }

            return(Page());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid || id == null)
            {
                return(Page());
            }

            Review.TimePosted = DateTime.Now;
            Review.BookId     = id.Value;

            _context.Reviews.Add(Review);
            await _context.SaveChangesAsync();

            return(RedirectToPage("Details", new { id = id }));
        }
Exemplo n.º 4
0
        public void ShootBoard(string aim)
        {
            Game game = _context.Games
                        .Include(u => u.Player1).ThenInclude(b => b.SelfBoard).ThenInclude(r => r.RowNodes).ThenInclude(n => n.Nodes)
                        .Include(v => v.Player1).ThenInclude(p => p.OppenentBoard).ThenInclude(t => t.RowNodes).ThenInclude(m => m.Nodes)
                        .Include(u => u.Player2).ThenInclude(b => b.SelfBoard).ThenInclude(r => r.RowNodes).ThenInclude(n => n.Nodes)
                        .Include(v => v.Player2).ThenInclude(p => p.OppenentBoard).ThenInclude(t => t.RowNodes).ThenInclude(m => m.Nodes)
                        .FirstOrDefault(m => m.GameId == _id);

            string letter = aim.Substring(0, 1).ToUpper();
            int    numer  = -1;

            if (aim.Length == 2)
            {
                numer = int.Parse(aim.Substring(1, 1)) - 1;
            }
            else
            {
                numer = int.Parse(aim.Substring(1, 2)) - 1;
            }

            int c = alpha.IndexOf(letter);


            if (game.Player2.SelfBoard.RowNodes[numer].Nodes[c].NodeValue == "\x25A8")
            {
                game.Player2.SelfBoard.RowNodes[numer].Nodes[c].NodeValue     = "\xD83D\xDD25";
                game.Player1.OppenentBoard.RowNodes[numer].Nodes[c].NodeValue = "\xD83D\xDD25";
                game.Player1.Score += 1;

                shiploc.Clear();
                if (allfinder(game.Player2, numer, c))
                {
                    shiploc.Clear();
                    hinting(game.Player1, game.Player2, numer, c);
                }
            }
            else if (game.Player2.SelfBoard.RowNodes[numer].Nodes[c].NodeValue == "\x25A2")
            {
                game.Player1.OppenentBoard.RowNodes[numer].Nodes[c].NodeValue = "\x26DE";
                OpponentShoot(game);
            }
            else
            {
            }
            _context.SaveChangesAsync();
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Book = await _context.Books.FindAsync(id);

            if (Book != null)
            {
                _context.Books.Remove(Book);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            InitBoard.InitializeBoard(Game);
            _context.Games.Add(Game);
            await _context.SaveChangesAsync();

            if (!StandardShips)
            {
                return(RedirectToPage("CustomShips", new { id = _context.Games.Last().GameId }));
            }

            return(RedirectToPage("ShipPlacement", new { id = _context.Games.Last().GameId }));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> OnGetAsync(Guid?gameId, Guid?deleteGameId)
        {
            if (gameId != null)
            {
                return(Redirect("PlayGame?gameId=" + gameId.Value));
            }

            if (deleteGameId != null)
            {
                var gameToDel = _context.Games.FirstOrDefault(g => g.GameId == deleteGameId.Value);
                if (gameToDel != null)
                {
                    _context.Games.Attach(gameToDel);
                    _context.Games.Remove(gameToDel);
                    await _context.SaveChangesAsync();
                }
            }

            // SavedGames = await _context.Games.Where(g => g.SaveName != null).ToListAsync();
            SavedGames = await _context.Games.ToListAsync();

            return(Page());
        }
Exemplo n.º 8
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                var maxWinningCondition = 0;
                if (GameSettings.BoardHeight >= GameSettings.BoardWidth)
                {
                    maxWinningCondition = GameSettings.BoardHeight;
                }
                else
                {
                    maxWinningCondition = GameSettings.BoardWidth;
                }

                if (GameSettings.WinningCondition > maxWinningCondition)
                {
                    ModelState.AddModelError(nameof(GameSettings.WinningCondition), "Too many chips in a row to win");
                    return(Page());
                }
                Game.InitializeNewGame(GameSettings.BoardHeight, GameSettings.BoardWidth);
                var savedGame = new SavedGame()
                {
                    GameName          = Game.GameName,
                    GameBoard         = Game.SerializeBoard(),
                    PlayerOneMoves    = Game.PlayerOneMoves,
                    IsHumanVsComputer = GameSettings.IsHumanVsComputer,
                    PlayerOneName     = Game.PlayerOneName,
                    PlayerTwoName     = Game.PlayerTwoName,
                    WinningCondition  = GameSettings.WinningCondition
                };
                _context.SavedGames.Add(savedGame);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/PlayGame", new { gameId = savedGame.SavedGameId }));
            }
            return(Page());
        }
Exemplo n.º 9
0
        public async Task <ActionResult> OnGet(Guid?gameId, int?col)
        {
            if (gameId == null)
            {
                return(Redirect("Index"));
            }

            GameId = gameId.Value;

            Game = _context.Games.Find(GameId);
            Game.DeserializeBoard(Game.BoardString);
            if (Game == null)
            {
                return(RedirectToPage("Index", new { error = "game-not-found" }));
            }

            if (col != null)
            {
                int selectedCol = (int)(col + 1);
                if (Game.IsColumnFull(selectedCol))
                {
                }
                else
                {
                    Game.Move((int)col + 1);
                    _context.Games.Update(Game);
                    await _context.SaveChangesAsync();
                }
            }

            if (Game.IsGameDone())
            {
                return(RedirectToPage("Index", new { error = "you-lost-ha-ha", quitGameId = GameId }));
            }

            return(Page());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Console.WriteLine(Grade.GradeId);
            Console.WriteLine(Grade.GradeNumber);

            _context.Attach(Grade).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GradeExists(Grade.GradeId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var grade = _context.Grades
                        .Include(a => a.PersonSubjectSemester)
                        .ThenInclude(b => b.SubjectSemester)
                        .FirstOrDefaultAsync(a => a.GradeId == id).Result;
            var subjectGradeId = grade.PersonSubjectSemester.SubjectSemester.SubjectSemesterId;

            return(RedirectToPage("./SubjectGrades", new { id = subjectGradeId }));
        }
Exemplo n.º 11
0
        public async Task <ActionResult> OnGet(int?gameId, int?col, int?row, bool?over, bool?win)
        {
            if (win != null)
            {
                WinGame = win.Value;
            }

            if (over != null)
            {
                GameOver = over.Value;
            }

            GameSettings = await _context.GameSettingses.ToListAsync();

            if (gameId == null)
            {
                return(RedirectToPage("./StartGame"));
            }

            var match = false;

            foreach (GameSettings settings in _context.GameSettingses)
            {
                if (settings.GameId == gameId)
                {
                    match = true;
                }
            }

            if (!match)
            {
                return(RedirectToPage("./MainMenu"));
            }

            GameId      = gameId.Value;
            BoardHeight = GameSettings.First(a => a.GameId == gameId).BoardHeight;
            BoardWidth  = GameSettings.First(a => a.GameId == gameId).BoardWidth;
            var game = new GameEngine.Game(GameSettings.First(a => a.GameId == gameId).BoardHeight,
                                           GameSettings.First(a => a.GameId == gameId).BoardWidth);
            var indexOfList = 0;
            var gameCells   = GameSettings.First(a => a.GameId == gameId)
                              .GameState.ToString();
            var gameCallsList = gameCells.Split(",");

            for (var i = 0; i < GameSettings.First(a => a.GameId == gameId).BoardHeight; i++)
            {
                for (var j = 0; j < GameSettings.First(a => a.GameId == gameId).BoardWidth; j++)
                {
                    game.Board[i, j] = (CellState)int.Parse(gameCallsList[indexOfList]);
                    indexOfList++;
                }
            }

            Board = game.Board;
            if (col != null && row != null)
            {
                game.Move(row.Value, col.Value);
                if (game.GetValue(row.Value, col.Value) == CellState.B)
                {
                    return(RedirectToPage("./PlayGame", new { over = true, gameId = GameId }));
                }

                var emptyCellCount = 0;
                foreach (CellState cellState in Board)
                {
                    if (NotOpenValues.Contains(cellState))
                    {
                        emptyCellCount++;
                    }
                }


                string gameState = "";
                foreach (CellState variable in Board)
                {
                    gameState += Convert.ToInt32(variable) + ",";
                }

                gameState = gameState.Remove(gameState.Length - 1);

                _context.GameSettingses.First(a => a.GameId == gameId).GameState = gameState;
                await _context.SaveChangesAsync();

                if (emptyCellCount == GameSettings.First(a => a.GameId == gameId).BombAmount)
                {
                    return(RedirectToPage("./PlayGame", new { win = true, gameId = GameId }));
                }
            }

            return(Page());
        }
Exemplo n.º 12
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string?languagePick,
                                                      string?publisherPick, string?deleteLanguage, string?deletePublisher,
                                                      string?deleteAuthor, string?authorPick, List <int>?hiddenAuthorsList,
                                                      string?final, string?picturePick, string?deletePicture)
        {
            if (!string.IsNullOrEmpty(languagePick) && "pick".Equals(languagePick))
            {
                LanguageIsSet   = true;
                Book.LanguageId = PickLanguageModel.LanguageId;
                Book.Language   = _context.Languages.Find(Book.LanguageId);
            }
            else if (!string.IsNullOrEmpty(languagePick) && "add".Equals(languagePick) &&
                     !string.IsNullOrEmpty(PickLanguageModel.NewLanguageName))
            {
                LanguageIsSet = true;
                var language = new Language(PickLanguageModel.NewLanguageName, "EE");
                if (!_context.Languages.Any(l => l.LanguageName == language.LanguageName))
                {
                    _context.Languages.Add(language);
                    _context.SaveChanges();
                    Book.LanguageId = language.LanguageId;
                }
                else
                {
                    Book.LanguageId = _context.Languages
                                      .First(l => l.LanguageName == language.LanguageName).LanguageId;
                }

                Book.Language = _context.Languages.Find(Book.LanguageId);
            }

            if (!string.IsNullOrEmpty(deleteLanguage))
            {
                Book.LanguageId = 0;
                LanguageIsSet   = false;
            }

            if (!string.IsNullOrEmpty(publisherPick) && "pick".Equals(publisherPick) &&
                PickPublisherModel.PublisherId != null)
            {
                PublisherIsSet   = true;
                Book.PublisherId = (int)PickPublisherModel.PublisherId;
                Book.Publisher   = _context.Publishers.Find(Book.PublisherId);
            }
            else if (!string.IsNullOrEmpty(publisherPick) && "add".Equals(publisherPick) &&
                     !string.IsNullOrEmpty(PickPublisherModel.NewPublisherName))
            {
                PublisherIsSet = true;
                var publisher = new Publisher(PickPublisherModel.NewPublisherName);
                if (!_context.Publishers.Any(a => a.PublisherName == publisher.PublisherName))
                {
                    _context.Publishers.Add(publisher);
                    _context.SaveChanges();
                    Book.PublisherId = publisher.PublisherId;
                }
                else
                {
                    Book.PublisherId = _context.Publishers
                                       .First(p => p.PublisherName == publisher.PublisherName).PublisherId;
                }

                Book.Publisher = _context.Publishers.Find(Book.PublisherId);
            }

            if (!string.IsNullOrEmpty(deletePublisher))
            {
                Book.PublisherId = 0;
                PublisherIsSet   = false;
            }

            if (LanguageIsSet)
            {
                Book.Language = _context.Languages.Find(Book.LanguageId);
            }
            else
            {
                PickLanguageModel.LanguagesSelectlist = new SelectList(_context.Languages,
                                                                       nameof(Language.LanguageId), nameof(Language.LanguageName));
            }

            if (PublisherIsSet)
            {
                Book.Publisher = _context.Publishers.Find(Book.PublisherId);
            }
            else
            {
                PickPublisherModel.PublishersSelectlist = new SelectList(_context.Publishers,
                                                                         nameof(Publisher.PublisherId), nameof(Publisher.PublisherName));
            }

            AuthorIds = hiddenAuthorsList;
            if (!string.IsNullOrEmpty(authorPick) && "pick".Equals(authorPick))
            {
                Console.WriteLine("Got to Pick!" + SelectedAuthorIds.Count +
                                  PickAuthorPartialModel.SelectedAuthorIds.Count);
                foreach (var selectedAuthorId in PickAuthorPartialModel.SelectedAuthorIds)
                {
                    if (!AuthorIds.Contains(selectedAuthorId))
                    {
                        AuthorIds.Add(selectedAuthorId);
                    }
                }
            }

            var author = PickAuthorPartialModel.Author;

            if (!string.IsNullOrEmpty(authorPick) && "add".Equals(authorPick) &&
                !string.IsNullOrEmpty(author.FirstName) && !string.IsNullOrEmpty(author.LastName))
            {
                Console.WriteLine(author);
                if (!_context.Authors.Any(a => a.FirstName == author.FirstName &&
                                          a.LastName == author.LastName &&
                                          a.BirthYear == author.BirthYear &&
                                          a.DeathYear == author.DeathYear &&
                                          a.Description == author.Description))
                {
                    Console.WriteLine("Got to add author!");
                    _context.Authors.Add(author);
                    _context.SaveChanges();
                    AuthorIds.Add(author.AuthorId);
                }
                else
                {
                    AuthorIds.Add(_context.Authors.FirstOrDefault(a => a.FirstName == author.FirstName &&
                                                                  a.LastName == author.LastName &&
                                                                  a.BirthYear == author.BirthYear &&
                                                                  a.DeathYear == author.DeathYear &&
                                                                  a.Description == author.Description).AuthorId);
                }
            }


            if (!string.IsNullOrEmpty(deleteAuthor) && int.TryParse(deleteAuthor, out var authorId))
            {
                Console.WriteLine("AuhorInt: " + authorId);
                AuthorIds.Remove(authorId);
            }

            BookAuthorsSelectList = new SelectList(_context.Authors, nameof(Author.AuthorId), nameof(Author.FirstName));
            PickAuthorPartialModel.BookAuthorsSelectList =
                new SelectList(_context.Authors, nameof(Author.AuthorId), nameof(Author.FirstName));

            Authors = _context.Authors.Where(a => AuthorIds.Contains(a.AuthorId))
                      .Select(a => new AuthorDto()
            {
                Author        = a,
                BooksAuthored = a.AuthoredBooks.Count
            }).ToList();
            Console.WriteLine("Before picturepick!");
            if (!string.IsNullOrEmpty(picturePick) && "add".Equals(picturePick) &&
                FormFile != null)
            {
                Console.WriteLine("Inside picturePick! " + FormFile.FileName);
                var file = Path.Combine(_env.WebRootPath, "resources", FormFile.FileName);
                using (var fileStream = new FileStream(file, FileMode.Create))
                {
                    await FormFile.CopyToAsync(fileStream);
                }

                UploadImagePath  = FormFile.FileName;
                Book.PicturePath = UploadImagePath;
            }

            if (!string.IsNullOrEmpty(deletePicture) && "remove".Equals(deletePicture))
            {
                UploadImagePath  = null;
                Book.PicturePath = null;
            }

            Book.PicturePath = UploadImagePath;

            if (!string.IsNullOrEmpty(final) && "Create".Equals(final) &&
                !string.IsNullOrEmpty(Book.Title) &&
                Book.Language != null &&
                Book.Publisher != null &&
                AuthorIds.Count > 0 &&
                !string.IsNullOrEmpty(Book.PicturePath))
            {
                Book.BookAuthors = AuthorIds.Select(a => new BookAuthor()
                {
                    AuthorId = a,
                    BookId   = Book.BookId
                }).ToList();
                _context.Attach(Book).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(Book.BookId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToPage("./Index"));
            }

            return(Page());


            /*
             * if (!ModelState.IsValid)
             * {
             *  return Page();
             * }
             *
             * _context.Attach(Domain.Book).State = EntityState.Modified;
             *
             * try
             * {
             *  await _context.SaveChangesAsync();
             * }
             * catch (DbUpdateConcurrencyException)
             * {
             *  if (!BookExists(Domain.Book.BookId))
             *  {
             *      return NotFound();
             *  }
             *  else
             *  {
             *      throw;
             *  }
             * }
             *
             * return RedirectToPage("./Index");*/
        }