Exemplo n.º 1
0
        public IHttpActionResult Create(Race race)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Context.Races.Add(race);
            Context.SaveChanges();

            return Ok();
        }
Exemplo n.º 2
0
        public IHttpActionResult Update(int id, Race race)
        {
            race.Id = id;

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Context.Races.Attach(race);
            var entry = Context.Entry(race);
            entry.State = EntityState.Modified;

            Context.SaveChanges();

            return Ok();
        }
Exemplo n.º 3
0
        public IHttpActionResult Update(int id, Class @class)
        {
            @class.Id = id;

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            // really f*****g dirty, but working!!!

            var entry = Context.Entry(@class);
            var tmp = new Race[@class.AvailableRaces.Count];
            @class.AvailableRaces.CopyTo(tmp, 0);

            @class.AvailableRaces.Clear();
            entry.State = EntityState.Modified;

            entry.Collection(i => i.AvailableRaces).Load();
            @class.AvailableRaces.Clear();

            foreach (var race in tmp)
            {
                @class.AvailableRaces.Add(Context.Races.Find(race.Id));
            }

            Context.SaveChanges();

            return Ok();
        }