Exemple #1
0
        public ContractUpdateResponse updateContract(ContractRequest _request)
        {
            ContractUpdateResponse response = new ContractUpdateResponse();

            using (var conn = createConnection())
            {
                conn.Open();

                try
                {
                    using (var cmd = new NpgsqlCommand(new SQLStatements().updateContract(_request), conn))
                        using (var reader = cmd.ExecuteReader())
                        {
                            response = validateUpdate(reader, _request.Id);

                            response.originalRequest = _request;
                        }
                }
                catch (Exception e)
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.BadRequest);
                    resp.Content = new StringContent(e.Message);

                    throw new HttpResponseException(resp);
                }
            }

            return(response);
        }
Exemple #2
0
        private ContractUpdateResponse validateUpdate(NpgsqlDataReader reader, int contractId)
        {
            ContractUpdateResponse response = new ContractUpdateResponse();

            if (reader.HasRows)
            {
                response.updateSuccessful = true;
            }
            else
            {
                var resp = new HttpResponseMessage(HttpStatusCode.BadRequest);
                resp.Content = new StringContent(String.Format("Error updating contract. {0}", contractId));

                throw new HttpResponseException(resp);
            }
            return(response);
        }