Example #1
0
        public IActionResult CreatePathWay([FromBody] PathwayCreateDTO pathwayCreateDTO)
        {
            if (pathwayCreateDTO == null)
            {
                return(BadRequest(ModelState));
            }
            if (_repo.PathWayExists(pathwayCreateDTO.Name))
            {
                ModelState.AddModelError("Error !", "PathWay Exists");
                return(StatusCode(404, ModelState));
            }
            var pw = _mapper.Map <PathWay>(pathwayCreateDTO);

            if (!_repo.CreatePathWay(pw))
            {
                ModelState.AddModelError("Error !", $"Something went wrong when creating the record {pw.Name}");
                return(StatusCode(500, ModelState));
            }
            //return Ok();
            //Tu dong goi HttpGet voi Id de hien thi thong tin ngay lap tuc
            return(CreatedAtRoute("GetPathWay", new { id = pw.Id }, pw));
        }