Пример #1
0
        public async Task <IActionResult> AddAgencyAsync([FromBody] Model.AgencyModel model)
        {
            var entity = _mapper.Map <Entity.Agency>(model);

            _pimsAdminService.Agency.Add(entity);

            // TODO: This isn't ideal as the db update may be successful but this request may not.
            await entity.Users.ForEachAsync(async u =>
            {
                var user = _pimsAdminService.User.Get(u.UserId);
                await _pimsKeycloakService.UpdateUserAsync(user);
            });

            var agency = _mapper.Map <Model.AgencyModel>(entity);

            return(CreatedAtAction(nameof(GetAgency), new { id = agency.Id }, agency));
        }
Пример #2
0
        public async Task <IActionResult> AddOrganizationAsync([FromBody] Model.OrganizationModel model)
        {
            var entity = _mapper.Map <Entity.PimsOrganization>(model);

            _pimsService.UserOrganization.Add(entity);

            // TODO: This isn't ideal as the db update may be successful but this request may not.
            await entity.PimsUserOrganizations.ForEachAsync(async u =>
            {
                var user = _pimsService.User.Get(u.User.GuidIdentifierValue.Value);
                await _pimsKeycloakService.UpdateUserAsync(user);
            });

            var organization = _mapper.Map <Model.OrganizationModel>(entity);

            return(CreatedAtAction(nameof(GetOrganization), new { id = organization.Id }, organization));
        }
Пример #3
0
        public async Task <IActionResult> UpdateUserAsync(Guid id, [FromBody] AdminModels.UserModel model)
        {
            var user   = _mapper.Map <Entity.User>(model);
            var entity = await _keycloakService.UpdateUserAsync(user);

            var result = _mapper.Map <AdminModels.UserModel>(entity);

            return(new JsonResult(result));
        }