Exemplo n.º 1
0
        public async Task <IResponse <Domain.Tamagochi> > Handle(CreateTamagochiCommand request, CancellationToken cancellationToken)
        {
            if (_tamagochiTypeRepository.GetById(request.Type).Result == null)
            {
                return(this.RespondWith().ApplicationError <Domain.Tamagochi>("TamagochiType not available."));
            }

            Domain.Tamagochi tamagochi = new Domain.Tamagochi()
            {
                Type          = request.Type,
                Name          = request.Name,
                BirthDateTime = request.BirthDateTime,
                Happiness     = request.Happiness,
                Hungry        = request.Hungry
            };

            await _tamagochiRepository.Create(tamagochi);


            return(this.RespondWith().Ok(tamagochi));
        }
Exemplo n.º 2
0
        public async Task <IResponse <Domain.Tamagochi> > Handle(FeedTamagochiCommand request, CancellationToken cancellationToken)
        {
            var tamagochi = await _tamagochiRepository.GetById(request.TamagochiId);

            if (tamagochi == null)
            {
                return(this.RespondWith().ApplicationError <Domain.Tamagochi>("We couldn't found your tamagochi."));
            }


            var types = await _tamagochiTypeRepository.GetById(tamagochi.Type);

            if (types == null)
            {
                return(this.RespondWith().ApplicationError <Domain.Tamagochi>("We couldn't found your tamagochi type."));
            }

            decimal factor = types.FeedFactor;
            var     result = await _tamagochiRepository.FeedTamagochiAsync(request.TamagochiId, factor);


            return(this.RespondWith().Ok(result));
        }