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

            var major = await repository.GetMajor(id);

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

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

            var nameExist = await repository.EditMajorExist(major);

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

            await unitOfWork.CompleteAsync();

            major = await repository.GetMajor(major.Id);

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

            return(Ok(result));
        }