示例#1
0
        public IHttpActionResult PostSkill(Skill skill)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            // Ownership reassignment is not allows
            if (skill.OwnerIdentity != User.Identity.Name)
                return BadRequest();

            db.Save(skill);

            return CreatedAtRoute("DefaultApi", new { id = skill.Id }, skill);
        }
示例#2
0
        public IHttpActionResult PutSkill(int id, Skill skill)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            // Ownership reassignment is not allows
            if (skill.OwnerIdentity != User.Identity.Name)
                return BadRequest();

            using(var tx = db.BeginTransaction())
            {
                db.SaveOrUpdate(skill);
                tx.Commit();
            }

            return StatusCode(HttpStatusCode.NoContent);
        }