Ejemplo n.º 1
0
        public void ChangeRoomStatus(int id, ClassRoomStatus classRoomStatus)
        {
            using (var context = new ClassBookingContext())
            {
                var classRoom = context.ClassRooms.Find(id);
                context.ClassRooms.Attach(classRoom);
                var entry = context.Entry(classRoom);
                switch (classRoomStatus)
                {
                case ClassRoomStatus.Opened:
                    classRoom.IsLocked = false;
                    break;

                case ClassRoomStatus.Closed:
                    classRoom.IsLocked = true;

                    var eventsToDelete = context.Events.Where(e => e.ClassRoomId == id).ToList();
                    foreach (var eventToDelete in eventsToDelete)
                    {
                        context.Participants.RemoveRange(
                            context.Participants.Where(p => p.EventId == eventToDelete.Id));
                    }

                    context.Events.RemoveRange(context.Events.Where(e => e.ClassRoomId == id));

                    break;
                }
                entry.Property(e => e.IsLocked).IsModified = true;
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
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();
            }
        }
Ejemplo n.º 3
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();
                }
            }
        }