public async Task <IActionResult> AdminIndex()
        {
            List <UserEventDetailsViewModel> userEventDetails = new List <UserEventDetailsViewModel>();

            var userEvents = await _context.UserEventModels.ToListAsync();

            foreach (var userEvent in userEvents)
            {
                var eventInfo = await _context.EventInfoModel.FindAsync(userEvent.EventId);

                var user = await _userManager.FindByIdAsync(userEvent.UserId);

                var userEventDetail = new UserEventDetailsViewModel()
                {
                    EmployeeName   = user.EmployeeName,
                    Department     = user.Department,
                    Position       = user.Position,
                    EventId        = eventInfo.Id,
                    EventName      = eventInfo.EventName,
                    EventOrg       = eventInfo.EventOrg,
                    PresentersName = eventInfo.PresentersName,
                    EventLocation  = eventInfo.EventLocation,
                    EventStartDate = eventInfo.EventStartDate,
                    EventEndDate   = eventInfo.EventEndDate
                };

                userEventDetails.Add(userEventDetail);
            }

            return(View(userEventDetails));
        }
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var userEvent = await _context.UserEventModels.FirstOrDefaultAsync(model => model.EventId == id);

            if (userEvent == null)
            {
                return(NotFound());
            }

            var eventInfo = await _context.EventInfoModel.FirstOrDefaultAsync(m => m.Id == userEvent.EventId);

            if (eventInfo == null)
            {
                return(NotFound());
            }

            var user = await _userManager.FindByIdAsync(userEvent.UserId);

            if (user == null)
            {
                return(NotFound());
            }

            var userEventDetails = new UserEventDetailsViewModel()
            {
                EmployeeName   = user.EmployeeName,
                Department     = user.Department,
                Position       = user.Position,
                EventId        = eventInfo.Id,
                EventName      = eventInfo.EventName,
                EventOrg       = eventInfo.EventOrg,
                PresentersName = eventInfo.PresentersName,
                EventLocation  = eventInfo.EventLocation,
                EventStartDate = eventInfo.EventStartDate,
                EventEndDate   = eventInfo.EventEndDate
            };

            return(View(userEventDetails));
            //return View(eventInfoModel);
        }
        public async Task <IActionResult> DownloadExcel(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var userEvent = await _context.UserEventModels.FirstOrDefaultAsync(model => model.EventId == id);

            if (userEvent == null)
            {
                return(NotFound());
            }

            var eventInfo = await _context.EventInfoModel.FirstOrDefaultAsync(m => m.Id == userEvent.EventId);

            if (eventInfo == null)
            {
                return(NotFound());
            }

            var user = await _userManager.FindByIdAsync(userEvent.UserId);

            if (user == null)
            {
                return(NotFound());
            }

            var userEventDetails = new UserEventDetailsViewModel()
            {
                EmployeeName   = user.EmployeeName,
                Department     = user.Department,
                Position       = user.Position,
                EventId        = eventInfo.Id,
                EventName      = eventInfo.EventName,
                EventOrg       = eventInfo.EventOrg,
                PresentersName = eventInfo.PresentersName,
                EventLocation  = eventInfo.EventLocation,
                EventStartDate = eventInfo.EventStartDate,
                EventEndDate   = eventInfo.EventEndDate
            };

            //string fileName = "Event Feedback Form.xlsx";
            //string sourcePath = @"D:\Core\FeedbackService\FeedbackWebsite\FeedbackWebsite\Excel\Source";

            string fileName = @"Excel\Source\Event Feedback Form.xlsx";

            var exePath = Path.GetDirectoryName(System.Reflection
                                                .Assembly.GetExecutingAssembly().CodeBase);
            Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)");
            var   appRoot        = appPathMatcher.Match(exePath).Value;

            //string soutceFile = Path.Combine(sourcePath, fileName);
            string soutceFile = Path.Combine(appRoot, fileName);

            MemoryStream ms;

            using (var fs = new FileStream(soutceFile, FileMode.Open, FileAccess.Read))
            {
                ms = new MemoryStream();
                fs.CopyTo(ms);
                ms.Position = 0;
            }


            UpdateCell(ms, userEventDetails.EmployeeName, 4, "B");

            string buf = $"{userEventDetails.Department} \\ {userEventDetails.Position}";

            UpdateCell(ms, buf, 5, "B");

            UpdateCell(ms, userEventDetails.EventName, 6, "B");

            UpdateCell(ms, userEventDetails.EventOrg, 7, "B");

            UpdateCell(ms, userEventDetails.PresentersName, 8, "B");

            UpdateCell(ms, userEventDetails.EventLocation, 9, "B");

            UpdateCell(ms, userEventDetails.EventStartDate.Day, 10, "B");
            UpdateCell(ms, userEventDetails.EventStartDate.Month, 10, "C");
            UpdateCell(ms, userEventDetails.EventStartDate.Year, 10, "D");

            UpdateCell(ms, userEventDetails.EventEndDate.Day, 11, "B");
            UpdateCell(ms, userEventDetails.EventEndDate.Month, 11, "C");
            UpdateCell(ms, userEventDetails.EventEndDate.Year, 11, "D");

            var answersInfoEnums = _context.AnswerEnum.Where(model => model.EventId == id);

            uint counter = 14;

            foreach (var answersInfoEnum in answersInfoEnums)
            {
                buf = ReturnStringAnswer(answersInfoEnum.QuestionEnumAnswer);
                UpdateCell(ms, buf, counter, "E");
                counter++;
            }

            AnswerText answerText = await _context.AnswerText.FirstOrDefaultAsync(model => model.EventId == id);

            UpdateCell(ms, answerText.AnswerTextAnswer, 25, "A");
            ms.Position = 0;


            string downloadFileName = $"{userEventDetails.EmployeeName} - {userEventDetails.EventName} - {fileName}";

            return(File(ms, "application/xlsx", downloadFileName));
            //return RedirectToAction("Index");
        }