Exemple #1
0
        public IHttpActionResult Create([FromBody] Principal value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                service.Create(value);
                return(CreatedAtRoute("Principals_Create", new { id = value.Id }, value));
            }
            catch (UnauthorizedAccessException)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
Exemple #2
0
        public ActionResult <Principal> Create([FromBody] Principal value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                service.Create(value);
                return(CreatedAtRoute(nameof(Read), new { id = value.Id }, value));
            }
            catch (UnauthorizedAccessException)
            {
                return(Forbid());
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }