예제 #1
0
        public void Handle(UpdateWashCommand command)
        {
            WashDbModel washDbModel = _unitOfWork.Wash.GetRecentByUserIdAsync(command.UserId).Result;

            if (washDbModel == null)
            {
                return;
            }

            if (washDbModel.Done)
            {
                throw ExceptionFactory.NoWashIsOnGoingException();
            }

            washDbModel.Done = command.Abort;

            if (command.Abort)
            {
                _unitOfWork.Wash.Update(washDbModel.Id, new Dictionary <string, object>()
                {
                    { "Done", command.Abort }
                });
            }
            else
            {
                DateTime startTime = _timeService.UtcNow;
                _unitOfWork.Wash.StartWashThread(washDbModel.Duration, $"{washDbModel.Id}-{washDbModel.Type}");
                _unitOfWork.Wash.Update(washDbModel.Id, new Dictionary <string, object>()
                {
                    { "StartTime", startTime }
                });
            }

            _eventStore.AddEvents(_washEventFactory.GetWashUpdatedEvent(washDbModel));
        }
예제 #2
0
        public async Task <string> Add(WashDbModel washDbModel)
        {
            washDbModel.UserId = _crypto.Encrypt(washDbModel.UserId, "J2uEDdYPYG4h996V");

            DocumentReference docRef = await _entities.FirestoreDb?.Collection(_collection)?.AddAsync(washDbModel);

            return(docRef.Id);
        }
예제 #3
0
 public IEvent GetWashUpdatedEvent(WashDbModel wash)
 {
     return(new WashUpdatedEvent()
     {
         WashId = wash.Id,
         Done = wash.Done
     });
 }
예제 #4
0
 public IEvent GetWashCreatedEvent(WashDbModel wash)
 {
     return(new WashCreatedEvent()
     {
         UserId = wash.UserId,
         Type = wash.Type,
         StartTime = wash.StartTime,
         Duration = wash.Duration
     });
 }
예제 #5
0
        public bool IsWashOnGoingForUser(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                return(true);
            }

            WashDbModel dbModel = GetRecentByUserIdAsync(userId).Result;

            if (dbModel == null)
            {
                return(true);
            }                                     //TODO: Is this right

            return(dbModel.Done);
        }
예제 #6
0
        public void Handle(CreateWashCommand command)
        {
            if (command == null)
            {
                return;
            }
            if (!_unitOfWork.Wash.IsWashOnGoingForUser(command.UserId))
            {
                throw ExceptionFactory.WashIsOnGoingException();
            }

            var newDbModel = new WashDbModel()
            {
                Done      = false,
                Duration  = int.Parse(_config.GetSection("WashTypes").GetSection(command.Type.ToString()).Value),
                StartTime = _timeService.UtcNow,
                Type      = command.Type,
                UserId    = command.UserId
            };

            newDbModel.Id = _unitOfWork.Wash.Add(newDbModel).Result;

            _eventStore.AddEvents(_washEventFactory.GetWashCreatedEvent(newDbModel));
        }
예제 #7
0
 public async void Remove(WashDbModel washDbModel)
 {
     await _entities.FirestoreDb?.Collection(_collection)?.Document(washDbModel.Id.ToString()).DeleteAsync();
 }