示例#1
0
        public ActionResult Registered()
        {
            var model = new RegistrationsViewModel
            {
                StartedRegistrations = GetFidoRepository().GetAllStartedRegistrationsOfUser(GetCurrentUser()).ToList(),
                DeviceRegistrations  = GetFidoRepository().GetDeviceRegistrationsOfUser(GetCurrentUser()).ToList()
            };

            return(View(model));
        }
        public async Task <ActionResult> Delete(int id)
        {
            var data = await _registrationService.GetByIdAsync(id);

            var model = new RegistrationsViewModel
            {
                Id        = data.Id,
                Date      = data.Date,
                StartTime = data.StartTime,
                EndTime   = data.EndTime.GetValueOrDefault()
            };

            return(View(model));
        }
        public async Task <ActionResult> Details(int id)
        {
            _logger.LogInformation($"Vis detaljer for registrering {id}");

            var data = await _registrationService.GetByIdAsync(id);

            var model = new RegistrationsViewModel
            {
                Id        = data.Id,
                Date      = data.Date,
                StartTime = data.StartTime,
                EndTime   = data.EndTime.GetValueOrDefault()
            };

            return(View(model));
        }
示例#4
0
        public async Task <Stream> GenerateAsync(RegistrationsViewModel registrationsViewModel)
        {
            string tempFileName = Path.GetTempFileName();

            File.Copy(_settings.ReportTemplatePath, tempFileName, overwrite: true);

            using (var package = new ExcelPackage(new FileInfo(tempFileName)))
            {
                FillContent(package, registrationsViewModel);

                package.Save();
            }

            var file = File.Open(tempFileName, FileMode.Open, FileAccess.Read);

            return(await Task.FromResult(file));
        }
