public async Task <EventWithStatus> GetSingleEventWithStatus(string userId, Guid eventId) { var currentEvent = await _context.Event.Where(x => x.Id == eventId).FirstOrDefaultAsync(); var currentEventWithStatus = new EventWithStatus() { Id = currentEvent.Id, Name = currentEvent.Name, OwnerId = currentEvent.OwnerId, HowManyPeople = currentEvent.HowManyPeople, CurrentPeopleNumber = currentEvent.CurrentPeopleNumber, StartDate = currentEvent.StartDate, longitude = currentEvent.longitude, latitude = currentEvent.latitude, }; var statusTemp = await _context.EventRequest.Where(x => x.EventId == currentEvent.Id && x.UserId == userId).FirstOrDefaultAsync(); if (statusTemp == null) { currentEventWithStatus.Status = 0; } else { currentEventWithStatus.Status = statusTemp.Status; } currentEventWithStatus.doIOwnedIt = (currentEvent.OwnerId == userId); return(currentEventWithStatus); }
public async Task <EventWithStatus[]> GetEventWithStatus(string userId) { var events = await _context.Event.ToArrayAsync(); var eventsWithStatus = new List <EventWithStatus>(); foreach (var item in events) { var singleEventWithStatus = new EventWithStatus() { Id = item.Id, Name = item.Name, OwnerId = item.OwnerId, HowManyPeople = item.HowManyPeople, CurrentPeopleNumber = item.CurrentPeopleNumber, StartDate = item.StartDate, longitude = item.longitude, latitude = item.latitude, }; var statusTemp = await _context.EventRequest.Where(x => x.EventId == item.Id && x.UserId == userId).FirstOrDefaultAsync(); if (statusTemp == null) { singleEventWithStatus.Status = 0; } else { singleEventWithStatus.Status = statusTemp.Status; } singleEventWithStatus.doIOwnedIt = (item.OwnerId == userId); eventsWithStatus.Add(singleEventWithStatus); } return(eventsWithStatus.ToArray()); }