public IEnumerable <EventUserModel> GetNewEventsForUser(string userId) { var eventsUser = EventsUsers.Where(x => x.UserId == userId && x.State == EventState.New).ToArray(); return(Events.Where(x => eventsUser.Any(eu => eu.EventId == x.Id)) .Select(x => new EventUserModel(x, eventsUser.Single(eu => eu.EventId == x.Id)))); }
/// <summary> /// Adds a request for joining the given event. Admins require no confirmation and automatically join if free slots are available. /// </summary> /// <param name="eventId"></param> /// <param name="userId"></param> /// <param name="isAdmin"></param> /// <returns></returns> public async Task RequestJoinEvent(int eventId, string userId, bool isAdmin) { if (userId == null) { throw new ArgumentException("User does not exist!"); } if (!this.Exists(eventId)) { throw new ArgumentException("Event does not exist!"); } var eventUser = this.eventUserRepository.All().FirstOrDefault(x => x.UserId == userId && x.EventId == eventId); if (eventUser != null && !eventUser.PendingJoinRequest) { throw new ArgumentException("You have already joined the event!"); } else if (eventUser != null && eventUser.PendingJoinRequest) { throw new ArgumentException("You have already sent a request to join!"); } var @event = this.eventsRepository.All().FirstOrDefault(x => x.Id == eventId); if (@event.MaxGroupSize == @event.Participants.Count()) { throw new ArgumentException("This event is full! You can't join this event! "); } eventUser = new EventsUsers { UserId = userId, EventId = eventId }; if (@event.CreatedById == userId || isAdmin) { eventUser.PendingJoinRequest = false; @event.Participants.Add(eventUser); } else { eventUser.PendingJoinRequest = true; @event.Participants.Add(eventUser); } await this.eventsRepository.SaveChangesAsync(); }
public int GetUnseenEventCountForUser(string userId) { return(EventsUsers.Count(x => x.UserId == userId && x.State == EventState.New)); }
public WorkEventUserRelation GetRelation(int eventId, string userId) { return(EventsUsers.SingleOrDefault(x => x.EventId == eventId && x.UserId == userId)); }
public void AddWorkEventRelation(WorkEventUserRelation relation) { EventsUsers.Add(relation); }
public int GetTotalEventsForUserCount(string userId, EventFilterModel filterModel) { return(EventsUsers.Count(x => x.UserId == userId && x.State == EventState.Seen)); }
public IEnumerable <Tuple <WorkEvent, WorkEventUserRelation> > GetEventsForUser(string userId) { return(EventsUsers.Where(x => x.UserId == userId) .Join(Events, relation => relation.EventId, @event => @event.Id, (relation, @event) => new Tuple <WorkEvent, WorkEventUserRelation>(@event, relation))); }