コード例 #1
0
        public async Task <IActionResult> AddFMAdmin(FMAdminForAddDto fmAdminForAddDto)
        {
            if (await _repo.FMAdminExists(fmAdminForAddDto.UserId))
            {
                return(BadRequest("File Manager Admin user already exists"));
            }

            var user = await _repo.GetUser(fmAdminForAddDto.UserId);

            if (user == null)
            {
                return(BadRequest("User does not exist exists"));
            }

            var fmAdminToAdd = _mapper.Map <FileManagerAdmin>(fmAdminForAddDto);

            var createdFMAdmin = await _repo.AddFMAdmin(fmAdminToAdd);

            var fmAdminToReturn = _mapper.Map <FMAdminForListDto>(createdFMAdmin);

            return(CreatedAtRoute("GetFMAdmin", new { controller = "FMAdmins", id = createdFMAdmin.Id }, fmAdminToReturn));
        }