コード例 #1
0
 public ActionResult <coreevent.Person> Post([FromBody] coreevent.Person value)
 {
     try
     {
         //string authorization = Request.Headers["Authorization"];
         if (!ModelState.IsValid)
         {
             throw new ArgumentException("ModelState must be invalid", nameof(ModelState));
         }
         var np = _personService.CreatePerson(value);
         return(Ok(np));
     }
     catch (Exception ex)
     {
         var sb = new System.Text.StringBuilder();
         while (ex != null)
         {
             ModelState.AddModelError("Person:Post", ex.Message);
             ex = ex.InnerException;
         }
         return(BadRequest(ModelState));
     }
 }
コード例 #2
0
        public async Task <IActionResult> Put([FromBody] coreevent.Person item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new ArgumentException("ModelState must be invalid", nameof(ModelState));
                }
//                if (id != item.Id)
//                    return NotFound("Person not found");
                var np = _personService.UpdatePerson(item);
                return(Ok(np));
            }
            catch (Exception ex)
            {
                var sb = new System.Text.StringBuilder();
                while (ex != null)
                {
                    ModelState.AddModelError("Person:Put", ex.Message);
                    ex = ex.InnerException;
                }
                return(BadRequest(ModelState));
            }
        }