public async Task <IActionResult> PutAsync(int id, [FromBody] SaveUniversityResource resource)
        {
            var university = mapper.Map <SaveUniversityResource, University>(resource);
            var result     = await universityService.UpdateAsync(id, university);

            if (!result.Success)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
Beispiel #2
0
        public async Task <IActionResult> PostAsync([FromBody] SaveUniversityResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var university = _mapper.Map <SaveUniversityResource, University>(resource);
            var result     = await _universityService.SaveAsync(university);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var universityResource = _mapper.Map <University, UniversityResource>(result.Resource);

            return(Ok(universityResource));
        }