예제 #1
0
 public IEvent Get(int id)
 {
     using (var context = new ClassBookingContext())
     {
         return(MapService.Map(context.Events.Find(id)));
     }
 }
예제 #2
0
 public IClassRoom Get(int id)
 {
     using (var context = new ClassBookingContext())
     {
         return(MapService.Map(context.ClassRooms.Find(id)));
     }
 }
예제 #3
0
        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 void Add(IFeedback feedbackModel)
 {
     using (var context = new ClassBookingContext())
     {
         context.Feedbacks.Add(MapService.Map(feedbackModel));
         context.SaveChanges();
     }
 }
예제 #5
0
 public void Add(IClassRoom classRoom)
 {
     using (var context = new ClassBookingContext())
     {
         context.ClassRooms.Add(MapService.Map(classRoom));
         context.SaveChanges();
     }
 }
예제 #6
0
        public IEnumerable <IEvent> Get()
        {
            var eventsList = new List <IEvent>();

            using (var context = new ClassBookingContext())
            {
                var events = context.Events.ToList();
                foreach (var _event in events)
                {
                    eventsList.Add(MapService.Map(_event));
                }
            }
            return(eventsList);
        }
예제 #7
0
        public IEnumerable <IClassRoom> Get()
        {
            var classRoomModel = new List <IClassRoom>();

            using (var context = new ClassBookingContext())
            {
                var classRooms = context.ClassRooms.ToList();
                foreach (var classRoom in classRooms)
                {
                    classRoomModel.Add(MapService.Map(classRoom));
                }
            }
            return(classRoomModel);
        }
예제 #8
0
        public IEnumerable <IParticipant> Get(int eventId)
        {
            var participantModelList = new List <IParticipant>();

            using (var context = new ClassBookingContext())
            {
                var participants = context.Participants
                                   .Where(p => p.EventId == eventId)
                                   .ToList();
                foreach (var participant in participants)
                {
                    participantModelList.Add(MapService.Map(participant));
                }
            }

            return(participantModelList);
        }
예제 #9
0
        public void Update(IEvent eventModel, IEvent pivotModel)
        {
            if (eventModel.ClassRoomId != pivotModel.ClassRoomId)
            {
                if (ServiceHelper.IsRoomBusy(eventModel))
                {
                    throw new RoomIsBusyException();
                }
            }

            if (DateTime.Compare(eventModel.BeginingDate, pivotModel.BeginingDate) < 0)
            {
                if (ServiceHelper.IsRoomBusy(new EventModel
                {
                    BeginingDate = eventModel.BeginingDate,
                    EndingDate = pivotModel.BeginingDate,
                    ClassRoomId = eventModel.ClassRoomId
                }))
                {
                    throw new RoomIsBusyException();
                }
            }

            if (DateTime.Compare(eventModel.EndingDate, pivotModel.EndingDate) > 0)
            {
                if (ServiceHelper.IsRoomBusy(new EventModel
                {
                    BeginingDate = pivotModel.EndingDate,
                    EndingDate = eventModel.EndingDate,
                    ClassRoomId = eventModel.ClassRoomId
                }))
                {
                    throw new RoomIsBusyException();
                }
            }

            var events = MapService.Map(eventModel);

            using (var context = new ClassBookingContext())
            {
                context.Events.Attach(events);
                context.Entry(events).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
예제 #10
0
        public void Update(IClassRoom classRoom)
        {
            var updatedClassRoom = MapService.Map(classRoom);

            using (var context = new ClassBookingContext())
            {
                var old = context.ClassRooms.FirstOrDefault(c => c.Id == updatedClassRoom.Id);
                if (old != null)
                {
                    context.Entry(old).CurrentValues.SetValues(updatedClassRoom);
                    context.SaveChanges();
                }
                else
                {
                    throw new ObjectNotFoundException();
                }
            }
        }