Example #1
0
        public HttpResponseMessage Post([FromBody] GlossaryDto glossary)
        {
            if ((glossary == null))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseApiResponse
                {
                    Code = InternalApiStatusCode.Error,
                    Message = "Invalid glossary object"
                }));
            }

            if (string.IsNullOrEmpty(glossary.Definition) || string.IsNullOrEmpty(glossary.Term))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseApiResponse
                {
                    Code = InternalApiStatusCode.FailedRequestValidation,
                    Message = "Invalid glossary object"
                }));
            }

            var glossaryResposne = new GlossaryResponse();

            try
            {
                if (_glossaryRepository.FindTerm(glossary.Term.Trim()))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseApiResponse
                    {
                        Code = InternalApiStatusCode.Conflict,
                        Message = "Glossary item already exists !"
                    }));
                }


                var glossaryResult = _glossaryRepository.Add(glossary);

                glossaryResposne.Glossary = glossaryResult;
                glossaryResposne.Code     = InternalApiStatusCode.Success;

                return(Request.CreateResponse(HttpStatusCode.Created, glossaryResposne));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Example #2
0
        public GlossaryDto Add(GlossaryDto entity)
        {
            var glossaryEntity = new GlossaryEntity
            {
                GlossaryEntityId = entity.GlossaryId,
                Definition       = entity.Definition,
                Term             = entity.Term,
                DateCreated      = entity.DateCreated,
                DateChanged      = entity.DateChanged
            };

            _dataContext.Glossaries.Add(glossaryEntity);

            _dataContext.SaveChanges();

            entity.GlossaryId = glossaryEntity.GlossaryEntityId;

            return(entity);
        }
Example #3
0
        public GlossaryDto Update(GlossaryDto entity)
        {
            var glossaryEntity = _dataContext.Glossaries.SingleOrDefault(g => g.GlossaryEntityId == entity.GlossaryId);

            if (glossaryEntity == null)
            {
                return(null);
            }

            glossaryEntity.Definition = entity.Definition;
            glossaryEntity.Term       = entity.Term;

            _dataContext.SaveChanges();

            return(new GlossaryDto
            {
                GlossaryId = glossaryEntity.GlossaryEntityId,
                Term = glossaryEntity.Term,
                Definition = glossaryEntity.Definition,
                DateChanged = glossaryEntity.DateChanged,
                DateCreated = glossaryEntity.DateCreated,
            });
        }