Ejemplo n.º 1
0
        public void SaveEventPod(IEnumerable <EventPodEditModel> models, long eventId)
        {
            var eventPodsInDb = _eventPodRepository.GetByEventId(eventId);

            if (eventPodsInDb != null && eventPodsInDb.Any())
            {
                var currentPodIds          = models.Select(m => m.PodId).ToArray();
                var eventPodIdsToBeDeleted = eventPodsInDb.Where(ep => !currentPodIds.Contains(ep.PodId)).Select(ep => ep.PodId).ToArray();

                if (eventPodIdsToBeDeleted.Any())
                {
                    _eventPodRepository.DeactivateEventPod(eventId, eventPodIdsToBeDeleted);

                    var eventPodRooms = _eventPodRoomRepository.GetByEventIdAndPodIds(eventId, eventPodIdsToBeDeleted);

                    if (eventPodRooms != null && eventPodRooms.Any())
                    {
                        var eventPodRoomIds = eventPodRooms.Select(epr => epr.Id).ToArray();
                        DeleteEventPodRooms(eventPodRoomIds);
                    }
                }
            }

            foreach (var eventPodEditModel in models)
            {
                var existingEventPodRooms = _eventPodRoomRepository.GetByEventIdAndPodIds(eventId, new[] { eventPodEditModel.PodId });
                if (existingEventPodRooms != null && existingEventPodRooms.Any())
                {
                    if (eventPodEditModel.EventPodRooms != null && eventPodEditModel.EventPodRooms.Any())
                    {
                        var rooms = eventPodEditModel.EventPodRooms.Select(p => p.RoomNo);
                        var eventPodRoomsToBeDeleted = existingEventPodRooms.Where(m => !rooms.Contains(m.RoomNo)).Select(m => m).ToArray();
                        if (eventPodRoomsToBeDeleted.Any())
                        {
                            var eventPodRoomIds = eventPodRoomsToBeDeleted.Select(epr => epr.Id).ToArray();
                            DeleteEventPodRooms(eventPodRoomIds);
                        }
                    }
                    else
                    {
                        var eventPodRoomIds = existingEventPodRooms.Select(epr => epr.Id).ToArray();
                        DeleteEventPodRooms(eventPodRoomIds);
                    }
                }

                SaveEventPod(eventId, eventPodEditModel);
            }
        }
