Exemplo n.º 1
0
        // POST: api/AppClaims
        public IHttpActionResult Post([FromBody] AppClaimAdd newItem)
        {
            // Ensure that the URI is clean (and does not have an id parameter)
            if (Request.GetRouteData().Values["id"] != null)
            {
                return(BadRequest("Invalid request URI"));
            }

            // Ensure that a "newItem" is in the entity body
            if (newItem == null)
            {
                return(BadRequest("Must send an entity body with the request"));
            }

            // Ensure that we can use the incoming data
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Attempt to add the new object
            var addedItem = m.AppClaimAdd(newItem);

            // Continue?
            if (addedItem == null)
            {
                return(BadRequest("Cannot add the object"));
            }

            // HTTP 201 with the new object in the entity body
            // Notice how to create the URI for the Location header
            var uri = Url.Link("DefaultApi", new { id = addedItem.Id });

            return(Created(uri, addedItem));
        }
Exemplo n.º 2
0
        // AppClaimAdd
        public AppClaimBase AppClaimAdd(AppClaimAdd newItem)
        {
            // Maybe check for a retired match and resurrect it
            // Also check for existing match - keep them unique

            // Initial version of the method, without the fixes above...
            // Attempt to add the object
            var addedItem = ds.AppClaims.Add(Mapper.Map <AppClaim>(newItem));

            // Help configure a role claim with the official URI
            if (addedItem.ClaimType.ToLower() == "role")
            {
                addedItem.ClaimTypeUri = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
            }

            ds.SaveChanges();

            // Return the result
            return((addedItem == null) ? null : Mapper.Map <AppClaimBase>(addedItem));
        }