示例#1
0
        public async Task <IActionResult> UpdateFaculty(int id, [FromBody] SaveFacultyResource facultyResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var faculty = await repository.GetFaculty(id);

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

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

            var nameExist = await repository.EditFacultyExist(faculty);

            if (nameExist != null)
            {
                return(Conflict("Faculty details already exist"));
            }

            await unitOfWork.CompleteAsync();

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

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

            return(Ok(result));
        }