public ActionResult Index()
        {
            var staffEventRoles = _staffEventRoleRepository.GetAllActiveRoles();
            var tests           = ((IUniqueItemRepository <Test>)_testRepository).GetByIds(staffEventRoles.SelectMany(ser => ser.AllowedTestIds).Distinct());

            return(View(_staffEventRoleListModelFactory.Create(staffEventRoles, tests)));
        }
Example #2
0
        public void SavePodDefaultTeamToEventStaff(long eventId, List <long> podIds, long scheduledByOrgRoleId)
        {
            var eventRoles = _eventRoleRepository.GetAllActiveRoles();
            var eventStaff = _eventStaffAssignmentRepository.GetForEvent(eventId);

            if (eventStaff != null && eventStaff.Count() > 0)
            {
                var removedPodIds = eventStaff.Where(es => !podIds.Contains(es.PodId)).Select(es => es.PodId).Distinct().ToList();
                if (removedPodIds.Count > 0)
                {
                    foreach (var podId in removedPodIds)
                    {
                        _eventStaffAssignmentRepository.DeleteFor(eventId, podId);
                    }
                }

                var currentPodIds = eventStaff.Select(es => es.PodId).Distinct().ToList();
                var newPodIds     = podIds.Where(p => !currentPodIds.Contains(p)).Select(p => p).ToList();
                if (newPodIds.Count > 0)
                {
                    foreach (var newPodId in newPodIds)
                    {
                        var defaultStaffAssignments = _podStaffAssignmentRepository.GetPodSatff(newPodId);
                        var eventStaffBasicinfo     = GetStaffBasicModels(defaultStaffAssignments.Select(dsa => new OrderedPair <long, long>(dsa.OrganizationRoleUserId, dsa.EventRoleId)), eventRoles, newPodId);
                        Save(eventId, newPodId, scheduledByOrgRoleId, eventStaffBasicinfo);
                    }
                }
            }
            else
            {
                if (podIds.Count > 0)
                {
                    foreach (var podId in podIds)
                    {
                        var defaultStaffAssignments = _podStaffAssignmentRepository.GetPodSatff(podId);
                        var eventStaffBasicinfo     = GetStaffBasicModels(defaultStaffAssignments.Select(dsa => new OrderedPair <long, long>(dsa.OrganizationRoleUserId, dsa.EventRoleId)), eventRoles, podId);
                        Save(eventId, podId, scheduledByOrgRoleId, eventStaffBasicinfo);
                    }
                }
            }
        }
