public EventPodRoom Save(EventPodRoom domain)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(adapter);
                var entity       = (from epr in linqMetaData.EventPodRoom where epr.EventPodId == domain.EventPodId && epr.RoomNo == domain.RoomNo select epr).SingleOrDefault();
                if (entity != null)
                {
                    domain.Id = entity.EventPodRoomId;
                }

                entity = Mapper.Map <EventPodRoom, EventPodRoomEntity>(domain);
                adapter.SaveEntity(entity, true, false);
                return(Mapper.Map <EventPodRoomEntity, EventPodRoom>(entity));
            }
        }
Beispiel #2
0
        private void SaveEventPodRoom(EventPodRoomEditModel eventPodRoomEditModel)
        {
            var eventPodRoom = new EventPodRoom
            {
                Duration   = eventPodRoomEditModel.Duration,
                EventPodId = eventPodRoomEditModel.EventPodId,
                RoomNo     = eventPodRoomEditModel.RoomNo
            };

            eventPodRoom = _eventPodRoomRepository.Save(eventPodRoom);

            eventPodRoomEditModel.EventPodRoomId = eventPodRoom.Id;

            var testIds = eventPodRoomEditModel.EventPodRoomTests.Where(rt => rt.IsSelected).Select(rt => rt.TestId);

            _eventPodRoomRepository.SaveEventPodRoomTests(testIds, eventPodRoom.Id);
        }
Beispiel #3
0
        public IEnumerable <EventPodEditModel> GetEventPodEditModels(long eventId, IEnumerable <long> podIds)
        {
            var eventPodEditModels = new List <EventPodEditModel>();
            var pods = ((IUniqueItemRepository <Pod>)_podRepository).GetByIds(podIds);

            foreach (var pod in pods)
            {
                var eventPodEditModel = new EventPodEditModel
                {
                    PodId = pod.Id,
                    Name  = pod.Name
                };

                EventPod eventPod = null;
                if (eventId > 0)
                {
                    eventPod = _eventPodRepository.GetByEventIdPodId(eventId, pod.Id);
                    if (eventPod != null)
                    {
                        eventPodEditModel.EventPodId  = eventPod.Id;
                        eventPodEditModel.EventId     = eventPod.EventId;
                        eventPodEditModel.TerritoryId = eventPod.TerritoryId;
                    }
                }


                //pod rooms
                var podRooms = _podRoomRepository.GetByPodId(eventPodEditModel.PodId);

                if (eventId > 0)
                {
                    var eventPodRooms = _eventPodRoomRepository.GetByEventId(eventId);

                    if (!eventPodRooms.IsNullOrEmpty())
                    {
                        var rooms = eventPodRooms.Select(x => x.RoomNo);
                        podRooms = podRooms.Where(x => rooms.Contains(x.RoomNo));
                    }
                }

                if (podRooms != null && podRooms.Any())
                {
                    var eventPodRoomEditModels = new List <EventPodRoomEditModel>();

                    var podRoomTests = _podRoomRepository.GetPodRoomTestsByPodId(eventPodEditModel.PodId);

                    var tests = _testRepository.GetAll();

                    IEnumerable <EventPodRoom>     eventPodRooms     = null;
                    IEnumerable <EventPodRoomTest> eventPodRoomTests = null;
                    if (eventPod != null)
                    {
                        eventPodRooms     = _eventPodRoomRepository.GetByEventIdAndPodIds(eventPod.EventId, new[] { eventPod.PodId });
                        eventPodRoomTests = _eventPodRoomRepository.GetEventPodRoomTestsByEventId(eventPod.EventId);
                    }

                    foreach (var podRoom in podRooms)
                    {
                        var eventPodRoomTestEditModels = tests.Select(t => new EventPodRoomTestEditModel {
                            Name = t.Alias, TestId = t.Id
                        }).ToList();
                        var eventPodRoomEditModel = new EventPodRoomEditModel
                        {
                            EventPodRoomTests = eventPodRoomTestEditModels
                        };

                        EventPodRoom eventPodRoom = null;

                        if (eventPodRooms != null && eventPodRooms.Any())
                        {
                            eventPodRoom = eventPodRooms.SingleOrDefault(epr => epr.RoomNo == podRoom.RoomNo);
                        }

                        if (eventPodRoom != null)
                        {
                            eventPodRoomEditModel.EventPodRoomId = eventPodRoom.Id;
                            eventPodRoomEditModel.EventPodId     = eventPodRoom.EventPodId;
                            eventPodRoomEditModel.RoomNo         = eventPodRoom.RoomNo;
                            eventPodRoomEditModel.Duration       = eventPodRoom.Duration;

                            var eventPodRoomTestIds = eventPodRoomTests.Where(eprt => eprt.EventPodRoomId == eventPodRoom.Id).Select(eprt => eprt.TestId).ToArray();
                            foreach (var eventPodRoomTestEditModel in eventPodRoomEditModel.EventPodRoomTests)
                            {
                                if (eventPodRoomTestIds.Contains(eventPodRoomTestEditModel.TestId))
                                {
                                    eventPodRoomTestEditModel.IsSelected = true;
                                }
                            }
                        }
                        else
                        {
                            eventPodRoomEditModel.RoomNo   = podRoom.RoomNo;
                            eventPodRoomEditModel.Duration = podRoom.Duration;

                            var podRoomTestIds = podRoomTests.Where(eprt => eprt.PodRoomId == podRoom.Id).Select(eprt => eprt.TestId).ToArray();
                            foreach (var eventPodRoomTestEditModel in eventPodRoomEditModel.EventPodRoomTests)
                            {
                                if (podRoomTestIds.Contains(eventPodRoomTestEditModel.TestId))
                                {
                                    eventPodRoomTestEditModel.IsSelected = true;
                                }
                            }
                        }

                        eventPodRoomEditModels.Add(eventPodRoomEditModel);
                    }
                    eventPodEditModel.EventPodRooms = eventPodRoomEditModels;
                }

                eventPodEditModels.Add(eventPodEditModel);
            }

            return(eventPodEditModels);
        }