Exemplo n.º 1
0
        public IActionResult CreateInstitute([FromBody] InstituteDto instituteDto)
        {
            if (instituteDto == null)
            {
                return(BadRequest(ModelState));
            }
            if (_insRepo.InstituteExists(instituteDto.Name))
            {
                ModelState.AddModelError("", "Institute Exists!");
                return(StatusCode(404, ModelState));
            }
            var instituteObj = _mapper.Map <Institute>(instituteDto);

            if (!_insRepo.CreateInstitute(instituteObj))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record {instituteObj.Name}");
                return(StatusCode(500, ModelState));
            }
            return(CreatedAtRoute("GetInstitute", new { instituteId = instituteObj.Id }, instituteObj));
        }
 public Institute CreateInstitute(Institute institute)
 {
     return _repo.CreateInstitute(institute);
 }