public Answer UpdateRoles(string participantId, string[] sysKeys, string[] conKeys) { LongTermParticipant asLongTerm = null; if (participantId.StartsWith("LongTerm")) { asLongTerm = Session.Load <LongTermParticipant>(participantId); } var isLongTerm = asLongTerm != null; var engagement = Session .Query <ConventionEngagement>() .FirstOrDefault(x => x.ConventionId == Actor.ManagedConvention.ConventionId && x.ParticipantId == participantId); if (engagement == null) { engagement = new ConventionEngagement() { ConventionId = Actor.ManagedConvention.ConventionId, ConventionStartDate = Actor.ManagedConvention.Days .Min(x => x.Date) .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), ParticipantId = participantId, IsLongTerm = isLongTerm }; } foreach (ConventionRoles conRole in Enum.GetValues(typeof(ConventionRoles))) { if (conKeys.Contains(conRole.ToString())) { engagement.AddRole(conRole); } else { engagement.RemoveRole(conRole); } } Session.Store(engagement); if (isLongTerm) { foreach (SystemRoles system in Enum.GetValues(typeof(SystemRoles))) { if (sysKeys.Contains(system.ToString())) { asLongTerm.AddRole(system); } else { asLongTerm.RemoveRole(system); } } } Session.SaveChanges(); return(Answer.Success); }
public async Task <Answer> CreateParticipant(ParticipantCreateUpdateViewModel viewmodel) { var answer = ValidateParticipantFields(viewmodel); if (answer.AnswerType != AnswerType.Success) { return(answer); } IParticipant model; ConventionEngagement engagement = new ConventionEngagement { ConventionId = Actor.ManagedConvention.ConventionId, ConventionStartDate = Actor.ManagedConvention.Days .Min(x => x.Date) .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), Payment = new PaymentInvoice() }; if (viewmodel.Email.IsEmptyString()) { model = new ShortTermParticipant { CreatedById = Actor.Me.Id }; } else { model = new LongTermParticipant { UserName = viewmodel.Email, Email = viewmodel.Email, IsAllowingPromotions = viewmodel.IsAllowingPromotions, }; engagement.IsLongTerm = true; } model.FullName = viewmodel.FullName; model.PhoneNumber = viewmodel.PhoneNumber ?? string.Empty; model.YearOfBirth = viewmodel.YearOfBirth; var result = await Identities.AddNewParticipant(model); engagement.ParticipantId = model.Id; if (result.IsSuccess) { Session.Store(engagement); Session.SaveChanges(); } if (result.IsSuccess && result.IsLongTerm) { await Hub.SendCreationPasswordAsync(model as LongTermParticipant, result.Token); } if (result.IsSuccess == false) { return(Answer.Error(result.Errors?.AsJson())); } return(Answer.Success); }
public PersonalViewModel BuildPersonalViewModel() { var currentConvention = Actor.DisplayConvention.ConventionId; var currentUser = Actor.Me.Id; var myEngagement = Session.Query <ConventionEngagement>() .Include(x => x.ConventionId) .Include(x => x.ParticipantId) .Include(x => x.EventIds) .Include(x => x.SuggestedEventIds) .FirstOrDefault(x => x.ConventionId == currentConvention && x.ParticipantId == currentUser); var myRelatedEngagements = Session.Query <ConventionEngagement>() .Include(x => x.ParticipantId) .Include(x => x.EventIds) .Where(x => x.CreatorId == currentUser && x.ParticipantId != currentUser && x.ConventionId == currentConvention) .ToList(); if (myEngagement == null) { myEngagement = new ConventionEngagement { CreatorId = currentUser, ParticipantId = currentUser, ConventionId = currentConvention, ConventionStartDate = Actor.DisplayConvention.Days .Min(x => x.Date) .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), IsLongTerm = true, }; Session.Store(myEngagement); Session.SaveChanges(); } var allEvents = myEngagement.EventIds; allEvents.AddRange(myEngagement.SuggestedEventIds); var allParticipants = new List <string>(); foreach (var myRelatedEngagement in myRelatedEngagements) { allParticipants.Add(myRelatedEngagement.ParticipantId); allEvents.AddRange(myRelatedEngagement.EventIds); } // Preload Events Session .Include <Event>(x => x.ConventionDayId) .Load <Event>(allEvents); var result = new PersonalViewModel(); var wrapperFactory = new WrapperFactory(Session); result.MyEngagement = wrapperFactory.Wrap(myEngagement); result.RelatedEngagements = wrapperFactory.Wrap(myRelatedEngagements); return(result); }