public IEnumerable <IEvent> GetByUser(string id) { var eventsList = new List <IEvent>(); var dateNow = DateTime.UtcNow.AddHours(EventSettings.DateTimeUtcOffset); using (var context = new ClassBookingContext()) { var userEmail = ServiceHelper.GetUserEmail(id); var events = (from e in context.Events join p in context.Participants on e.Id equals p.EventId where e.EndingDate > dateNow && p.Email == userEmail select new EventModel { Id = e.Id, ClassRoomId = e.ClassRoomId, BeginingDate = e.BeginingDate, EndingDate = e.EndingDate, Title = e.Title, Description = e.Description, IsPrivate = e.IsPrivate }).ToList(); foreach (var _event in events) { eventsList.Add(_event); } } return(eventsList); }
public void Add(IEvent eventModel) { using (var context = new ClassBookingContext()) { if (ServiceHelper.IsRoomBusy(eventModel)) { throw new RoomIsBusyException(); } var roomCapacity = context.ClassRooms .Where(c => c.Id == eventModel.ClassRoomId) .Select(c => c.Capacity).FirstOrDefault(); if (roomCapacity < 1) { throw new RoomCapacityException(); } var events = MapService.Map(eventModel); var userEmail = ServiceHelper.GetUserEmail(eventModel.UserId); context.Events.Add(events); context.Participants.Add(new Participants { EventId = events.Id, Email = userEmail }); context.SaveChanges(); } }
public bool IsTakePart(int eventId, string userId) { using (var context = new ClassBookingContext()) { var userEmail = ServiceHelper.GetUserEmail(userId); var userCount = context.Participants.Count( p => p.EventId == eventId && p.Email == userEmail); return(userCount > 0); } }