public void Update(Participant participant) { var gender = participant.Person.Gender.HasValue ? (byte)participant.Person.Gender : (byte?)null; var dbParticipant = _repository.Update(GuidUtil.ToGuid(participant.Id), participant.Bagage, participant.Person.FirstNameInPassport, participant.Person.LastNameInPassport, participant.Person.DateOfBirth, gender); if (!dbParticipant.Gender.HasValue || string.IsNullOrWhiteSpace(dbParticipant.FirstNameInPassport) || string.IsNullOrWhiteSpace(dbParticipant.LastNameInPassport) || dbParticipant.Bagage == null || !dbParticipant.DateOfBirth.HasValue) { throw new ApplicationException("U heeft nog niet alle boekingsgegevens ingevuld."); } var isComplete = dbParticipant.Availabilities.All(a => a.Value.HasValue); if (!isComplete) { throw new ApplicationException("U heeft nog niet alle beschikbaarheid ingevuld."); } var dbEvent = new EventRepository(_dbContext).Single(dbParticipant.EventID); // dont send to myself if the organizer is a participant also if (!dbParticipant.Email.Equals(dbEvent.OrganizerEmail)) { _mailService.SendAvailabilityUpdate(dbEvent, dbParticipant); } dbParticipant.AvailabilityConfirmed = true; _dbContext.Current.SaveChanges(); }
public Participant Add(string eventId, string name, string email) { var dbEvent = new EventRepository(_dbContext).Single(GuidUtil.ToGuid(eventId)); var dbParticipant = _repository.Add(dbEvent.ID, name, email); return(EntityMapper.Map(dbParticipant)); }
public void SelectFlight(string eventId, long flightSearchId, long flightId) { _repository.Single(GuidUtil.ToGuid(eventId)); var dbFlightySearch = new FlightSearchRepository(_dbContext).Single(flightSearchId); dbFlightySearch.SelectedFlightID = flightId == 0 ? (long?)null : flightId; _dbContext.Current.SaveChanges(); }
public void SendReminder(string eventId, string[] participantIds) { var dbEvent = _repository.Single(GuidUtil.ToGuid(eventId)); var participants = dbEvent.Participants.Where(p => participantIds.Contains(GuidUtil.ToString(p.ID))); foreach (var dbParticipant in participants) { _mailService.SendReminder(dbEvent, dbParticipant); } }
public Event Get(string id) { // fetch event (including complete tree) var dbEvent = _repository.Single(GuidUtil.ToGuid(id)); var eventIsActive = dbEvent.PNR == null; var evn = EntityMapper.Map(dbEvent, includeAvailability: eventIsActive); new FlightSearchService(_dbContext).AddStationNames(evn); return(evn); }
public void UpdatePerson(string id, string name, string email, bool sendInvitation) { var dbParticipant = _repository.Single(GuidUtil.ToGuid(id)); dbParticipant.Name = name; dbParticipant.Email = email; _dbContext.Current.SaveChanges(); if (sendInvitation) { var dbEvent = new EventRepository(_dbContext).Single(dbParticipant.EventID); _mailService.SendInvitation(dbEvent, dbParticipant); } }
public Event Get(string participantId) { var id = GuidUtil.ToGuid(participantId); var dbParticipant = new ParticipantRepository(_dbContext).Single(id); var dbEvent = new EventRepository(_dbContext).Single(dbParticipant.EventID); var eventIsActive = dbEvent.PNR == null; // als vluchten zijn geprikt, hoeven overige vluchten niet meer geladen te worden var evn = EntityMapper.Map(dbEvent, includeParticipants: false, includeFlights: eventIsActive, includeAvailability: eventIsActive); new FlightSearchService(_dbContext).AddStationNames(evn); // don't add other participant data evn.Participants.Add(EntityMapper.Map(dbParticipant)); if (eventIsActive) { bool participantHasAvailability = dbParticipant.Availabilities.Any(); if (!participantHasAvailability) { // first visit, create if not exist yet (first time participant visits the event) foreach (var dbFlight in dbEvent.OutboundFlightSearch.Flights) { _repository.Create(dbParticipant, dbFlight); } foreach (var dbFlight in dbEvent.InboundFlightSearch.Flights) { _repository.Create(dbParticipant, dbFlight); } _dbContext.Current.SaveChanges(); } CopyParticipantAvailability(participantId, evn.OutboundFlightSearch); CopyParticipantAvailability(participantId, evn.InboundFlightSearch); } // remove personal data return(evn); }
public void SetPnr(string id, string pnr) { var dbEvent = _repository.Single(GuidUtil.ToGuid(id)); if (!string.IsNullOrWhiteSpace(dbEvent.PNR)) { throw new FormattedException("Event already has a PNR"); } dbEvent.PNR = pnr.ToUpper(); dbEvent.StatusID = EventStatusEnum.BookingCompleted; _dbContext.Current.SaveChanges(); foreach (var dbParticipant in dbEvent.Participants) { _mailService.SendBookingCreatedEmail(dbEvent, dbParticipant); } }
public void Complete(Event evn) { var dbEvent = _repository.Single(GuidUtil.ToGuid(evn.Id)); // update event details dbEvent.Title = evn.Title; dbEvent.Description = evn.Description; dbEvent.OrganizerName = evn.OrganizerName; dbEvent.OrganizerEmail = evn.OrganizerEmail; // add selected flights dbEvent.OutboundFlightSearch = AddFlightSearch(evn.OutboundFlights, evn.Origin, evn.Destination, evn.BeginDate, evn.EndDate, evn.DaysOfWeek, evn.MaxPrice); dbEvent.InboundFlightSearch = AddFlightSearch(evn.InboundFlights, evn.Destination, evn.Origin, evn.BeginDate, evn.EndDate, evn.DaysOfWeek, evn.MaxPrice); // create avaiablities for all participants var availabilityRepository = new AvailabilityRepository(_dbContext); foreach (var dbParticipant in dbEvent.Participants) { bool isOrganizer = dbParticipant.Email.Equals(dbEvent.OrganizerEmail); short?value = isOrganizer ? (short?)100 : null; foreach (var dbFlight in dbEvent.OutboundFlightSearch.Flights) { availabilityRepository.Create(dbParticipant, dbFlight, value); } foreach (var dbFlight in dbEvent.InboundFlightSearch.Flights) { availabilityRepository.Create(dbParticipant, dbFlight, value); } if (isOrganizer) { dbParticipant.AvailabilityConfirmed = true; } } dbEvent.StatusID = EventStatusEnum.NewCompleted; _dbContext.Current.SaveChanges(); // send confirmation email _mailService.SendEventConfirmation(dbEvent); }
public void Confirm(string id) { var dbEvent = _repository.Single(GuidUtil.ToGuid(id)); if (_repository.Confirm(GuidUtil.ToGuid(id))) { foreach (var dbParticipant in dbEvent.Participants) { if (dbParticipant.Email.Equals(dbEvent.OrganizerEmail)) { continue; } _mailService.SendInvitation(dbEvent, dbParticipant); } //_mailService.SendInvitationConfirmation(dbEvent); dbEvent.StatusID = EventStatusEnum.InvitationsSent; _dbContext.Current.SaveChanges(); } }
public Event RefreshFlights(string eventId) { var dbEvent = _repository.Single(GuidUtil.ToGuid(eventId)); bool isRefreshAllowed = string.IsNullOrEmpty(dbEvent.PNR) && (!dbEvent.LastModifiedPricesUtc.HasValue || dbEvent.LastModifiedPricesUtc.Value.AddMinutes(30) < DateTime.UtcNow); if (isRefreshAllowed) { dbEvent.LastModifiedPricesUtc = DateTime.UtcNow; // todo: async var bitArray = new BitArray(BitConverter.GetBytes(dbEvent.OutboundFlightSearch.DaysOfWeek)); var response = _flightRepository.Search(dbEvent.OutboundFlightSearch.DepartureStation, dbEvent.OutboundFlightSearch.ArrivalStation, dbEvent.OutboundFlightSearch.StartDate, dbEvent.OutboundFlightSearch.EndDate, (short)dbEvent.Participants.Count, bitArray, (short?)dbEvent.OutboundFlightSearch.MaxPrice); UpdateFlights(dbEvent.OutboundFlightSearch, response.OutboundFlights); UpdateFlights(dbEvent.InboundFlightSearch, response.InboundFlights); _dbContext.Current.SaveChanges(); } return(EntityMapper.Map(dbEvent, includeFlights: true, includeParticipants: false, includeAvailability: false)); }
public void Delete(string id) { _repository.Delete(GuidUtil.ToGuid(id)); }
public Participant Get(string id) { var dbParticipant = _repository.Single(GuidUtil.ToGuid(id)); return(EntityMapper.Map(dbParticipant)); }
public void Update(Availability availability) { var dbParticipant = new ParticipantRepository(_dbContext).Single(GuidUtil.ToGuid(availability.ParticipantId)); _repository.Update(dbParticipant.ID, availability.FlightId, availability.Value, availability.CommentText); }