コード例 #1
0
        // GET: api/LookupType
        public IHttpActionResult Get(HttpRequestMessage request)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Executing call in debug mode");
            }

            var  headers      = request.Headers;
            bool showInActive = false;

            if (headers.Contains("showInactive"))
            {
                showInActive = Boolean.Parse(headers.GetValues("showInactive").First());
            }

            //Check the request object to see if they passed a userId
            if (headers.Contains("userid"))
            {
                var user = headers.GetValues("userid").First();
                _log.InfoFormat("Handling GET request from user: {0}", user);

                try
                {
                    LookupTypeActions lookupActions = new LookupTypeActions();
                    _log.Debug("Getting Lookup Types");
                    IEnumerable <LookupTypeModel> lookupTypeList = lookupActions.Get(showInActive);
                    var lookupTypeModels = lookupTypeList as IList <LookupTypeModel> ?? lookupTypeList.ToList();
                    _log.DebugFormat("Lookup Types retreived Count: {0}", lookupTypeModels.Count());
                    return(Ok(lookupTypeModels));
                }
                catch (Exception e)
                {
                    _log.Error("An error occurred while getting Lookup Types.", e);
                    return(InternalServerError(e));
                }
            }

            return(BadRequest("Header value <userid> not found."));
        }
コード例 #2
0
        public IHttpActionResult Put(HttpRequestMessage request, LookupTypeModel value)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Executing call in debug mode");
            }

            var headers = request.Headers;

            //Check the request object to see if they passed a userId
            if (headers.Contains("userid"))
            {
                var user = headers.GetValues("userid").First();
                _log.InfoFormat("Handling PUT request from user: {0}", user);

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }

                try
                {
                    LookupTypeActions lookupActions = new LookupTypeActions();

                    lookupActions.Update(value, user);
                    _log.Debug("Lookup Type Updated");
                    return(Ok());
                }
                catch (Exception e)
                {
                    _log.Error("An error occurred while updating Lookup Type.", e);
                    return(InternalServerError(e));
                }
            }

            return(BadRequest("Header value <userid> not found."));
        }
コード例 #3
0
        // GET: api/LookupType/5
        public IHttpActionResult Get(int id, HttpRequestMessage request)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Executing call in debug mode");
            }

            var headers = request.Headers;

            //Check the request object to see if they passed a userId
            if (headers.Contains("userid"))
            {
                var user = headers.GetValues("userid").First();
                _log.InfoFormat("Handling GET request from user: {0}", user);

                LookupTypeActions lookupActions = new LookupTypeActions();
                try
                {
                    _log.Debug("Getting LookupType");

                    var lookupTypeModel = lookupActions.GetById(id);
                    if (lookupTypeModel != null)
                    {
                        _log.DebugFormat("LookupType retrieved. ID: {0}", lookupTypeModel.Id);
                        return(Ok(lookupTypeModel));
                    }
                    return(Ok());
                }
                catch (Exception e)
                {
                    _log.Error("An error occurred while getting Lookup Type.", e);
                    return(InternalServerError(e));
                }
            }
            return(BadRequest("Header value <userid> not found."));
        }