Exemplo n.º 1
0
        public async Task <IActionResult> PutCity([FromRoute] int id, [FromBody] City city)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != city.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> PutGroundItem(int id, GroundItem groundItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> LearnPower(int characterId, int power)
        {
            //CharacterModel characterData = await db.Characters.Select(c =>
            //    new CharacterModel() { Id = c.Id, Name = c.Name, MapId = c.MapId, WorldX = c.WorldX, WorldY = c.WorldY, InventoryId = c.InventoryId, Energy = (byte)c.Energy, Health = (byte)c.Health, ArmorId = c.ArmorId, LeftHandId = c.LeftHandId, RightHandId = c.RightHandId }).FirstOrDefaultAsync(c => c.Id == id); //.Include(c => c.Powers)
            Character character = await db.Characters.FindAsync(characterId);

            if (character == null)
            {
                return(NotFound());
            }

            int powerCount = await db.CharacterPowers.CountAsync(c => c.CharacterId == characterId);

            if (powerCount >= 7)
            {
                return(BadRequest());
            }

            CharacterPower newPower = db.CharacterPowers.Create();

            newPower.Power       = power;
            newPower.CharacterId = characterId;
            db.CharacterPowers.Add(newPower);

            await db.SaveChangesAsync();

            return(Ok(true));
        }
Exemplo n.º 4
0
        public async Task <int> AddCountryAsync(Country country)
        {
            await _contect.AddAsync(country);

            await _contect.SaveChangesAsync();

            return(country.Id);
        }
        public async Task <IHttpActionResult> CreateSession(int id) //Could be moved to PlayerSessionsPost, just ignore all incoming fields except CharacterId.
        {
            string        clientAddress = HttpContext.Current.Request.UserHostAddress.Trim();
            PlayerSession playerSession = await db.PlayerSessions.Where(ps => ps.CharacterId == id).FirstOrDefaultAsync();

            if (playerSession == null)
            {
                playerSession = db.PlayerSessions.Create();
                playerSession.ClientAddress = clientAddress;
                playerSession.Created       = DateTime.Now;
                db.PlayerSessions.Add(playerSession);
            }
            if (playerSession.ClientAddress != clientAddress)
            {
                return(BadRequest());
            }

            playerSession.CharacterId = id;
            int result = await db.SaveChangesAsync();

            return(Ok(playerSession.Id));
        }
Exemplo n.º 6
0
        public async Task <IHttpActionResult> PostContainerPosition(ItemContainerPositionModel positionModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Item itemToUpdate = await db.Items.FindAsync(positionModel.ItemId);

            if (itemToUpdate == null)
            {
                return(BadRequest(ModelState));
            }

            itemToUpdate.ContainerId = positionModel.ContainerId;
            itemToUpdate.WorldMapId  = itemToUpdate.WorldX = itemToUpdate.WorldY = null;

            //db.Items.Add(item);
            await db.SaveChangesAsync();

            //return CreatedAtRoute("DefaultApi", new { id = item.Id }, item);
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 7
0
        public async Task <int> AddCityAsync(City city)
        {
            var country = await _worldDbContext.Countries.FindAsync(city.Country.Id);

            city.UpdateCountry(country);
            try
            {
                await _worldDbContext.AddAsync(city);

                await _worldDbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw e;
            }

            return(city.Id);
        }