public async Task <Result> RemoveAsync(string id) { IBaseSpecification <GroupEntity, GroupEntity> specification = SpecificationBuilder .Create <GroupEntity>() .Where(x => x.Id == id) .Include(x => x.Invites) .Include(x => x.Users) .Build(); Result <GroupEntity> getGroupResult = await _groupStore.SingleOrDefault(specification); if (getGroupResult.Failure) { return(Result.Fail(getGroupResult)); } _logger.LogInformation($"Removing group. GroupId {id}"); GroupEntity groupEntity = getGroupResult.Value; string guid = Guid.NewGuid().ToString(); groupEntity.Name = $"deleted_group_{guid}"; bool updateResult = await _groupDAO.Update(groupEntity); if (!updateResult) { _logger.LogError($"Failed to update group for deleting. GroupId {id}"); return(Result.Fail(FAILED_TO_UPDATE_USER)); } if (groupEntity.Invites.Any()) { _logger.LogInformation($"Removing group invites. GroupId {groupEntity.Id}"); bool removeGroupInvitesResult = await _inviteDAO.RemoveRange(groupEntity.Invites); if (!removeGroupInvitesResult) { _logger.LogError($"Failed to remove group invites. GroupId {groupEntity.Id}"); } } if (groupEntity.Users.Any()) { _logger.LogInformation($"Removing group users. GroupId {groupEntity.Id}"); bool removeGroupUsersResult = await _groupUserDAO.RemoveRange(groupEntity.Users); if (!removeGroupUsersResult) { _logger.LogError($"Failed to remove group users. GroupId {groupEntity.Id}"); } } bool removeResult = await _groupDAO.Remove(groupEntity); if (!removeResult) { _logger.LogError($"Failed to remove Group. GroupId {id}"); return(Result.Fail("failed_to_remove_group", "Failed to remove group")); } return(Result.Ok()); }