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)); }
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); }
public IEvent GetWashUpdatedEvent(WashDbModel wash) { return(new WashUpdatedEvent() { WashId = wash.Id, Done = wash.Done }); }
public IEvent GetWashCreatedEvent(WashDbModel wash) { return(new WashCreatedEvent() { UserId = wash.UserId, Type = wash.Type, StartTime = wash.StartTime, Duration = wash.Duration }); }
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); }
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)); }
public async void Remove(WashDbModel washDbModel) { await _entities.FirestoreDb?.Collection(_collection)?.Document(washDbModel.Id.ToString()).DeleteAsync(); }