示例#1
0
        public IActionResult CreatescientificClass([FromBody] ScientificClassDto scientificClassDto)
        {
            if (scientificClassDto == null)
            {
                return(BadRequest(ModelState));
            }

            if (_scientificClassRepository.ScientificClassExits(scientificClassDto.Name))
            {
                ModelState.AddModelError("", "Scientific Class Exits!");
                return(StatusCode(404, ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var scientificClassObj = _mapper.Map <ScientificClass>(scientificClassDto);

            if (!_scientificClassRepository.CrateScientificClass(scientificClassObj))
            {
                ModelState.AddModelError("", $"Somethings went wrong when saving the record {scientificClassObj.Name}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetScientificClass", new
            {
                scientificClassId = scientificClassObj.Id
            }, scientificClassObj));
        }
示例#2
0
        public IActionResult UpdateScientificClass(int scientificClassId, [FromBody] ScientificClassDto scientificClassDto)
        {
            if (scientificClassDto == null || scientificClassId != scientificClassDto.Id)
            {
                return(BadRequest(ModelState));
            }

            var natiotionalParkObj = _mapper.Map <ScientificClass>(scientificClassDto);

            if (!_scientificClassRepository.UpdateScientificClass(natiotionalParkObj))
            {
                ModelState.AddModelError("", $"Somethings went wrong when updation the record {natiotionalParkObj.Name}");
                return(StatusCode(500, ModelState));
            }
            return(NoContent());
        }