Esempio n. 1
0
        public IHttpActionResult Update(int id, Char @char)
        {
            @char.Id = id;

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

            Context.Chars.Attach(@char);
            var entry = Context.Entry(@char);
            entry.State = EntityState.Modified;

            Context.SaveChanges();

            return Ok();
        }
Esempio n. 2
0
        public IHttpActionResult Create(Char @char)
        {
            @char.UserId = User.Identity.GetUserId();

            ModelState.Clear();
            Validate(@char);

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

            @char = Context.Chars.Add(@char);
            Context.SaveChanges();

            var user = (from u in Context.Users
                                    where u.Id == @char.UserId
                                    select u).Single();
            user.MainCharId = @char.Id;
            Context.SaveChanges();

            return Ok(@char.Id);
        }