Esempio n. 1
0
        public IActionResult CreateUniversity([FromBody] UniversityDTO universityDTO)
        {
            if (universityDTO == null)
            {
                return(BadRequest(ModelState));
            }
            if (_repo.UniversityExists(universityDTO.Name))
            {
                ModelState.AddModelError("Error !", "University Exists");
                return(StatusCode(404, ModelState));
            }
            var uni = _mapper.Map <University>(universityDTO);

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