Example #1
0
        public T Update(T entity, int key)
        {
            if (entity == null)
            {
                return(null);
            }
            var exist = _context.Set <T>().Find(key);

            if (exist != null)
            {
                _context.Entry(exist).CurrentValues.SetValues(entity);
                _context.SaveChanges();
            }
            return(exist);
        }
Example #2
0
        public async Task <IHttpActionResult> UpdateGame(long id, Game game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Validate IDs are the same
            if (id != game.Id)
            {
                return(BadRequest());
            }

            db.Entry(game).State = EntityState.Modified;

            try
            {
                // Save the changes
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
0
        public async Task <IHttpActionResult> UpdatePlayer(long id, Player player)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Make sure the IDs match
            if (id != player.Id)
            {
                return(BadRequest());
            }

            db.Entry(player).State = EntityState.Modified;

            try
            {
                // Save the changes
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlayerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
        public async Task <IActionResult> PutGame([FromRoute] Guid id, [FromBody] Data.Models.Game game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != game.Id)
            {
                return(BadRequest());
            }

            _context.Entry(game).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        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));
        }
        public void TestUpdate_ShouldUpdateGameById()
        {
            var options = new DbContextOptionsBuilder <GameDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new GameDbContext(options);

            SeedData(context);
            var repository = new GameRepository(context);

            var gameToUpdate = repository.GetById(1);

            gameToUpdate.Title = "Lorem";

            var actualState = context.Entry(gameToUpdate).State;

            repository.Update(gameToUpdate);


            EntityState expectedState = EntityState.Modified;


            Assert.Equal(expectedState, actualState);
        }
        public async Task <IActionResult> PutGame(int id, Game game)
        {
            if (id != game.ID)
            {
                return(BadRequest());
            }

            _context.Entry(game).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public ActionResult Edit([Bind(Include = "Title,GameLength,Publisher,Designer,MinPlayer,MaxPlayer,RecPlayer,Mechanism,Theme,Complexity")] Game game)
 {
     if (ModelState.IsValid)
     {
         db.Entry(game).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(game));
 }
 public ActionResult Edit([Bind(Include = "Id,CharacterId,Name,Description,Intensity")] Spell spell)
 {
     if (ModelState.IsValid)
     {
         db.Entry(spell).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect(TempData["UrlReferrer"] + "/Characters/Test/" + TempData["CustomViewId"].ToString()));
     }
     ViewBag.CharacterId = new SelectList(db.Characters, "Id", "Name", spell.CharacterId);
     return(View(spell));
 }
Example #10
0
        public async Task <CarSlotInfoTrans> GetCarSlots(int personaId)
        {
            AppPersona persona = await _personaService.FindPersonaById(personaId);

            await _context.Entry(persona)
            .Collection(p => p.OwnedCars)
            .LoadAsync();

            CarSlotInfoTrans carSlotInfoTrans = new CarSlotInfoTrans();

            carSlotInfoTrans.OwnedCarSlotsCount   = persona.OwnedCars.Count;
            carSlotInfoTrans.DefaultOwnedCarIndex = persona.SelectedCarIndex;
            carSlotInfoTrans.CarsOwnedByPersona   = new List <OwnedCarTrans>();
            carSlotInfoTrans.ObtainableSlots      = new List <ProductTrans>();

            foreach (var personaOwnedCar in persona.OwnedCars)
            {
                carSlotInfoTrans.CarsOwnedByPersona.Add(ConvertOwnedCarToContract(personaOwnedCar));
            }

            return(carSlotInfoTrans);
        }
        public ActionResult Edit([Bind(Include = "Id,GameId,Name,Owner,Age,CharDesc,Plat,Gold,Silver,Copper,Str,Int,Dex,Luck,Speed,Charisma,CharacterBackground")] Character character)
        {
            int CustomViewId = (int)TempData["CustomViewId"];

            if (ModelState.IsValid)
            {
                db.Entry(character).State = EntityState.Modified;
                db.SaveChanges();
                return(Redirect(TempData["UrlReferrer"] + "/Characters/Test/" + CustomViewId.ToString()));
            }
            ViewBag.GameId = new SelectList(db.Game, "Id", "Name", character.GameId);
            return(Redirect(TempData["UrlReferrer"].ToString()));
        }
