Ejemplo n.º 1
0
        /// <summary>
        /// Asks the service to create a new notification, using the supplied information.
        /// </summary>
        /// <param name="data">
        /// The supplied POST-data used to create a new notification.
        /// </param>
        /// <returns>
        /// HTTP Status Code 201 - Created + Unique link to newly created notification,
        ///     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 notification 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(Notification data)
        {
            var result = _notificationService.Create(data);

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

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

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

            return(HandleErrorActionResult(result));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asks the service to asynchronously create a new user, using the supplied information.
        /// </summary>
        /// <param name="data">
        /// The supplied POST-data used to create a new user.
        /// </param>
        /// <returns>
        /// HTTP Status Code 201 - Created + Unique link to newly created user,
        ///     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 user 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 async Task <IHttpActionResult> Post(User data)
        {
            var result = await _userService.CreateAsync(data);

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

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

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

            return(HandleErrorActionResult(result));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Put(int id, Notification data)
        {
            data.Id = id;
            var result = _notificationService.Update(data);

            switch (result.ActionStatus.Status)
            {
            case ActionStatusEnum.Success:
                return(result.ActionStatus.SubStatus == ActionSubStatusEnum.Created
                               ? CreateHttpActionResult("Notification", result.ActionStatus.Id)
                               : StatusCode(HttpStatusCode.NoContent));

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

            return(HandleErrorActionResult(result));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> Put(decimal id, User data)
        {
            data.Id = id;
            var result = await _userService.UpdateAsync(data);

            switch (result.ActionStatus.Status)
            {
            case ActionStatusEnum.Success:
                return(result.ActionStatus.SubStatus == ActionSubStatusEnum.Created
                               ? CreateHttpActionResult("UserAsync", result.ActionStatus.Id)
                               : StatusCode(HttpStatusCode.NoContent));

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

            return(HandleErrorActionResult(result));
        }