public async Task <IActionResult> AddUser([FromQuery] Guid groupHash) { var username = User.Identity.Name; var user = await _userManager.FindByNameAsync(username); var profile = await _profileService.GetProfileByUserId(user.Id); var groupDto = await _groupService.GetGroupByGuidAsync(groupHash); var groupProfileDto = new GroupProfilesDto { ProfileId = profile.Id, GroupId = groupDto.Id, }; var checkDouble = await _groupService.CheckDoubleAsyncProfileToGroup(groupProfileDto); if (checkDouble) { await _groupService.AddAsyncProfileToGroup(groupProfileDto); return(RedirectToAction("Index", "Group")); } return(Content("Данный пользователь уже присутствует в группе")); }
public async Task AddAsyncProfileToGroup(GroupProfilesDto groupProfiles) { if (groupProfiles is null) { throw new ArgumentNullException(nameof(groupProfiles)); } var groupProfilesModel = new GroupProfiles { ProfileId = groupProfiles.ProfileId, GroupId = groupProfiles.GroupId }; await _repositoryGroupProfiles.AddAsync(groupProfilesModel); await _repositoryGroupProfiles.SaveChangesAsync(); }
public async Task <bool> CheckDoubleAsyncProfileToGroup(GroupProfilesDto groupProfiles) { if (groupProfiles is null) { throw new ArgumentNullException(nameof(groupProfiles)); } var getUserGroup = await _repositoryGroupProfiles.GetEntityWithoutTrackingAsync(groupProfile => groupProfile.ProfileId == groupProfiles.ProfileId && groupProfile.GroupId == groupProfiles.GroupId); if (getUserGroup != null) { return(false); } else { return(true); } }