示例#5
0
        private void FillContent(ExcelPackage package, RegistrationsViewModel registrationsViewModel)
        {
            var columns = new
            {
                Date        = "A",
                Employee    = "B",
                EventTime   = "C",
                Event       = "D",
                Place       = "E",
                WorkTime    = "F",
                DayWorkTime = "G",
                Lateness    = "H"
            };



            Filter(registrationsViewModel.FilterForm);
            Table();



            void Filter(ReportFilterForm filter)
            {
                package
                .Write(filter.EmployeeId.HasValue ? filter.Employees.FirstOrDefault(x => x.Selected)?.Text : "Все сотрудники")
                .To("B", 3);

                package
                .Write(filter.DateFrom.HasValue ? filter.DateFrom.Value.ToShortDateString() : "Не указана")
                .To("D", 3);

                package
                .Write(filter.DateTo.HasValue ? filter.DateTo.Value.ToShortDateString() : "Не указана")
                .To("D", 5);

                package
                .Write(filter.Lateness.HasValue ? filter.LatenessSelectListItems.FirstOrDefault(x => x.Selected)?.Text : "Не имеет значения")
                .To("F", 3);

                package
                .Write(filter.StrictSchedule.HasValue ? filter.StrictScheduleSelecrListItems.FirstOrDefault(x => x.Selected)?.Text : "Не имеет значения")
                .To("F", 5);
            }

            void Table()
            {
                int dayRowIndex = 11;

                foreach (var dayRegistrations in registrationsViewModel.DayRegistrations)
                {
                    var dayRegistrationsCount = dayRegistrations.DayEmployeeRegistrationsCount;

                    package
                    .Write(dayRegistrations.Day.ToShortDateString())
                    .From(columns.Date, dayRowIndex)
                    .To(columns.Date, dayRowIndex + dayRegistrationsCount - 1);

                    int dayEmployeeRowIndex = dayRowIndex;

                    foreach (var dayEmployeeRegistrations in dayRegistrations.DayEmployeeRegistraions)
                    {
                        var dayEmployeeRegistrationsCount = dayEmployeeRegistrations.TotalDayEmployeeRegistrationsCount;

                        package
                        .Write(dayEmployeeRegistrations.Employee)
                        .From(columns.Employee, dayEmployeeRowIndex)
                        .To(columns.Employee, dayEmployeeRowIndex + dayEmployeeRegistrationsCount - 1);

                        package
                        .Write(dayEmployeeRegistrations.TotalWorkDayTimeInterval.ToString("hh\\:mm"))
                        .From(columns.DayWorkTime, dayEmployeeRowIndex)
                        .To(columns.DayWorkTime, dayEmployeeRowIndex + dayEmployeeRegistrationsCount - 1);

                        package
                        .Write(dayEmployeeRegistrations.LatenessTimeInterval.ToString("hh\\:mm"))
                        .Fill(dayEmployeeRegistrations.EmployeeWasLate ? Color.Coral : Color.White)
                        .From(columns.Lateness, dayEmployeeRowIndex)
                        .To(columns.Lateness, dayEmployeeRowIndex + dayEmployeeRegistrationsCount - 1);

                        int registrationRowIndex = dayEmployeeRowIndex;

                        foreach (var registration in dayEmployeeRegistrations.RegistrationRows)
                        {
                            package
                            .Write(registration.Time.ToString("hh\\:mm"))
                            .To(columns.EventTime, registrationRowIndex);

                            package
                            .Write(registration.Event.DisplayName())
                            .To(columns.Event, registrationRowIndex);

                            package
                            .Write(registration.EntranceCompleteName)
                            .To(columns.Place, registrationRowIndex);

                            if (registration.Event is RegistrationEventType.Coming &&
                                registration.CheckResult is RegistrationCheckResult.Ok)
                            {
                                package
                                .Write(registration.WorkTimeInterval.ToString("hh\\:mm"))
                                .From(columns.WorkTime, registrationRowIndex)
                                .To(columns.WorkTime, registrationRowIndex + 1);
                            }
                            else if (registration.CheckResult == RegistrationCheckResult.Violation)
                            {
                                package
                                .Write("-")
                                .Fill(Color.Orchid)
                                .To(columns.WorkTime, registrationRowIndex);
                            }

                            registrationRowIndex++;
                        }

                        dayEmployeeRowIndex += dayEmployeeRegistrationsCount;
                    }

                    dayRowIndex += dayRegistrationsCount;
                }
            }
        }
        private ViewResult StackedBar(IEnumerable <Registration> registrations, ReportFilterForm form)
        {
            IEnumerable <RegistrationViewModel> registrationViewModels =
                _mapper.Map <IEnumerable <RegistrationViewModel> >(registrations);

            string selectedLateness =
                form.Lateness.HasValue ? Enum.GetName(typeof(Lateness), form.Lateness) : string.Empty;
            string selectedScheduleRestriction = form.StrictSchedule.HasValue
                ? Enum.GetName(typeof(StrictSchedureRequirement), form.StrictSchedule)
                : string.Empty;

            form.Registrations                 = registrationViewModels;
            form.Employees                     = _employeeService.All().ToSelectList();
            form.LatenessSelectListItems       = typeof(Lateness).ToSelectList(selectedLateness);
            form.StrictScheduleSelecrListItems =
                typeof(StrictSchedureRequirement).ToSelectList(selectedScheduleRestriction);

            RegistrationsViewModel registraionsViewModel =
                _registrationsViewModelService.ToRegistrationsViewModel(registrationViewModels, form);

            List <StackedBarDayViewModel> barViewModels =
                registraionsViewModel
                .DayRegistrations
                .Select(dayRegistrations =>
            {
                IOrderedEnumerable <DayEmployeeRegistraionsViewModel> orderedDayEmployeeRegistrations =
                    dayRegistrations.DayEmployeeRegistraions.OrderBy(x => x.EmployeeId);


                return(new StackedBarDayViewModel
                {
                    Day = dayRegistrations.Day.DayOfYear.ToString(),
                    Names =
                        JsonConvert.SerializeObject(orderedDayEmployeeRegistrations.Select(x => x.Employee)),
                    WorkTimes = JsonConvert.SerializeObject(orderedDayEmployeeRegistrations.Select(x =>
                    {
                        int totalMinutes = (int)x.TotalWorkDayTimeInterval.TotalMinutes;

                        if (dayRegistrations.Day.Date.Equals(_timeService.Now.Date))
                        {
                            RegistrationRowViewModel last = x.RegistrationRows.OrderBy(y => y.Time).Last();

                            if (last.Event.Equals(RegistrationEventType.Coming))
                            {
                                totalMinutes += (int)(_timeService.TimeNow - last.Time).TotalMinutes;
                            }
                        }

                        return totalMinutes.ToString();
                    })),
                    LatenessTimes = JsonConvert.SerializeObject(orderedDayEmployeeRegistrations.Select(x =>
                    {
                        int totalMinutes = (int)x.LatenessTimeInterval.TotalMinutes;

                        if (dayRegistrations.Day.Date.Equals(_timeService.Now.Date))
                        {
                            RegistrationRowViewModel last = x.RegistrationRows.OrderBy(y => y.Time).Last();

                            if (last.Event.Equals(RegistrationEventType.Coming))
                            {
                                if (totalMinutes < 1 && last.Time >= _timeService.WorkDayStartsAt)
                                {
                                    totalMinutes = (int)(last.Time - _timeService.WorkDayStartsAt)
                                                   .TotalMinutes;
                                }
                            }
                        }
                        else if (x.RegistrationRows.All(z =>
                                                        z.CheckResult == RegistrationCheckResult.Violation))
                        {
                            totalMinutes = (int)_timeService.TotalWorkDayTimeSpan.TotalMinutes;
                        }

                        return totalMinutes.ToString();
                    }))
                });
            })
                .ToList();

            StackedBarViewModel viewModel = new StackedBarViewModel
            {
                StackedBarDayViewModels = barViewModels,
                FilterForm       = form,
                DayRegistrations = registraionsViewModel.DayRegistrations
            };

            return(View(viewModel));
        }