public async Task<IActionResult> Register(UserPayment userPayment) { if (ModelState.IsValid) { UserApp userApp = new UserApp() { Name= userPayment.UserName }; _gameDbContext.UserApps.Add(userApp); _gameDbContext.SaveChanges(); string IP = _accessor.HttpContext.Connection.RemoteIpAddress.ToString(); int gameId = Convert.ToInt32(HttpContext.Session.GetString("gameId")); if (IP!=null) { Payment payment = new Payment() { Amount = userPayment.Amount, DateTime = userPayment.Date, Status = true, Ip = IP, GameId=gameId }; _gameDbContext.Payments.Add(payment); _gameDbContext.SaveChanges(); return RedirectToAction("Index","Home"); } } return View(); }
public IHttpActionResult PutGame(Guid id, Game Game) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != Game.Id) { return(BadRequest()); } db.Entry(Game).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GameExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
void UsunNiepotrzebne_Sprzatacz() { foreach (var inv in ctx.Inwestycja) { if (inv.Nazwa == "Przykład") { ctx.Inwestycja.Remove(inv); } } foreach (var user in ctx.Użytkownik) { if (user.Login == "Nowak") { ctx.Użytkownik.Remove(user); } } foreach (var fm in ctx.Firma) { if (fm.Name == "Przykład") { ctx.Firma.Remove(fm); } } ctx.SaveChanges(); }
public ActionResult Add(Game gameLibrary) { if (gameLibrary != null) { db.Games.Add(gameLibrary); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(GameCreate gameCreate) { if (ModelState.IsValid) { _db.GameCreates.Add(gameCreate); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gameCreate)); }
private void UpdateGameDb() { var gameService = new GameService.GameService(_executingDirectory); var gameIds = FolderUtils.GetGameIds(_executingDirectory); using (var db = new GameDbContext(_executingDirectory)) { foreach (var existingGame in db.Games) { db.Remove(existingGame); } foreach (var existingDisc in db.Discs) { db.Remove(existingDisc); } db.SaveChanges(); foreach (var id in gameIds) { var gameInfo = gameService.GetGameInfo(id); var game = new Game() { Id = id, Title = gameInfo.Title, Publisher = gameInfo.Publisher, Year = gameInfo.Year, Players = gameInfo.Players }; var i = 1; foreach (var discId in gameInfo.DiscIds) { var disc = new Disc() { GameId = id, DiscNumber = i, DiscBasename = discId }; i++; db.Add(disc); } db.Add(game); } db.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Title,GameLength,Publisher,Designer,MinPlayer,MaxPlayer,RecPlayer,Mechanism,Theme,Complexity")] Game game) { if (ModelState.IsValid) { db.Games.Add(game); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(game)); }
public ActionResult Create([Bind(Include = "Id,GameId,Name,Owner,Age,CharDesc,Plat,Gold,Silver,Copper,Str,Int,Dex,Luck,Speed,Charisma,CharacterBackground")] Character character) { if (ModelState.IsValid) { db.Characters.Add(character); db.SaveChanges(); return(Redirect(TempData["UrlReferrer"] + "/Characters/Test/" + TempData["CustomViewId"].ToString())); } ViewBag.GameId = new SelectList(db.Game, "Id", "Name", character.GameId); return(Redirect(TempData["UrlReferrer"].ToString())); }
private bool ShutUp(bool usedShutUp) { using var db = new GameDbContext(); var config = db.BotConfigs.FirstOrDefault(); if (config == null) { return(false); } var shutUpLastUsedSeconds = (DateTime.Now - config.ShutUpLastUsed).TotalSeconds; if (usedShutUp) { if (shutUpLastUsedSeconds < config.ShutUpDuration && config.ShutUpEnabled) { return(true); } if (shutUpLastUsedSeconds >= config.ShutUpDuration && config.ShutUpEnabled) { config.ShutUpEnabled = false; db.SaveChanges(); return(false); } if (config.ShutUpEnabled) { return(false); } config.ShutUpLastUsed = DateTime.Now; config.ShutUpEnabled = true; db.SaveChanges(); return(true); } if (!config.ShutUpEnabled) { return(false); } if (shutUpLastUsedSeconds < config.ShutUpDuration && config.ShutUpEnabled) { return(true); } if (shutUpLastUsedSeconds >= config.ShutUpDuration && config.ShutUpEnabled) { config.ShutUpEnabled = false; db.SaveChanges(); return(false); } return(false); }
public ActionResult Create([Bind(Include = "Id,CharacterId,Name,Description,Intensity")] Spell spell) { if (ModelState.IsValid) { db.Spells.Add(spell); db.SaveChanges(); return(Redirect(TempData["UrlReferrer"] + "/Characters/Test/" + TempData["CustomViewId"].ToString())); } ViewBag.CharacterId = new SelectList(db.Characters, "Id", "Name", spell.CharacterId); return(View(spell)); }
public ActionResult Create([Bind(Include = "Id,Name")] Player player) { player.StartParams(); if (ModelState.IsValid) { db.Players.Add(player); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(player)); }
public bool Action(CancellationToken ct) { if (ct.IsCancellationRequested) { return(false); } if (IEnumerableEx.IsNullOrEmpty(targetUsers)) { using (var db = new GameDbContext(dbo_game)) { db.Database.ExecuteSqlRaw( "INSERT INTO `game_mails`(`userid`, `typeid`, `title`, `message`, `sentdate`, " + "`item1id`, `item2id`, `item3id`, `item4id`, `item5id`, `item1cnt`, `item2cnt`, `item3cnt`, `item4cnt`, `item5cnt`) " + "SELECT `id`, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13} FROM `game_users`", (int)mail.typeid, mail.title, mail.message, mail.sentdate.ToDBFormatString(), mail.item1id, mail.item2id, mail.item3id, mail.item4id, mail.item5id, mail.item1cnt, mail.item2cnt, mail.item3cnt, mail.item4cnt, mail.item5cnt); db.agent_events.Add(AgentEvent.Create(AgentEvent.TypeID.MailCreateAll)); db.SaveChanges(); } } else { var mails = new List <GameUser.Mail>(); foreach (var userid in targetUsers) { var newmail = new GameUser.Mail(); DataMapping.Copy(mail, newmail); newmail.userid = userid; mails.Add(newmail); } using (var db = new GameDbContext(dbo_game)) { db.ChangeTracker.AutoDetectChangesEnabled = false; db.game_mails.AddRange(mails); db.ChangeTracker.AutoDetectChangesEnabled = true; if (ct.IsCancellationRequested) { return(false); } db.SaveChanges(); db.agent_events.Add(AgentEvent.Create(AgentEvent.TypeID.MailCreate, mails.First().id, mails.Last().id)); db.SaveChanges(); } } return(true); }
public async Task <IActionResult> Rate(RateGameViewModel vm) { var currentUser = await _userManager.GetUserAsync(HttpContext.User); if (currentUser == null) { return(RedirectToAction("Index", "Home")); } using (var db = new GameDbContext(((Server)_server).ConnectionString)) { var review = db.Reviews.FirstOrDefault(r => r.UserId.ToString().Equals(currentUser.Id) && r.Game.Name.Equals(vm.GameName)); if (review == null) { review = new Review { Id = Guid.NewGuid(), UserId = Guid.Parse(currentUser.Id), Game = db.Games.First(g => g.Name.Equals(vm.GameName)), Rating = 0, Comment = "" }; db.Reviews.Add(review); } review.Rating = vm.Rating; review.Comment = vm.Comment; db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
static string SaveSettings() { Console.Clear(); var boardWidth = 0; var boardHeight = 0; var userCanceled = false; (boardWidth, userCanceled) = GetUserIntInput("Enter board width", 9, 20, 0); if (userCanceled) { return(""); } (boardHeight, userCanceled) = GetUserIntInput("Enter board height", 9, 20, 0); if (userCanceled) { return(""); } _settings.BoardHeight = boardHeight; _settings.BoardWidth = boardWidth; _context.Add(_settings); _context.SaveChanges(); return(""); }
public bool AddGame(string name, string image, double size, decimal price, string url, string description, DateTime releaseDate) { using (var db = new GameDbContext()) { if (db.Games.Any(p => p.Title == name)) { return(false); } var game = new Game { Title = name, Description = description, ImageThumbnail = image, YouTubeVideoId = url, Size = size, Price = price, ReleaseDate = releaseDate }; db.Add(game); db.SaveChanges(); } return(true); }
/// <summary> /// Регистрация пользователя /// </summary> /// <param name="userName">Логин</param> /// <param name="password">Пароль</param> public void RegisterUser(string userName, string password) { _context.Users.Add(new User { UserName = userName, Password = password }); _context.SaveChanges(); }
// saves new Game object in database and returns partial view with info about game and links for opponent public ActionResult Create(string name) { // TODO: create fail view when there is no chosenSymbol in session state var symbol = (Symbol) Session["ChosenSymbol"]; var player = new Player() { Name = name, Symbol = symbol }; var game = new Game() { Player1 = player, Player2 = null }; using (var context = new GameDbContext()) { context.Players.Add(player); context.Games.Add(game); context.SaveChanges(); } return PartialView(game); }
public void Can_track_an_entity_with_more_than_10_properties() { using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName)) { var options = Fixture.CreateOptions(testDatabase); using (var context = new GameDbContext(options)) { context.Database.EnsureCreated(); context.Characters.Add(new PlayerCharacter(new Level { Game = new Game() })); context.SaveChanges(); } using (var context = new GameDbContext(options)) { var character = context.Characters .Include(c => c.Level.Game) .OrderBy(c => c.Id) .First(); Assert.NotNull(character.Game); Assert.NotNull(character.Level); Assert.NotNull(character.Level.Game); } } }
public IActionResult Index(int gameid, int review) { Game reviewgame = context.Games.Single(g => g.User == GetCurrentUserAsync().Result&& g.ID == gameid); reviewgame.Review = review; context.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Сохранить игру авторизованного пользователя /// </summary> /// <param name="map">Игровое поле в строковом представлении</param> public void SaveGame(string map) { var user = _context.Users.Single(u => u.UserName == UserName); user.CurrentGame = map; _context.SaveChanges(); }
public IActionResult Add(AddGenreViewModel addGenreViewModel) { if (ModelState.IsValid) { Genre newGenre = new Genre { Name = addGenreViewModel.Name }; context.Genres.Add(newGenre); context.SaveChanges(); return(Redirect("/Genre")); } return(View(addGenreViewModel)); }
public IActionResult Delete(Game game) { using (var db = new GameDbContext()) { db.Games.Remove(game); db.SaveChanges(); return(RedirectToAction("Index")); } }
public RedirectToPageResult OnPost() { GameEngine = new GameController(_context, GameId) { CurrentGame = { GameName = GameName } }; _context.SaveChanges(); return(RedirectToPage("../SaveGames/Index")); }
private void dataGridView4_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == dataGridView4.Columns["Buy"].Index) { DateTime data_aktualna = DateTime.Parse(czas_aktualny.Text); if (!data_aktualna.IsHoliday()) { // MessageBox.Show("Row:"+(e.RowIndex + 1) + " Column: " + (e.ColumnIndex + 1) + " Column button clicked "); // kup daną inwestycję Inwestycja inv = (Inwestycja)dataGridView4.Rows[e.RowIndex].DataBoundItem; // MessageBox.Show(inv.ToString()); //Kup inwestycję: var user = (from tmp in ctx.Użytkownik where tmp.Hasło == userPasswd select tmp).First(); try { int ilość = Int32.Parse(dataGridView4.Rows[e.RowIndex].Cells[dataGridView4.Columns["ilość"].Index].Value.ToString()); if (user.StanKonta < ilość * inv.Kurs) { MessageBox.Show("Brak środków"); } else { Operacja operation = new Operacja() { Transakcja = transakcja.kupno, StempelCzasowy = Convert.ToDateTime(czas_aktualny.Text), Ilość = ilość, Inwestycja = inv }; user.Operacja.Add(operation); user.StanKonta -= ilość * inv.Kurs * inv.Przelicznik; MessageBox.Show("zakupiłeś inwestycje " + inv.Nazwa); // Odśwież(); ctx.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Uzupełnij: pole ilość" + ex); } } } }
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)); }
public void Remove(string email, int id) { using (var db = new GameDbContext()) { var userGame = db.UserGames.SingleOrDefault(p => p.User.Email == email && p.Game.Id == id); db.UserGames.Remove(userGame); db.SaveChanges(); } }
public void Clear(string email) { using (var db = new GameDbContext()) { var orders = db.UserGames.Where(p => p.User.Email == email); db.UserGames.RemoveRange(orders); db.SaveChanges(); } }
public ActionResult CreateGame(Game game) { game.Id = Guid.NewGuid(); using (var context = new GameDbContext()) { context.Games.Add(game); context.SaveChanges(); } return(RedirectToAction("Index")); }
public IActionResult Edit(Game game) { using (var db = new GameDbContext()) { var gameToEdit = db.Games.FirstOrDefault(t => t.Id == game.Id); gameToEdit.Name = game.Name; gameToEdit.Price = game.Price; gameToEdit.Dlc = game.Dlc; gameToEdit.Platform = game.Platform; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Register(GameUserViewModel viewModel) { if (viewModel.Password != viewModel.ConfirmPassword) { return(View()); } var gameUsers = new GameUser(); mapper(gameUsers, viewModel); db.User.Add(gameUsers); db.SaveChanges(); return(RedirectToAction("Login")); }
public GameMessageId ResetCharacter(string user, string character) { if (!IsCharacterOwned(user, character)) { return(GameMessageId.Error); } if (IsConnected(user)) { return(GameMessageId.AccountConnected); } int resetLevel = Int32.Parse(ConfigurationManager.AppSettings["ResetLevel"]); int resetCap = Int32.Parse(ConfigurationManager.AppSettings["ResetMax"]); using (var c = new GameDbContext()) { Character ch = c.Characters.Find(character); //maybe not needed //ch = (Character)c.Entry(ch).GetDatabaseValues().ToObject(); if (ch.cLevel < resetLevel) { return(GameMessageId.ResetFailLevel); } else if (ch.Resets >= resetCap) { return(GameMessageId.ResetFailCap); } else if (ch.Money < GetResetCost(ch.Resets)) { return(GameMessageId.ResetFailZen); } else { //db.Users.Attach(updatedUser); //var entry = db.Entry(updatedUser); //entry.Property(e => e.Email).IsModified = true; //// other changed properties //db.SaveChanges(); ch.cLevel = 1; ch.Experience = 0; ch.Money -= GetResetCost(ch.Resets); ch.MapNumber = 0; ch.MapPosX = 182; ch.MapPosY = 128; ch.Resets += 1; c.SaveChanges(); //c.Entry(ch).GetDatabaseValues(); return(GameMessageId.ResetSuccess); } } }
public ActionResult Submit(int id, string name) { var symbol = (Symbol) Session["ChosenSymbol"]; var player = new Player() { Name = name, Symbol = symbol }; using (var context = new GameDbContext()) { var game = context.Games .Include(g => g.Player1) .Include(g => g.Player2) .SingleOrDefault(g => g.Id == id); if (game == null) { game = new Game(); game.Player1 = player; // TODO: przemyśl czy: // TODO: - powinieneś trzymać referencję do DataLoader w tym obiekcie, czy tworzyć każdorazowo, gdy jest potrzebny // TODO: - jw. z BasicUrlGenerator context.Players.Add(player); context.Games.Add(game); context.SaveChanges(); var urlGenerator = new BasicUrlGenerator(); game.RefLink = urlGenerator.GetUrl(game.Id); context.SaveChanges(); return PartialView("~/Views/NewLayout/Create.cshtml", game); } else { game.Player2 = player; context.Players.Add(player); context.SaveChanges(); return PartialView("~/Views/NewLayout/ShowPartial.cshtml", game); } } }