Example #1
0
 public IActionResult Post([FromBody] ChildModel childModel)
 {
     try
     {
         var child         = childModel.ToDomainModel();
         var newChild      = _childService.Add(child);
         var newChildModel = newChild.ToApiModel();
         return(Ok(newChildModel));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("AddChild", ex.Message);
         return(BadRequest(ModelState));
     }
 }
Example #2
0
        public IActionResult Put(int id, [FromBody] ChildModel childModel)
        {
            try
            {
                //return Ok(_childService.Update(child).ToApiModel());

                var child             = childModel.ToDomainModel();
                var updatedChild      = _childService.Update(child);
                var updatedChildModel = updatedChild.ToApiModel();
                return(Ok(updatedChildModel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("UpdateChild", ex.Message);
                return(BadRequest(ModelState));
            }
        }