コード例 #1
0
ファイル: GlossaryController.cs プロジェクト: hysyzq/AWI
 public ActionResult Edit(int id, IFormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         GlossaryItem item = new GlossaryItem();
         item.Id         = id;
         item.Term       = collection["Term"];
         item.Definition = collection["Definition"];
         _repos.Update(item);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
コード例 #2
0
        public HttpResponseMessage Put(int id, [FromBody] GlossaryRequest glossary)
        {
            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
            {
                var glossaryResult = _glossaryRepository.Update(new GlossaryDto
                {
                    GlossaryId = id,
                    Definition = glossary.Definition,
                    Term       = glossary.Term
                });

                if (glossaryResult == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new BaseApiResponse
                    {
                        Code = InternalApiStatusCode.Error,
                        Message = "Glossary item is not found"
                    }));
                }

                glossaryResposne.Glossary = glossaryResult;
                glossaryResposne.Code     = InternalApiStatusCode.Success;
                glossaryResposne.Message  = "Glossary item updated";

                return(Request.CreateResponse(HttpStatusCode.OK, glossaryResposne));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
コード例 #3
0
ファイル: GlossaryService.cs プロジェクト: basry/Glossary
 public async Task <GlossaryModel> Update(GlossaryModel model)
 {
     _repository.Update(model);
     return(model);
 }