Пример #1
0
        public HttpResponseMessage Post([FromBody] SourceValueListDTO values)
        {
            try
            {
                //create a new value
                if (dbDal.CreatedSourceValueList(values))
                {
                    HttpResponseMessage msg = Request.CreateResponse(HttpStatusCode.Created, values);

                    string location = HttpContext.Current.Request.Url + "/" + values.LookupID;
                    msg.Headers.Location = new Uri(location);

                    return(msg);
                }
                else
                {
                    //something went wrong
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, "An error occurred when creating the source value list"));
                }
            }
            catch (InvalidOperationException e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "The Source Value already exists"));
            }
            catch (ArgumentNullException e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Message was not valid"));
            }
            catch (NpgsqlException e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Database error occurred"));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "An error occurred when creating the source value list"));
            }
        }
Пример #2
0
        public HttpResponseMessage Get(int lookupID)
        {
            try
            {
                SourceValueListDTO retVal = null;

                if (dbDal.ReadSourceValue_List(lookupID, out retVal))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, retVal));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Source Value List not found"));
                }
            }
            catch (NpgsqlException e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Database error occurred"));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to get the source value list"));
            }
        }