コード例 #1
0
        Nancy.Response UpdateNotification(string id)
        {
            NotificationModel notification = null;

            // capture actual string posted in case the bind fails (as it will if the JSON is bad)
            // need to do it now as the bind operation will remove the data
            String rawBody = this.GetRawBody();

            try {
                notification = this.Bind <NotificationModel>();

                NotificationMapper not_mpr = new NotificationMapper();
                notification.Id = id;

                NotificationModel res = not_mpr.GetById(id);

                if (res == null)
                {
                    return(ErrorBuilder.ErrorResponse(this.Request.Url.ToString(), "GET", HttpStatusCode.NotFound, String.Format("A notification with Id = {0} does not exist", id)));
                }
                not_mpr.update(notification);

                Nancy.Response response = Response.AsJson(notification);
                response.StatusCode = HttpStatusCode.OK;

                string uri = this.Request.Url.SiteBase + this.Request.Path + "/" + notification.Id;
                response.Headers["Location"] = uri;

                return(response);
            } catch (Exception e) {
                String operation = String.Format("NotificationModule.UpdateBadge({0})", (notification == null) ? "No Model Data" : notification.Message);
                return(HandleException(e, operation));
            }
        }