Esempio n. 1
0
        public async Task <IActionResult> CreateFaculty([FromBody] SaveFacultyResource facultyResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var faculty = mapper.Map <SaveFacultyResource, Faculty>(facultyResource);

            var nameExist = await repository.FacultyNameExist(faculty);

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

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

            faculty = await repository.GetFaculty(faculty.Id);

            var result = mapper.Map <Faculty, FacultyResource>(faculty);

            return(Ok(result));
        }