コード例 #1
0
        public async Task<Notifiable> Handle(UpdateCarWorkshopCommand request, CancellationToken cancellationToken)
        {
            var notifiable = new Notifiable();
            var existsCity = await _repository.ValidateCityById(request.CityId);

            if (!existsCity)
                notifiable.AddError($"A cidade não está cadastrada");

            var exists = await _repository.Exists(x => x.Id == request.Id);

            if (!exists)
                notifiable.AddError($"A oficina {request.Name} não está cadastrada");

            if (!notifiable.HasErrors)
            {
                var updated = new CarWorkshop(request.Id, request.Name, request.Phone, request.Address, request.CityId);

                _repository.Update(updated);
                await _repository.Save();
                updated = await _repository.GetById(updated.Id);
                notifiable.SetData(updated);
                notifiable.SetMessage("");
            }

            return notifiable;
        }
コード例 #2
0
        public async Task <Notifiable> Handle(CreateCarWorkshopCommand request, CancellationToken cancellationToken)
        {
            var existsCity = await _repository.ValidateCityById(request.CityId);

            if (!existsCity)
            {
                return(new Notifiable(new NotifiableError($"A Cidade {request.Name} não está cadastrada")));
            }

            var carWorkshop = new CarWorkshop(request.Name, request.Phone, request.Address, request.CityId);

            await _repository.Add(carWorkshop);

            await _repository.Save();

            carWorkshop = await _repository.GetById(carWorkshop.Id);

            return(new Notifiable("Oficina cadastrada com sucesso", carWorkshop));
        }