Ejemplo n.º 1
0
        public HttpResponseMessage Get(int lookupID)
        {
            try
            {
                RuleFedDTO retVal = null;

                //get rule by hash
                if (dbDal.ReadRule_FedUri(lookupID, out retVal))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, retVal));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to get the federation rule"));
                }
            }
            catch (ArgumentException e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The Federation Rule was 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 federation rule"));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult Put(int lookupID, [FromBody] RuleFedDTO value, string destination = null)
        {
            if (value == null)
            {
                return(Content(HttpStatusCode.BadRequest, "The message was not valid"));
            }

            try
            {
                //If the destination is given, update the existing rule with the new destination.
                if (destination != null)
                {
                    if (!dbDal.AddRuleFed(lookupID, destination))
                    {
                        return(this.StatusCode(HttpStatusCode.InternalServerError));
                    }
                }
                // Otherwise, attempt to update rule.
                else
                {
                    if (!dbDal.UpdatedRule_FedUri(lookupID, value))
                    {
                        return(this.StatusCode(HttpStatusCode.InternalServerError));
                    }
                }
            }
            catch (ArgumentException e)
            {
                return(Content(HttpStatusCode.BadRequest, "The Federation Rule was not valid.  It was missing a required value or contained an invalid value."));
            }
            catch (InvalidOperationException e)
            {
                return(Content(HttpStatusCode.BadRequest, "The Federation Rule was not valid.  It was missing a required value or contained an invalid value."));
            }
            catch (NpgsqlException e)
            {
                return(Content(HttpStatusCode.InternalServerError, "Database error occurred"));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, "Failed to add the Federation Rule"));
            }
            return(Ok());
        }
Ejemplo n.º 3
0
        public IHttpActionResult Post([FromBody] RuleFedDTO value)
        {
            try
            {
                int ruleHash = -1;

                //create a new rule
                if (dbDal.CreatedRule_FedUri(value, out ruleHash))
                {
                    return(this.CreatedAtRoute("GetSingleFederationRule", new
                    {
                        lookupID = ruleHash
                    }, value));
                }
                else
                {
                    // something went wrong
                    return(this.StatusCode(HttpStatusCode.InternalServerError));
                }
            }
            catch (InvalidOperationException e)
            {
                return(Content(HttpStatusCode.BadRequest, "The Federation Rule was not valid.  It was missing a required value or had an invalid one."));
            }
            catch (ArgumentNullException e)
            {
                return(Content(HttpStatusCode.BadRequest, "The message was not valid"));
            }
            catch (NpgsqlException e)
            {
                return(Content(HttpStatusCode.InternalServerError, "Database error occurred"));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, "Failed to add the Federation Rule"));
            }
        }