Exemplo n.º 1
0
        /// <summary>
        /// Asks the service to create a new echo, using the supplied information.
        /// </summary>
        /// <param name="data">
        /// The supplied POST-data used to create a new echo.
        /// </param>
        /// <returns>
        /// HTTP Status Code 201 - Created + Unique link to newly created echo,
        ///     HTTP Status Code 400 - Bad Request if no ID was returned, or the supplied POST-data failed validation. Also contains information on failed validation cases.
        ///     HTTP Status Code 409 - Conflict if a echo with a provided unique value already exists,
        ///     HTTP Status Code 500 - Internal Server Error if the other codes don't apply. Contains exception on DEBUG.
        /// </returns>
        public IHttpActionResult Post(Echo data)
        {
            var result = _echoService.Create(data);

            switch (result.ActionStatus.Status)
            {
            case ActionStatusEnum.Success:
                return(CreateHttpActionResult("Echo", result.ActionStatus.Id));

            case ActionStatusEnum.ValidationError:
                return(ApiControllerExtension.BadRequest(this, result.BrokenValidationRules, data.GetType().Name));

            case ActionStatusEnum.Conflict:
                return(Conflict());
            }

            return(HandleErrorActionResult(result));
        }