Beispiel #1
0
        public async Task <IActionResult> UpdateLecturer(int id, [FromBody] SaveLecturerResource lecturerResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var lecturer = await repository.GetLecturer(id);

            if (lecturer == null)
            {
                return(NotFound());
            }

            mapper.Map <SaveLecturerResource, Lecturer>(lecturerResource, lecturer);

            var nameExist = await repository.EditLecturerExist(lecturer);

            if (nameExist != null)
            {
                return(Conflict("Lecturer name already exists"));
            }

            await unitOfWork.CompleteAsync();

            lecturer = await repository.GetLecturer(lecturer.Id);

            var result = mapper.Map <Lecturer, LecturerResource>(lecturer);

            return(Ok(result));
        }