Example #3
0
        public void PollForStaffEventScheduleParse()
        {
            try
            {
                var timeOfDay = DateTime.Now;
                if (_isDevEnvironment || timeOfDay.TimeOfDay > new TimeSpan(3, 0, 0))
                {
                    _logger.Info("Entering StaffEventSchedule parse polling agent @:" + timeOfDay);

                    var filesToParse = (IReadOnlyCollection <StaffEventScheduleUpload>)_staffEventScheduleUploadRepository.GetFilesToParse();

                    if (filesToParse.IsNullOrEmpty())
                    {
                        _logger.Info("No file found for parsing , exiting");
                        return;
                    }
                    _logger.Info("No. of files to Parse:" + filesToParse.Count());

                    var parseFileIds        = filesToParse.Select(x => x.FileId);
                    var uploadedFileDomains = (IReadOnlyCollection <File>)_fileRepository.GetByIds(parseFileIds);
                    var filesLocation       = _mediaRepository.GetStaffScheduleUploadMediaFileLocation();

                    var eventStaffRoles = _eventRoleRepository.GetAllActiveRoles();
                    var pods            = _podRepository.GetAllPods();

                    foreach (var staffEventScheduleUploadDomain in filesToParse)
                    {
                        var failedRecords = new List <StaffEventScheduleUploadLogViewModel>();
                        var staffEventScheduleUploadLogCollection = new List <StaffEventScheduleUploadLog>();
                        try
                        {
                            staffEventScheduleUploadDomain.ParseStartTime = DateTime.Now;
                            var fileDomainCurrent = uploadedFileDomains.FirstOrDefault(x => x.Id == staffEventScheduleUploadDomain.FileId);
                            if (fileDomainCurrent == null)
                            {
                                UpdateParsingStatus(staffEventScheduleUploadDomain, (long)StaffEventScheduleParseStatus.FileNotFound);
                                _logger.Info("Parsing Failed: FileNotFound StaffScheduleUpload Id: " + staffEventScheduleUploadDomain.Id);
                                continue;
                            }

                            var filePhysicalLocation = filesLocation.PhysicalPath + fileDomainCurrent.Path;
                            _logger.Info("Parsing for File: " + filePhysicalLocation);

                            if (!System.IO.File.Exists(filePhysicalLocation))
                            {
                                UpdateParsingStatus(staffEventScheduleUploadDomain, (long)StaffEventScheduleParseStatus.FileNotFound);
                                _logger.Info("Parsing Failed: FileNotFound on Physical Storage File name: " + fileDomainCurrent.Path);
                                continue;
                            }

                            var fInfo = new FileInfo(filePhysicalLocation);
                            if (fInfo.Extension != ".csv")
                            {
                                UpdateParsingStatus(staffEventScheduleUploadDomain, (long)StaffEventScheduleParseStatus.InvalidFileFormat);
                                _logger.Info("Parsing Failed: InvalidFileFormat File name: " + fileDomainCurrent.Path);
                                continue;
                            }

                            _logger.Error("Beginning to Parse File : File name: " + fileDomainCurrent.Path);
                            UpdateParsingStatus(staffEventScheduleUploadDomain, (long)StaffEventScheduleParseStatus.Parsing, false);

                            var staffEventScheduleTable = _csvReader.ReadWithTextQualifier(filePhysicalLocation);
                            var recordsInFile           = staffEventScheduleTable.Rows.Count;

                            IEnumerable <StaffEventScheduleParsedDataViewModel> tempParsedRecords = null;
                            var rows = staffEventScheduleTable.AsEnumerable();
                            tempParsedRecords = ParseScheduleUpload(rows, failedRecords, staffEventScheduleUploadLogCollection);
                            if (tempParsedRecords.IsNullOrEmpty())
                            {
                                staffEventScheduleUploadDomain.StatusId = (long)StaffEventScheduleParseStatus.ParseFailed;
                                UpdateStaffScheduleUploadDetail(staffEventScheduleUploadDomain, failedRecords, filePhysicalLocation, staffEventScheduleUploadLogCollection);
                                continue;
                            }

                            UpdateStaffEventSchedule(tempParsedRecords, fileDomainCurrent.UploadedBy.Id, eventStaffRoles, pods, staffEventScheduleUploadLogCollection);

                            staffEventScheduleUploadDomain.SuccessUploadCount = tempParsedRecords.Count(x => x.IsSuccess == true);
                            staffEventScheduleUploadDomain.ParseEndTime       = DateTime.Now;
                            staffEventScheduleUploadDomain.StatusId           = (long)StaffEventScheduleParseStatus.Parsed;

                            failedRecords.AddRange(tempParsedRecords
                                                   .Where(x => x.IsSuccess == false)
                                                   .Select(x => new StaffEventScheduleUploadLogViewModel
                            {
                                EmployeeId   = x.EmployeeId,
                                ErrorMessage = x.ErrorMessage,
                                EventDate    = x.EventDate.ToString("MM/dd/yyyy"),
                                Name         = x.Name,
                                Pod          = x.Pod,
                                Role         = x.Role
                            }).ToList());

                            UpdateStaffScheduleUploadDetail(staffEventScheduleUploadDomain, failedRecords, filePhysicalLocation, staffEventScheduleUploadLogCollection);
                            _logger.Error("Parse Succeeded : File name: " + fileDomainCurrent.Path);
                        }
                        catch (Exception ex)
                        {
                            var fileDomain = uploadedFileDomains.FirstOrDefault(x => x.Id == staffEventScheduleUploadDomain.FileId);

                            if (fileDomain != null)
                            {
                                _logger.Error("Failed to parse File , File name: " + fileDomain.Path);
                                var filePhysicalLocation = filesLocation.PhysicalPath + fileDomain.Path;
                                staffEventScheduleUploadDomain.StatusId = (long)StaffEventScheduleParseStatus.ParseFailed;
                                UpdateStaffScheduleUploadDetail(staffEventScheduleUploadDomain, failedRecords, filePhysicalLocation, staffEventScheduleUploadLogCollection);
                            }
                            else
                            {
                                _logger.Error("Record does not exist in file table");
                            }

                            _logger.Error("ExceptionMessage: " + ex.Message + "\n\tStackTrace: " + ex.StackTrace);
                            continue;
                        }
                    }
                }
                else
                {
                    _logger.Info(string.Format("StaffEventSchedule Parser can not be invoked as time of day is {0}", timeOfDay.TimeOfDay));
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Exception occurred during execution of polling agent\nException Message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace));
                return;
            }
        }