Example #12
0
        public ActionResult UpdateGame(Game postGame)
        {
            using (var context = new GameDbContext())
            {
                var entity = context.Games.Find(postGame.Id);

                if (entity != null)
                {
                    context.Entry(entity).CurrentValues.SetValues(postGame);
                }
                context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Example #13
0
        public ActionResult DeleteGame(Guid id)
        {
            using (var context = new GameDbContext())
            {
                var Game = context.Games.FirstOrDefault(x => x.Id == id);

                if (Game != null)
                {
                    context.Games.Remove(Game);
                    context.Entry(Game).State = EntityState.Deleted;
                    context.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Example #14
0
        public async Task <UserInfo> GetPermanentSession(AppUser user, string token)
        {
            // Load personas
            await _dbContext.Entry(user)
            .Collection(u => u.Personas)
            .LoadAsync();

            // Reset session info
            await CreateSession(user);

            return(new UserInfo
            {
                personas = new List <ProfileData>(user.Personas.Select(ConvertPersonaToProfile)),
                user = new User
                {
                    securityToken = token,
                    fullGameAccess = false,
                    isComplete = false,
                    userId = user.Id,
                    remoteUserId = user.Id
                }
            });
        }
Example #15
0
 public async Task Update <T>(T entity) where T : BaseEntity
 {
     GameDbContext.Entry(entity).State = EntityState.Modified;
     await GameDbContext.SaveChangesAsync();
 }
Example #16
0
 public void Update(Player player)
 {
     _db.Entry(player).State = EntityState.Modified;
 }
Example #17
0
        private void Turn(PlayerComponent currentPlayer)
        {
            var manager = currentPlayer.Game.Manager;

            foreach (var levelEntity in manager.Levels)
            {
                var level = levelEntity.Level;
                if (level.TerrainChanges != null)
                {
                    level.TerrainChanges.Clear();
                }
                else
                {
                    level.TerrainChanges = new Dictionary <int, byte>();
                }

                if (level.KnownTerrainChanges != null)
                {
                    level.KnownTerrainChanges.Clear();
                }
                else
                {
                    level.KnownTerrainChanges = new Dictionary <int, byte>();
                }

                if (level.WallNeighboursChanges != null)
                {
                    level.WallNeighboursChanges.Clear();
                }
                else
                {
                    level.WallNeighboursChanges = new Dictionary <int, byte>();
                }

                if (_dbContext.Snapshot?.LevelSnapshots.ContainsKey(levelEntity.Id) != true)
                {
                    level.VisibleTerrainSnapshot = null;
                }

                level.VisibleNeighboursChanged = false;
            }

            currentPlayer.Game.ActingPlayer = null;
            manager.TimeSystem.AdvanceToNextPlayerTurn(manager);

            //TODO: If all players are dead end the game

            _dbContext.ChangeTracker.AutoDetectChangesEnabled = false;
            foreach (var levelEntity in manager.Levels)
            {
                var level = levelEntity.Level;

                var levelEntry = _dbContext.Entry(level);
                if (levelEntry.State == EntityState.Added)
                {
                    continue;
                }

                if (level.TerrainChanges == null ||
                    level.TerrainChanges.Count > 0)
                {
                    levelEntry.Property(l => l.Terrain).IsModified = true;
                }

                if (level.KnownTerrainChanges == null ||
                    level.KnownTerrainChanges.Count > 0)
                {
                    levelEntry.Property(l => l.KnownTerrain).IsModified = true;
                }

                if (level.WallNeighboursChanges == null ||
                    level.WallNeighboursChanges.Count > 0)
                {
                    levelEntry.Property(l => l.WallNeighbours).IsModified = true;
                }

                // TODO: Move VisibleTerrainSnapshot and VisibleTerrainChanges to the snapshot
                if (level.VisibleTerrainChanges == null)
                {
                    level.VisibleTerrainChanges = new Dictionary <int, byte>();
                }
                else
                {
                    level.VisibleTerrainChanges.Clear();
                }

                if (level.VisibleTerrainSnapshot != null)
                {
                    for (var i = 0; i < level.VisibleTerrain.Length; i++)
                    {
                        var newValue = level.VisibleTerrain[i];
                        if (newValue != level.VisibleTerrainSnapshot[i])
                        {
                            level.VisibleTerrainChanges.Add(i, newValue);
                        }
                    }
                }

                if (level.VisibleTerrainSnapshot == null ||
                    level.VisibleTerrainChanges.Count > 0)
                {
                    levelEntry.Property(l => l.VisibleTerrain).IsModified = true;
                }

                if (level.VisibleNeighboursChanged)
                {
                    levelEntry.Property(l => l.VisibleNeighbours).IsModified = true;
                }
            }

            _dbContext.ChangeTracker.AutoDetectChangesEnabled = true;

            _dbContext.SaveChanges(acceptAllChangesOnSuccess: false);
        }
 private int Update(WinnerPlayer winnerPlayer)
 {
     _context.Entry(winnerPlayer).State = EntityState.Modified;
     _context.SaveChanges();
     return(1);
 }