public async Task HandleAsync(CreateRecipCommand command) { if (command == null) { throw ExceptionFactory.CommandIsNull(); } var tmp = _createMapper.Map(command); if (tmp == null) { throw ExceptionFactory.MappingOfRecipeFailed(); } if (tmp.Nutrient.ProteinInfo != null && tmp.Nutrient.ProteinInfo.Name == null) { tmp.Nutrient.ProteinInfo = null; } if (tmp.Nutrient.CarbohydratesInfo != null && tmp.Nutrient.CarbohydratesInfo.Name == null) { tmp.Nutrient.CarbohydratesInfo = null; } if (tmp.Nutrient.EnergyInfo != null && tmp.Nutrient.EnergyInfo.Name == null) { tmp.Nutrient.EnergyInfo = null; } if (tmp.Nutrient.EnergyKcalInfo != null && tmp.Nutrient.EnergyKcalInfo.Name == null) { tmp.Nutrient.EnergyKcalInfo = null; } if (tmp.Nutrient.FatInfo != null && tmp.Nutrient.FatInfo.Name == null) { tmp.Nutrient.FatInfo = null; } if (tmp.Nutrient.FiberInfo != null && tmp.Nutrient.FiberInfo.Name == null) { tmp.Nutrient.FiberInfo = null; } if (tmp.Nutrient.SaltInfo != null && tmp.Nutrient.SaltInfo.Name == null) { tmp.Nutrient.SaltInfo = null; } if (tmp.Nutrient.SaturatedFatInfo != null && tmp.Nutrient.SaturatedFatInfo.Name == null) { tmp.Nutrient.SaturatedFatInfo = null; } if (tmp.Nutrient.SodiumInfo != null && tmp.Nutrient.SodiumInfo.Name == null) { tmp.Nutrient.SodiumInfo = null; } if (tmp.Nutrient.SugarsInfo != null && tmp.Nutrient.SugarsInfo.Name == null) { tmp.Nutrient.SugarsInfo = null; } _unitOfWork.Foodrepos.AddRecip(tmp); _eventStore.AddEvents(_foodEventFactory.GetFoodCreatedEvent(tmp)); await _unitOfWork.SaveAsync(); }
public async Task <Reservation> Create(CreateReservationRequest createReservationRequest) { var reservation = new Reservation(createReservationRequest); if (await _eventStore.StreamExists(reservation.Id)) { throw new ConflictException("Reservation already exists"); } reservation.OnSave = async x => { await _eventStore.AddEvents(x.Id, x.Events); }; return(reservation); }
public bool AddEvents(IEnumerable <DomainEvent> newEvents) { lock (eventStore) { return(eventStore.AddEvents(newEvents)); } }
public void NewAppointments(Guid medicalPracticeId, Date day) { var patients = patientRepository.GetAllPatients().ToList(); var user = configurationRepository.GetAllUsers().First(); var eventstream = eventStore.GetEventStreamForADay(new AggregateIdentifier(day, medicalPracticeId)); if (eventstream.EventCount > 0) { MessageBox.Show("cannot create appointments - there are already appointments"); return; } var medicalPractice = configurationRepository.GetMedicalPracticeByIdAndVersion(medicalPracticeId, eventstream.Id.PracticeVersion); if (!medicalPractice.HoursOfOpening.IsOpen(day)) { MessageBox.Show("cannot create appointments - practice is not open"); return; } var identifier = new AggregateIdentifier(day, medicalPractice.Id, medicalPractice.Version); var openingTime = medicalPractice.HoursOfOpening.GetOpeningTime(day); var closingTime = medicalPractice.HoursOfOpening.GetClosingTime(day); var eventList = new List <DomainEvent>(); uint aggregateVersion = 0; foreach (var therapyPlace in medicalPractice.GetAllTherapyPlaces()) { var currrentTime = openingTime; currrentTime += RandomTimeInterval(0); while (currrentTime + new Duration(60 * 60) < closingTime) { var newEvent = CreateAppointmentData(patients, user, identifier, aggregateVersion++, currrentTime, closingTime, therapyPlace.Id); eventList.Add(newEvent); currrentTime += new Duration(newEvent.StartTime, newEvent.EndTime); currrentTime += RandomTimeInterval(0); } } eventStore.AddEvents(eventList); }
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 Task HandleAsync(UpdateCacheCommand command) { if (command == null) { throw ExceptionFactory.CommandIsNull(); } List <RecipModel> listOfRecipModel = new List <RecipModel>(); RootobjectModel rootobject = GetRootobject(GetFoodrepoProducts($"https://www.foodrepo.org/api/v3/products?page%5Bnumber%5D=1&page%5Bsize%5D={ command.PageSize }").Result, command.PageNumer); listOfRecipModel.AddRange(rootobject.Data); for (int i = 0; i < 3; i++) { rootobject = GetRootobject(GetFoodrepoProducts(rootobject.Links.Next).Result, command.PageNumer); listOfRecipModel.AddRange(rootobject.Data); } var tmpListOfRecips = (from RecipModel model in listOfRecipModel select _recipMapper.Map(model)).ToList(); var listOfRecip = _unitOfWork.Foodrepos.GetAllAsyncRecip().Result; foreach (Recip recip in listOfRecip) { if (tmpListOfRecips.Select(x => x.RepoId).ToList().Contains(recip.RepoId)) { tmpListOfRecips.Remove(tmpListOfRecips.Where(x => x.RepoId == recip.RepoId).First()); } } if (tmpListOfRecips.Count > 0 || listOfRecip.Count == 0) { try { _unitOfWork.Foodrepos.AddRangeRecip(tmpListOfRecips); _eventStore.AddEvents(_foodrepoEventFactory.GetFoodrepoUpdatedEvent(tmpListOfRecips)); await _unitOfWork.SaveAsync(); } catch (Exception ex) { _logger.LogError(ex.Message); } } }
public void Save(Aggregate aggregate) { _store.AddEvents(aggregate.Id, aggregate.GetEvents()); }