public async Task <IActionResult> Update(string slug, [FromBody] ProviderWorkerUpdateModel model) { if (!ModelState.IsValid) { return(BadModelResponse()); } return(Ok(await _providerWorkerManager.UpdateBySlug(slug, model))); }
public async Task <ProviderWorkerDisplayModel> UpdateBySlug(string slug, ProviderWorkerUpdateModel model) { if (!await _providerRepository.IsWorkerInRoleBySlug(slug, _userId, ProviderWorkerRole.USER_MANAGER)) { throw new AccessDeniedException("", typeof(AppUser)); } var shortUser = await _appUserRepository.GetShortById(model.UserId); if (shortUser == null) { throw new EntityNotFoundException(model.UserId, typeof(AppUser)); } if (shortUser.Status == UserStatus.Blocked) { throw new MRException(-1, "User is blocked"); } ProviderWorker entity = _mapper.Map <ProviderWorker>(model); entity.UserEmail = shortUser.Email; if (!await _providerRepository.IsWorkerExistsBySlug(slug, model.UserId)) { await _providerRepository.InsertWorkersBySlug(slug, entity); } else { await _providerRepository.UpdateWorkerBySlug(slug, model.UserId, model.Roles); } if (!await _appUserManager.IsInRoleAsync(shortUser, AppUserRoleList.MANAGER)) { await _appUserManager.AddToRoleAsync(shortUser, AppUserRoleList.MANAGER); } return(_mapper.Map <ProviderWorkerDisplayModel>(entity).ApplyUser(shortUser)); }