Beispiel #1
0
        private void SaveEventPod(long eventId, EventPodEditModel eventPodEditModel)
        {
            var pod      = ((IUniqueItemRepository <Pod>)_podRepository).GetById(eventPodEditModel.PodId);
            var eventPod = new EventPod
            {
                Id                      = eventPodEditModel.EventPodId,
                EventId                 = eventId,
                PodId                   = eventPodEditModel.PodId,
                TerritoryId             = eventPodEditModel.TerritoryId,
                DateCreated             = DateTime.Now,
                DateModified            = DateTime.Now,
                IsActive                = true,
                EnableKynIntegration    = pod.EnableKynIntegration,
                IsBloodworkFormAttached = pod.IsBloodworkFormAttached
            };

            eventPod = _eventPodRepository.Save(eventPod);

            eventPodEditModel.EventPodId = eventPod.Id;

            if (eventPodEditModel.EventPodRooms != null && eventPodEditModel.EventPodRooms.Any())
            {
                foreach (var eventPodRoomEditModel in eventPodEditModel.EventPodRooms)
                {
                    eventPodRoomEditModel.EventPodId = eventPodEditModel.EventPodId;
                    SaveEventPodRoom(eventPodRoomEditModel);
                }
            }
        }
Beispiel #2
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);
        }