示例#1
0
        public HttpResponseMessage Get(int lookupID)
        {
            try
            {
                SourceValueDTO retVal = null;

                if (dbDal.ReadSourceValue_Item(lookupID, out retVal))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, retVal));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to get the value"));
                }
            }
            catch (NpgsqlException e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Database error occurred"));
            }
            catch (ArgumentException e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The Source Value was not found"));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to get the value"));
            }
        }
示例#2
0
        public IHttpActionResult Post([FromBody] SourceValueDTO value)
        {
            try
            {
                int?feedHash = null;

                //create a new value
                if (dbDal.CreatedSourceValue(value, out feedHash))
                {
                    return(this.CreatedAtRoute("GetSingleValue", new
                    {
                        lookupID = feedHash.Value
                    }, value));
                }
                else
                {
                    //something went wrong
                    return(Content(HttpStatusCode.InternalServerError, "Failed to add the Source Value"));
                }
            }
            catch (NpgsqlException e)
            {
                return(Content(HttpStatusCode.InternalServerError, "Database error occurred"));
            }
            catch (ArgumentNullException e)
            {
                return(Content(HttpStatusCode.BadRequest, "The message was not valid"));
            }
            catch (InvalidOperationException e)
            {
                return(Content(HttpStatusCode.Conflict, "The Source Value already exists"));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, "Failed to add the Source Value"));
            }
        }