예제 #1
0
        public IActionResult SaveEntity(WardViewModel wardVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }

            if (wardVm.Id == 0)
            {
                _wardService.Add(wardVm);
            }
            else
            {
                _wardService.Update(wardVm);
            }

            _wardService.Save();
            return(new OkObjectResult(wardVm));
        }