Beispiel #1
0
        public async Task <Result> RemoveAsync(long groupUserId)
        {
            _logger.LogInformation($"Removing GroupUser. GroupUserId {groupUserId}");

            Result <GroupUserEntity> getGroupUserResult = await _groupUserStore.SingleOrDefault(groupUserId);

            if (getGroupUserResult.Failure)
            {
                return(Result.Fail(getGroupUserResult));
            }

            GroupUserEntity groupUser = getGroupUserResult.Value;

            Result canManageResult = await _groupUserStore.CanManageUser(groupUser);

            if (canManageResult.Failure)
            {
                return(Result.Fail(canManageResult));
            }

            bool removeResult = await _groupUserDAO.Remove(groupUser);

            if (!removeResult)
            {
                _logger.LogError($"Failed to remove GroupUser. GroupUserId {groupUserId}");
                return(Result.Fail(FAILED_TO_REMOVE_GROUP_USER));
            }

            return(Result.Ok());
        }
        public async Task <Result> Remove(string userId)
        {
            IBaseSpecification <UserImageEntity, UserImageEntity> specification = SpecificationBuilder
                                                                                  .Create <UserImageEntity>()
                                                                                  .Where(x => x.UserId == userId)
                                                                                  .Select(x => new UserImageEntity(
                                                                                              x.Id))
                                                                                  .Build();

            UserImageEntity userImage = await _userImageDAO.SingleOrDefault(specification);

            if (userImage == null)
            {
                _logger.LogWarning($"User does not have a profile image. UserId {userId}");
                return(Result.Ok());
            }

            bool removeResult = await _userImageDAO.Remove(userImage);

            if (!removeResult)
            {
                _logger.LogError($"Failed to remove user image");
                return(Result.Fail(FAILED_TO_REMOVE_USER_IMAGE));
            }

            return(Result.Ok());
        }
Beispiel #3
0
        private async Task <Result> Remove(InviteEntity invite)
        {
            bool removeResult = await _inviteDAO.Remove(invite);

            if (!removeResult)
            {
                _logger.LogError($"Failed to remove invite");
                return(Result.Fail(FAILED_TO_REMOVE_INVITE));
            }

            return(Result.Ok());
        }
Beispiel #4
0
        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());
        }