Example #1
0
        protected override async Task <HabitantViewModel> HandleEx(GetHabitantQuery query, CancellationToken cancellationToken = default)
        {
            var habitant = await habitantReadOnlyRepository.GetSingleAsync(query.Id);

            if (habitant.HasValue)
            {
                return(Mapper.Map <HabitantViewModel> (habitant.Value));
            }

            throw new NotFoundException("Habitant not found");
        }
        protected override async Task <Result> HandleEx(DeleteFriendFromHabitantCommand command, CancellationToken cancellationToken = default)
        {
            var habitant = await habitantReadOnlyRepository.GetSingleAsync(new HabitantId(command.HabitantId));

            await habitantRemoveFriendValidator.Validate(habitant, HabitantName.FromString(command.FriendName)).ConfigureAwait(false);

            habitant.Value.Friends.Remove(HabitantName.FromString(command.FriendName));

            await habitantRepository.UpdateAsync(habitant.Value.Id, habitant.Value).ConfigureAwait(false);

            return(Result.Ok());
        }
 protected async Task <bool> ExistHabitantAsync(Habitant habitant)
 {
     return((await habitantReadOnlyRepository.GetSingleAsync(habitant.Id).ConfigureAwait(false)).HasValue);
 }