Ejemplo n.º 2
0
        public bool AddMissingTestToEvent(long eventId, IEnumerable <long> testIds)
        {
            var eventtests      = _eventTestRepository.GetTestsForEvent(eventId);
            var existingtestIds = eventtests.Select(x => x.TestId).ToList();
            var toBeAddedTests  = testIds.Where(testId => !existingtestIds.Contains(testId)).ToList();

            if (toBeAddedTests.Any())
            {
                foreach (var tobeAddedTest in toBeAddedTests)
                {
                    _eventTestRepository.Save(new EventTest
                    {
                        TestId            = tobeAddedTest,
                        EventId           = eventId,
                        WithPackagePrice  = (decimal)0.0,
                        Price             = (decimal)0.0,
                        RefundPrice       = (decimal)0.0,
                        ReimbursementRate = 0,
                        ShowInAlaCarte    = true,
                        Gender            = (long)Gender.Unspecified,

                        GroupId      = (long)TestGroupType.None,
                        DateCreated  = System.DateTime.Now,
                        DateModified = System.DateTime.Now
                    });
                }
                var theEvent = _eventRepository.GetById(eventId);
                if (theEvent.IsDynamicScheduling)
                {
                    var eventPods     = _eventPodRepository.GetByEventId(eventId);
                    var eventPodIds   = eventPods.Select(x => x.Id);
                    var eventPodRooms = _eventPodRoomRepository.GetByEventPodIds(eventPodIds);
                    foreach (var eventPodRoom in eventPodRooms)
                    {
                        _eventPodRoomRepository.SaveEventPodRoomTests(toBeAddedTests, eventPodRoom.Id);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        private void UpdateStaffEventSchedule(IEnumerable <StaffEventScheduleParsedDataViewModel> parsedRecords, long fileUploader,
                                              IEnumerable <StaffEventRole> staffEventRoles, IEnumerable <Pod> pods, List <StaffEventScheduleUploadLog> staffEventScheduleUploadLogCollection)
        {
            var eventDatePodPair = parsedRecords.GroupBy(x => new { x.EventDate, x.Pod }).Select(x => new OrderedPair <DateTime, string>()
            {
                FirstValue = x.Key.EventDate, SecondValue = x.Key.Pod
            }).ToArray();

            foreach (var eventDatePod in eventDatePodPair)
            {
                try
                {
                    var events = _eventRepository.GetEventByEventDateAndPod(eventDatePod.FirstValue, eventDatePod.SecondValue);
                    if (!events.IsNullOrEmpty())
                    {
                        var recordsForEventId = parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue).Select(x => x);
                        var employeeIds       = recordsForEventId.Select(x => x.EmployeeId.ToUpper()).ToList();
                        var employeeIdOruPair = _organizationRoleUserRepository.GetActiveOruIdEmployeeIdPairByEmployeeIdAndRole(employeeIds, (long)Roles.Technician);

                        foreach (var @event in events)
                        {
                            var validRecords = new List <StaffEventScheduleParsedDataViewModel>();
                            var eventId      = @event.Id;
                            try
                            {
                                var eventPods = _eventPodRepository.GetByEventId(eventId);
                                if (eventPods.IsNullOrEmpty())
                                {
                                    _logger.Info("No Event Pod found for EventId:" + eventId);
                                    parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue).ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "No pod Exist for this EventId"; });
                                    continue;
                                }

                                var podNamesInCsvForEvent    = parsedRecords.Select(x => x.Pod);
                                var validPodsForEventFromCsv = pods.Where(x => podNamesInCsvForEvent.Contains(x.Name) && eventPods.First().PodId == x.Id);

                                if (validPodsForEventFromCsv.IsNullOrEmpty())
                                {
                                    _logger.Info("No valid Pod provided for EventId:" + eventId);
                                    parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue).ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Pod not attached to this Event"; });
                                    continue;
                                }

                                var selectedPodId = validPodsForEventFromCsv.First().Id;
                                var selectedPod   = pods.First(x => x.Id == selectedPodId);

                                foreach (var record in recordsForEventId)
                                {
                                    var staff = employeeIdOruPair.FirstOrDefault(x => x.SecondValue.Trim().ToUpper() == record.EmployeeId.ToUpper());
                                    if (staff == null)
                                    {
                                        parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue && x.EmployeeId == record.EmployeeId && x.Name == record.Name && x.Role == record.Role)
                                        .ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Provided Employee Id does not exist"; });

                                        continue;
                                    }

                                    var role = staffEventRoles.FirstOrDefault(x => string.Compare(x.Name.Trim(), record.Role, StringComparison.InvariantCultureIgnoreCase) == 0);
                                    if (role == null)
                                    {
                                        parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue && x.EmployeeId == record.EmployeeId && x.Name == record.Name && x.Role == record.Role)
                                        .ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Provided role does not exist or Inactive"; });
                                        continue;
                                    }

                                    var pod = pods.FirstOrDefault(x => x.Name.Trim().ToUpper() == record.Pod.ToUpper());
                                    if (pod == null)
                                    {
                                        parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue && x.EmployeeId == record.EmployeeId && x.Name == record.Name && x.Role == record.Role)
                                        .ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Provided pod does not exist"; });
                                        continue;
                                    }

                                    if (pod.Id != selectedPodId && eventPods.Select(x => x.PodId).Contains(pod.Id))
                                    {
                                        parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue && x.EmployeeId == record.EmployeeId && x.Name == record.Name && x.Role == record.Role)
                                        .ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Record Discarded for :" + record.Pod.ToUpper() + ", Successfully attached :" + selectedPod.Name.ToUpper(); });
                                        continue;
                                    }

                                    if (record.EventDate != @event.EventDate)
                                    {
                                        parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue && x.EmployeeId == record.EmployeeId && x.Name == record.Name && x.Role == record.Role)
                                        .ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Provided event date doesn't match with the eventId"; });
                                        continue;
                                    }

                                    parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue && x.EmployeeId == record.EmployeeId && x.Name == record.Name && x.Role == record.Role)
                                    .ForEach(x => { x.IsSuccess = true; });

                                    staffEventScheduleUploadLogCollection.Add(new StaffEventScheduleUploadLog
                                    {
                                        ErrorMessage = null,
                                        EventDate    = record.EventDate.ToString("MM/dd/yyyy"),
                                        IsSuccessful = true,
                                        Pod          = record.Pod,
                                        Role         = record.Role,
                                        EmployeeId   = record.EmployeeId.ToString(),
                                        StaffName    = record.Name
                                    });
                                    validRecords.Add(record);
                                }
                                if (!validRecords.IsNullOrEmpty())
                                {
                                    //parsed records eventStaffBasicInfoModelCollection
                                    var eventStaffBasicInfoModelCollection = GetEventStaffModel(validRecords, staffEventRoles, selectedPodId, employeeIdOruPair).ToList();

                                    //Appending records from DB to our parsed records
                                    var alreadyAssignedStaffForEvent = (IReadOnlyCollection <EventStaffAssignment>)_eventStaffAssignmentRepository.GetForEvent(eventId);
                                    if (alreadyAssignedStaffForEvent.Any())
                                    {
                                        eventStaffBasicInfoModelCollection.AddRange(MapEventStaffAssignmentToEventBasicInfoModel(alreadyAssignedStaffForEvent, selectedPodId));
                                    }

                                    //now filtering only unique combination of ScheduledStaffOrgRoleUserId and EventRoleId
                                    //because one Staff can be assigned some role only once

                                    var uniqueEntriesInEventStaffBasicInfoModel = new List <EventStaffBasicInfoModel>();
                                    foreach (var eventStaffBasicInfoModel in eventStaffBasicInfoModelCollection)
                                    {
                                        var data = eventStaffBasicInfoModel;
                                        if (uniqueEntriesInEventStaffBasicInfoModel.FirstOrDefault(
                                                x =>
                                                x.ScheduledStaffOrgRoleUserId == eventStaffBasicInfoModel.ScheduledStaffOrgRoleUserId &&
                                                x.EventRoleId == eventStaffBasicInfoModel.EventRoleId) == null)
                                        {
                                            uniqueEntriesInEventStaffBasicInfoModel.Add(data);
                                        }
                                    }

                                    _eventStaffAssignmentService.Save(@event.Id, selectedPodId, fileUploader, uniqueEntriesInEventStaffBasicInfoModel);
                                }
                            }
                            catch (Exception ex)
                            {
                                _logger.Info("Exception Occurred while saving staff Assignment for EventId:" + eventId + "\nMarking all Records as Failed");

                                parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue)
                                .ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Internal Error Occured"; });

                                _logger.Error("ExceptionMessage: " + ex.Message + "\n\tStackTrace: " + ex.StackTrace);
                                continue;
                            }
                        }
                    }
                    else
                    {
                        parsedRecords.Where(x => x.EventDate == eventDatePod.FirstValue && x.Pod == eventDatePod.SecondValue)
                        .ForEach(x => { x.IsSuccess = false; x.ErrorMessage = "Event Date and Pod pair does not exist"; });
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("ExceptionMessage: " + ex.Message + "\n\tStackTrace: " + ex.StackTrace);
                }
            }
        }