예제 #1
0
 public async Task <GlossaryModel> Create(GlossaryModel model)
 {
     if (model.IsValid())
     {
         _repository.Add(model);
     }
     else
     {
         throw new GlossaryException("The glossary is not valid");
     }
     return(model);
 }
예제 #2
0
 public void Add()
 {
     if (FieldNotEmpty(_selectedItem.Term, _selectedItem.Definition))
     {
         if (_listIndex == null)
         {
             GlossaryRepository.Add(SelectedItem);
         }
         else
         {
             GlossaryRepository.Add(SelectedItem, (int)_listIndex);
             _listIndex = null;
         }
         Items   = GlossaryRepository.Items;
         Editing = false;
         Sort();
     }
     else
     {
         MessageBox.Show("Field is empty", "Notice");
     }
 }
예제 #3
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));
            }
        }