Пример #1
0
        public IHttpActionResult PutChampionEntity(int id, ChampionEntity championEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != championEntity.DbId)
            {
                return(BadRequest());
            }

            _dbContext.Entry(championEntity).State = EntityState.Modified;

            try
            {
                _dbContext.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EntityExists(id))
                {
                    PostChampionEntity(championEntity);
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult PostChampionEntity(ChampionEntity championEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _dbContext.ChampionEntities.Add(championEntity);
            _dbContext.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = championEntity.DbId }, championEntity));
        }
Пример #3
0
        public void UpdateChampion(ChampionEntity champion)
        {
            var champPut = lolDBContext.Champs.Single(c => c.Id == champion.Id);

            champPut.Name        = champion.Name;
            champPut.Title       = champion.Title;
            champPut.SafeLane    = champion.SafeLane;
            champPut.Type        = champion.Type;
            champPut.Description = champion.Description;
            champPut.Skills      = champion.Skills;
            champPut.ImgBanner   = champion.ImgBanner;
            champPut.ImgIcon     = champion.ImgIcon;
            champPut.ImgCard     = champion.ImgCard;
            champPut.Region      = champion.Region;
        }
Пример #4
0
 public void CreateChampion(ChampionEntity champion)
 {
     lolDBContext.Entry(champion.Region).State = EntityState.Unchanged;
     lolDBContext.Champs.Add(champion);
 }