コード例 #1
0
ファイル: MajorController.cs プロジェクト: GedeonHuy/PMS
        public async Task <IActionResult> UpdateMajor(int id, [FromBody] MajorResource majorResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var major = await repository.GetMajor(id);

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

            mapper.Map <MajorResource, Major>(majorResource, major);

            repository.UpdateLecturers(major, majorResource);
            repository.UpdateProjects(major, majorResource);
            repository.UpdateGroups(major, majorResource);
            repository.UpdateStudents(major, majorResource);

            await unitOfWork.Complete();

            var result = mapper.Map <Major, MajorResource>(major);

            return(Ok(result));
        }