Esempio n. 1
0
        public HttpResponseMessage GetTerm([FromUri] string term)
        {
            var glossary = InMemoryGlossaryProvider.Get();

            var possibleTerm = glossary.Find(term);

            if (possibleTerm.HasValue)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, possibleTerm.Value));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
Esempio n. 2
0
        public HttpResponseMessage UpdateTerm(string name, [FromBody] UpdateTermRequest request)
        {
            var glossary = InMemoryGlossaryProvider.Get();

            try
            {
                var updatedTerm = glossary.Update(name, request);

                return(Request.CreateResponse(HttpStatusCode.Created, updatedTerm));
            }
            catch (ArgumentNullException e)
            {
                logger.Error(e.ToString());
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Esempio n. 3
0
        public HttpResponseMessage Get([FromBody] RegisterTermRequest request)
        {
            var glossary = InMemoryGlossaryProvider.Get();

            try
            {
                var registeredTerm = glossary.Register(request);

                return(Request.CreateResponse(HttpStatusCode.Created, registeredTerm));
            }
            catch (ArgumentNullException e)
            {
                logger.Error(e.ToString());
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            catch (TermAlreadyRegisteredException e)
            {
                logger.Error(e.ToString());
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Esempio n. 4
0
        public HttpResponseMessage GetCount()
        {
            var glossary = InMemoryGlossaryProvider.Get();

            return(Request.CreateResponse(HttpStatusCode.OK, glossary.GetCount()));
        }