public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TodoTaskCategory = await _context.TodoTaskCategories.FindAsync(id); if (TodoTaskCategory != null) { _context.TodoTaskCategories.Remove(TodoTaskCategory); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } PersonSubjectSemester = await _context.PersonSubjectSemesters.FindAsync(id); if (PersonSubjectSemester != null) { _context.PersonSubjectSemesters.Remove(PersonSubjectSemester); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Node = await _context.Nodes.FindAsync(id); if (Node != null) { _context.Nodes.Remove(Node); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string id) { if (id == null) { return(NotFound()); } GameState = await _context.Games.FindAsync(id); if (GameState != null) { _context.Games.Remove(GameState); await _context.SaveChangesAsync(); } return(RedirectToPage("./Load")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } PerformerSong = await _context.PerformerSongs.FindAsync(id); if (PerformerSong != null) { _context.PerformerSongs.Remove(PerformerSong); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } NewGame ng = new NewGame(_context); Game.Player1.SelfBoard = ng.DefaultBoard(false);//_context.Boards.FirstOrDefault(i => i.BoardId == b.BoardId);//b; Game.Player1.OppenentBoard = ng.DefaultBoard(true); Game.Player2.SelfBoard = ng.DefaultBoard(false); Game.Player2.OppenentBoard = ng.DefaultBoard(true); _context.Games.Add(Game); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } FestivalEvent = await _context.FestivalEvents.FindAsync(id); if (FestivalEvent != null) { _context.FestivalEvents.Remove(FestivalEvent); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } OrganisedEvent = await _context.Events.FindAsync(id); if (OrganisedEvent != null) { _context.Events.Remove(OrganisedEvent); await _context.SaveChangesAsync(); } return(RedirectToPage("/Festivals/Details", new { id = FestivalId })); }
// 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() { SettingsState = await _context.Settings.FindAsync(1); GameState.Data = JsonConvert.SerializeObject(new Game(SettingsState.BoardHeight, SettingsState.BoardWidth)); if (_context.Games.Any(g => g.Name == GameState.Name)) { _context.Games.Update(GameState); } else { _context.Games.Add(GameState); } await _context.SaveChangesAsync(); return(RedirectToPage("./Play", new { id = GameState.Name })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Comment = await _context.Comments.FindAsync(id); if (Comment != null) { _context.Comments.Remove(Comment); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index", new { book = Comment.BookId })); }
// 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 += OrderedItem.FoodItem.Price; _context.Persons.Update(person); await _context.SaveChangesAsync(); return(RedirectToPage("../Persons/Details", new{ id = OrderedItem.PersonId })); }
// 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(int?personId) { if (personId == null) { return(Page()); } if (!ModelState.IsValid) { return(Page()); } Quiz.CreationTime = DateTime.Now; _context.Quizzes.Add(Quiz); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { personId })); }
public async Task <ActionResult> OnGet(int?gameId, int?col, int?row, bool?computerMove) { if (gameId == null) { return(RedirectToPage("/NewGame")); } var savedGame = Game.RestoreSavedGameFromDb(gameId.Value); if (savedGame.IsHumanVsComputer) { savedGame.PlayerTwoName = "Computer"; } if (computerMove != null) { col = Game.ComputerMove(savedGame.WinningCondition); row = Game.FindYIndex(col.Value); } if (col != null && row != null) { Game.Move(row.Value, col.Value); CellState playerState = Game.PlayerOneMoves ? CellState.G : CellState.R; if (Game.IsWinning(row.Value, col.Value, savedGame.WinningCondition, playerState)) { var player = Game.PlayerOneMoves ? Game.PlayerTwoName : Game.PlayerOneName; Game.Message = player + " WON!"; Game.GameIsOver = true; } else if (Game.TableIsFull()) { Game.Message = "IT'S A TIE'!"; Game.GameIsOver = true; } Game.SaveGameToDb(savedGame.IsHumanVsComputer, savedGame.WinningCondition); await _context.SaveChangesAsync(); } if (savedGame.IsHumanVsComputer && !Game.PlayerOneMoves) { return(RedirectToPage("/PlayGame", new { gameId = savedGame.SavedGameId, computerMove = true })); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TrackAuthor = await _context.TrackAuthors.FindAsync(id); if (TrackAuthor != null) { _context.TrackAuthors.Remove(TrackAuthor); await _context.SaveChangesAsync(); return(RedirectToPage("/Tracks/Details", new { id = TrackAuthor.TrackId })); } return(RedirectToPage("/Tracks/Index")); }
// 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.Attach(BookAuthor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookAuthorExists(BookAuthor !.BookAuthorId)) { return(NotFound()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (_context.Users.FirstOrDefault(u => u.UserName == User.UserName) != null) { return(BadRequest("Username taken!")); } //User.Guid = Guid.NewGuid(); _context.Users.Add(User); await _context.SaveChangesAsync(); Response.Cookies.Append("guid", User.Guid.ToString()); return(Redirect("/")); }
public async Task <ActionResult> OnPost() { // validate newgame if (ModelState.IsValid) { // create an empty game in database var humanPlayerCount = 0; if (GameOptions.ToDoButton == "Human vs Human") { humanPlayerCount = 2; } if (GameOptions.ToDoButton == "AI vs Human") { humanPlayerCount = 1; } var engine = new Engine(_context); engine.InitializeNewGame(GameOptions.Height, GameOptions.Width); var gameState = new GameState() { Width = GameOptions.Width, Height = GameOptions.Height, // WinningConditionSequenceLength = GameOptions.WinningCondition, Player1Name = GameOptions.Player1Name, Player2Name = GameOptions.Player2Name, GameName = GameOptions.GameName, HumanPlayerCount = humanPlayerCount, BoardStateJson = engine.GetSerializedGameState() }; _context.GameStates.Add(gameState); await _context.SaveChangesAsync(); return(RedirectToPage("./PlayGame", new { gameId = gameState.GameStateId })); } return(Page()); }
// 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?action) { SameFound = _context.Publishers .Any(p => (p.PublisherName.ToLower()) == (Publisher.PublisherName.ToLower())); if (!ModelState.IsValid || SameFound) { return(Page()); } _context.Publishers.Add(Publisher); await _context.SaveChangesAsync(); if (action == "CreateAndGoBack") { return(RedirectToPage("/Books/Create")); } return(RedirectToPage("./Index")); }
public async void OnGetAsync(int personId) { var orderedItemsQuery2 = _context.OrderItems.Where(n => n.PersonId == personId).Include(o => o.FoodItem).AsQueryable(); OrderedItems2 = await orderedItemsQuery2.ToListAsync(); foreach (var item in OrderedItems2) { Sum += item.Sum; } var person = _context.Persons.First(n => n.PersonId == personId); Name = person.PersonName; var order = _context.Orders.First(n => n.OrderId == person.OrderId); order.OrderSum = (int)Sum; _context.Orders.Update(order); await _context.SaveChangesAsync(); }
public async Task <IActionResult> OnPostAsync(int?personId) { if (personId == null) { return(Page()); } if (ChosenIds.Count == 0) { return(Page()); } foreach (var chosenId in ChosenIds) { var answer = new Answer(); answer.AnswerTime = DateTime.Now; answer.ChoiceId = chosenId; answer.PersonId = (int)personId; _context.Answers.Add(answer); } await _context.SaveChangesAsync(); return(RedirectToPage("/Quizzes/Index", new { personId = personId })); }
public async Task <IActionResult> OnGetAsync(int?id, int?redirect) { if (id == null) { return(NotFound()); } Choice = await _context.Choices.FindAsync(id); if (Choice != null) { var question = _context.Questions.FirstOrDefault(x => x.CorrectChoiceId == Choice.ChoiceId); if (question != null) { question.CorrectChoiceId = null; _context.Questions.Update(question); } _context.Choices.Remove(Choice); await _context.SaveChangesAsync(); } return(RedirectToPage("/Choices/Create", new { id = redirect })); }
public async Task SeedAsync() { await _context.Database.MigrateAsync().ConfigureAwait(false); if (!await _context.Users.AnyAsync()) { _logger.LogInformation("Generating inbuilt accounts"); const string adminRoleName = "administrator"; const string userRoleName = "user"; await EnsureRoleAsync(adminRoleName, "Default administrator", ApplicationPermissions.GetAllPermissionValues()); await EnsureRoleAsync(userRoleName, "Default user", new string[] { }); //var adminUser = await CreateUserAsync("admin", "Admin#123", "Inbuilt Administrator", "*****@*****.**", "+1 (123) 000-0000", new string[] { adminRoleName }); //var guestUser = await CreateUserAsync("user", "User#123", "Inbuilt Standard User", "*****@*****.**", "+1 (123) 000-0001", new string[] { userRoleName }); //adminUser.Permissions.Add _logger.LogInformation("Inbuilt account generation completed"); } if (!await _context.Customers.AnyAsync() && !await _context.ProductCategories.AnyAsync()) { _logger.LogInformation("Seeding initial data"); var cust_1 = new Customer { Name = " Trava", Email = "*****@*****.**", Gender = Gender.Male, CreatedDate = DateTime.UtcNow, //UpdatedDate = DateTime.UtcNow }; var cust_2 = new Customer { Name = "LanaLuna", Email = "*****@*****.**", PhoneNumber = "+81123456789", Address = "Some fictional Address, Street 123", City = "New Y", Gender = Gender.Female, CreatedDate = DateTime.UtcNow, UpdatedDate = DateTime.UtcNow }; var cust_3 = new Customer { Name = "John Doe", Email = "*****@*****.**", PhoneNumber = "+18585858", Address = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet", City = "Lorem Ipsum", Gender = Gender.Male, CreatedDate = DateTime.UtcNow, UpdatedDate = DateTime.UtcNow }; var cust_4 = new Customer { Name = "Jane Doe", Email = "*****@*****.**", PhoneNumber = "+18585858", Address = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet", City = "Lorem Ipsum", Gender = Gender.Male, CreatedDate = DateTime.UtcNow, //UpdatedDate = DateTime.UtcNow }; var prodCat_1 = new ProductCategory { Name = "None", Description = "Default category. Products that have not been assigned a category", CreatedDate = DateTime.UtcNow, //DateModified = DateTime.UtcNow }; var prod_1 = new Product { Name = "BMW M6", Description = "Yet another masterpiece from the world's best car manufacturer", BuyingPrice = 109775, SellingPrice = 114234, UnitsInStock = 12, IsActive = true, ProductCategory = prodCat_1, CreatedDate = DateTime.UtcNow, //DateModified = DateTime.UtcNow }; var prod_2 = new Product { Name = "Nissan Patrol", Description = "A true man's choice", BuyingPrice = 78990, SellingPrice = 86990, UnitsInStock = 4, IsActive = true, ProductCategory = prodCat_1, CreatedDate = DateTime.UtcNow }; var ordr_1 = new Order { Discount = 500, Cashier = await _context.Users.FirstAsync(), Customer = cust_1, CreatedDate = DateTime.UtcNow, UpdatedDate = DateTime.UtcNow, OrderDetails = new List <OrderDetail>() { new OrderDetail() { CreatedDate = DateTime.Now, UnitPrice = prod_1.SellingPrice, Quantity = 1, Product = prod_1 }, new OrderDetail() { UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2 }, } }; var ordr_2 = new Order { Cashier = await _context.Users.FirstAsync(), Customer = cust_2, CreatedDate = DateTime.UtcNow, UpdatedDate = DateTime.UtcNow, OrderDetails = new List <OrderDetail>() { new OrderDetail { CreatedDate = DateTime.Now, UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2 }, } }; _context.Customers.Add(cust_1); _context.Customers.Add(cust_2); _context.Customers.Add(cust_3); _context.Customers.Add(cust_4); _context.Products.Add(prod_1); _context.Products.Add(prod_2); _context.Orders.Add(ordr_1); _context.Orders.Add(ordr_2); await _context.SaveChangesAsync(); _logger.LogInformation("Seeding initial data completed"); } }
public async Task <ActionResult> OnGetAsync(int?foodItemId, int?personId, int?removeItemId, string?search, string?toDoActionReset) { if (toDoActionReset == "Reset") { Search = ""; } else { if (!string.IsNullOrWhiteSpace(search)) { Search = search.Trim(); } } var itemsQuery = _context.FoodItems.Include(o => o.Category).AsQueryable(); if (!string.IsNullOrWhiteSpace(Search)) { if (Search.Contains("%21")) { itemsQuery = itemsQuery.Where(b => !b.FoodItemName.Contains(Search) || !b.Category.CategoryName.Contains(Search)); } else { itemsQuery = itemsQuery.Where(b => b.FoodItemName.Contains(Search) || b.Category.CategoryName.Contains(Search)); } } SavedPersonId = personId.Value; if (removeItemId.HasValue) { var dOrderItems = _context.OrderItems.First(n => n.OrderItemId == removeItemId && n.PersonId == personId); _context.Attach(dOrderItems); _context.Remove(dOrderItems); _context.SaveChanges(); } if (!foodItemId.Equals(null) && personId.HasValue) { var newFoodItem = _context.FoodItems.First(n => n.FoodItemId == foodItemId); var newOrderItem = new OrderItem() { PersonId = personId.Value, FoodItem = newFoodItem, FoodItemId = newFoodItem.FoodItemId, Sum = newFoodItem.Price }; _context.OrderItems.Add(newOrderItem); await _context.SaveChangesAsync(); } itemsQuery = itemsQuery.OrderBy((b => b.Category.CategoryId)); Items = await itemsQuery.ToListAsync(); //var orderedItem = _context.OrderItems.First(n => n.OrderItemId == orderItemId); //var personId = orderedItem.PersonId; var orderedItemsQuery = _context.OrderItems .Where(n => n.PersonId == personId) .AsQueryable() .Include(o => o.FoodItem) .Include(o => o.FoodItem.Category); OrderedItems = await orderedItemsQuery.ToListAsync(); return(Page()); }