示例#1
0
        public async Task <IActionResult> CreateLecturer([FromBody] SaveLecturerResource lecturerResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var nameExist = await repository.LecturerNameExist(lecturer);

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

            repository.Add(lecturer);
            await unitOfWork.CompleteAsync();

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

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

            return(Ok(result));
        }